Instances behaviour

Mr.Rech andrea.riciputi at gmail.com
Fri Dec 2 04:53:06 EST 2005


Thanks for your suggestions. They are very usefull and indeed bypass my
problem. However, I've found a (perhaps) more elegant way to get the
same result using metaclasses. My idea is to define my classes as
follows:

>>> class meta_A(type):
....      def __new__(cls, classname, bases, classdict):
             # define here all special methods
             newdict = { #special methods dict}
             classdict.update(newdict) # any suggestion on
automatically build newdict?
             return type.__new__(cls, classname, bases, classdict)

>>> class B(object):
          __metaclass__ = meta_A
          # More methods here

I know metaclasses are a complete different beast, anyway I find this
approach more pythonic. Any comment? Suggestion?

Thanks,
 Andrea.




More information about the Python-list mailing list