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.


Jeff Rush wrote:
> 
> learningpython wrote:
>> Sorry Senthil and all,
>> I am sure, it's pretty easy but don't i am not able to catch it. In C, i
>> just pass the & of the another structure in the structure element, some
>> thing close.
> 
> The equivalent to the & operator in C is just an object reference in
> Python.
> 
>> class Send_Msg_req(msg):
>>      def __init__(self):
>>        self.usr_mac =< Earlier class defined > 
>>        self.msgtype = <blah>
>>        self.msgsize = <blah>
>>        self.order = ['usr_mac', 
>>                       'msgtype ',
>>                        'msgsize ']
> 
> so the line becomes just:
> 
>   self.usr.mac = usr_mac()
> 
> where you declared usr_mac as a class in your prior email.  If the
> usr_mac() call needs arguments, provide them in the __init__ for
> Send_MSG_req and pass them through:
> 
>   class Send_Msg_req(msg):
>       def __init__(self, a, b):
>           self.usr_mac = usr_mac(a, b)
>           self.msgtype = BV.Bit24.new()
> 
> You haven't mentioned it but from here you'll need a flattener.  From
> your code I presume you have the idea for one already, in that:
> 
>>        self.msgtype = <blah>
>>        self.msgsize = <blah>
>>        self.order = ['usr_mac',
>>                       'msgtype ',
>>                        'msgsize ']
> 
> at some point you have a method defined for the base 'msg' class that
> uses the self.order list to construct the actual bitstream going out the
> serial port from the various object attributes.  So your BV.Bit24 class
> has some method that gives you back the 24-bits that make it up.  The
> method that walks self.order and returns the raw bits is a flattener.
> 
> Now with the declaring of self.usr_mac referencing an earlier class, you
> just need to extend the idea of a flattener a bit further.  So when you
> call:
> 
>   msg = Send_Msg_req(MSG_A, 34)
>   serial.output(msg.flatten())
> 
> that .flatten method, upon encountering the self.usr_mac attribute,
> calls the .flatten method of the usr_mac class and merges those bits
> into the stream it is building for the Send_Msg_req class.
> 
> This is why it is called a flattener -- it walks a tree of msg fragments
> and constructs a flat sequence of bits making up a single message.
> 
> Another example of the use of a flattener is the STAN DOM used in the
> Nevow templating module used with the Twisted web framework.
> 
>   http://www.kieranholland.com/code/documentation/nevow-stan/
> 
> It takes an object graph of nested lists and attributes and returns a
> flat string of HTML.  It goes a bit further in that it has an extensible
> registry of adapters for teaching the system to handle new kinds of
> object graph nodes.
> 
> -Jeff
> _______________________________________________
> BangPypers mailing list
> BangPypers@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
> 
> 

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

_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to