I read some discussion on this list before about how sometimes it's useful to create a generic object class that you can just stick attributes to. I was reading the PyPanel source (not written by me) and I came across this:

#----------------------------------------------------------------------------

class Obj(object):
#----------------------------------------------------------------------------


   """ Multi-purpose class """
   #----------------------------
   def __init__(self, **kwargs):
   #----------------------------
       self.__dict__.update(kwargs)

Normally I'd just use class Obj(object): pass, but the advantage to this method is you can create an Obj like this:

Obj(id="desktop", last=0, color=self.getColor(DESKTOP_COLOR))

You can pass all the attributes you want the object to have this way. Nifty :)

Sorry if this has been posted before, but I haven't seen it.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to