[BangPypers] calling instance of the other class.

learningpython learningpython at aol.com
Wed Jun 24 11:33:17 CEST 2009




bangpyper wrote:
> 
> On Wed, Jun 24, 2009 at 7:42 AM, Jeff Rush <jeff at taupro.com> wrote:
> 
>> learningpython wrote:
>> > Hi Jeff,
>> > Can i ask you a related question. Long shot ..
>> > but since you have good idea of area i am working ( which is
>> communications,
>> > sending, decoding, encoding) data over a serial interface.
>> > I have a problem, i am facing.. Like in ASN format..
>> > I have a Data Unit ( am defining a class for each )
>> >
>> > 1. msg type  ( 8 bits )
>> > 2. Identity(8 bits)
>> > 3. ADESC ( 8 bits)
>> > 4. Address ( Now this depends on value of ADESC )
>> > so the other elements, i am allocating the memory, but how can i
>> allocate
>> > Address, the number of fields ( i mean size) depends on the ASESC value
>> so
>> > it could be any value .. how can i say reserve memory .
>> >
>> > The only idea i get is to have a function within the class of this
>> > definition where, i read the ADESC and then allocate value in address.
>> Any
>> > other good ideas, please can you let me know. I really appreciate your
>> > links.
>>
>> The important module for bit manipulation in Python in the struct
>> module.  If you haven't come across it before, you should read the docs.
>>  It is part of the Python standard library.
>>
>>  http://docs.python.org/library/struct.html
> 
> 
>  I was just scanning the replies wondering why someone has not
>  mentioned "struct" so far!
> 
>  "struct" is very useful to pack data structures in/out of the wire.
>  In fact if you want to convert your data structure to a bytestream, you
>  should first investigate the possiblity of using "struct" before writing
>  custom code or searching other solutions.
> 
> 
> 
> 
>>
>> Once you've done that, check out this cool module that does much of what
>> you are trying to do.  Fair warning though, it uses very advanced Python
>> coding including metaclasses.  You'll learn a lot by carefully figuring
>> out how it does what it does.  For example it avoids the need for a
>> self.order list to sequence the fields of a class definition in a rather
>> clever fashion.
>>
>>  http://code.activestate.com/recipes/498149/
> 
> 
>  This seems like a very useful recipe. Often one requres something
>  which can handle nested objects which struct cannot do, since it wants
>  things to be presented to it as basic data types.
> 
> 
>>
>>
>> I'm probably going to do a source code walkthrough of this module with
>> the Dallas usergroup this Saturday because of its interesting parts.
>>
>> -Jeff
> 
> Hi Jeff, Thanks a lot. Much appreciated. Is the code walkthrough a video
> session or a group meeting 
> at some place. If there is a any link to uploaded of your presentation.
> Please request you to send me one. I will surely follow your links
> meanwhile. Thanks a lot.
>> _______________________________________________
>> BangPypers mailing list
>> BangPypers at python.org
>> http://mail.python.org/mailman/listinfo/bangpypers
>>
> 
> 
> 
> -- 
> -Anand
> 
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
> 
> 

-- 
View this message in context: http://www.nabble.com/calling-instance-of-the-other-class.-tp24145716p24181538.html
Sent from the BangPypers - Bangalore Python Users Group mailing list archive at Nabble.com.



More information about the BangPypers mailing list