Class probkem - getting msg that self not defined

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon May 22 20:37:19 EDT 2006


Andrew Robert a écrit :
> Hi Everyone,
> 
> I am having a problem with a class and hope you can help.
> 
> When I try to use the class listed below, I get the statement that self
> is not defined.
> 		
> test=TriggerMessage(data)
> var = test.decode(self.qname)
> 
> I would have thought that self would have carried forward when I grabbed
> an instance of TriggerMessage.

Hint : what is the name of your TriggerMessage instance in the above code ?

I think that what you wannt is more like this :

import struct

class TriggerMessage(object):
     def __init__(self,data):
         """
         Unpacks the passed binary data based on the
         MQTCM2 format dictated in
         the MQ Application Programming Reference
         """
         self._format = '4s 4s 48s 48s 64s 4s 256s 128s 128s 48s'
         self._data = data

         (self.version,
          self.qname,
          self.processname,
          self.triggerdata,
          self.appltype,
          self.applid,
          self.envdata,
          self.userdata,
          self.qmgr) = self._decode()

     def _decode(self):
         assert len(self._data) == struct.calcsize(self._format)
         return struct.unpack(self._format, self._data)

# test code
# data = ???
test=TriggerMessage(data)
var = test.qname



More information about the Python-list mailing list