Defining classes

Michele Simionato michele.simionato at gmail.com
Fri Dec 15 03:41:37 EST 2006


Steven Bethard wrote:
> How are you doing it currently?  Here's a sort of minimalist option:
>
>      >>> class weeble(object):
>      ...     def __metaclass__(name, bases, bodydict):
>      ...         cls = type(name, bases, bodydict)
>      ...         cls.wumpus = 'brinjal', cls
>      ...         return cls
>      ...
>      >>> weeble.wumpus
>      ('brinjal', <class '__main__.weeble'>)
>
> Of course, it still takes four lines and a metaclass...

Well, 'type' is a metaclass, yes, but not a custom metaclass, so I
would say that you are
using the metaclass hook here, but not a "real" metaclass.  Still
waiting for class decorators ...

      Michele Simionato




More information about the Python-list mailing list