Daniel Mark wrote:
> 
> 1> Does Python provide such Struct in this standard libary.
> Python has "4.3 struct -- Interpret strings as packed binary data", but
> it looks like different
> from what I really want to get.

I like the following version:

class Struct(dict):

     def __getattr__(self,name):

         try:
             val=self[name]
         except KeyError:
             val=super(Struct,self).getattr(self,name)

         return val

     def __setattr__(self,name,val):

         l=dir(self)

         if name in self:
             super(Struct,self).setattr(self,name,val)
         else:
             self[name]=val


it has the added benefit of having all of the dict methods too.


                                bb

-- 
-----------------

              [EMAIL PROTECTED]
              http://web.bryant.edu/~bblais
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to