Proper class initialization

Kent Johnson kent at
Thu Mar 2 13:09:57 CET 2006

Steven Bethard wrote:
> I don't run into this often, but when I do, I usually go Jack 
> Diederich's route::
>     class A(object):
>         class __metaclass__(type):
>             def __init__(cls, name, bases, classdict):
>                 cls.sum = sum(xrange(10))

I think you should call the superclass __init__ as well:

     class __metaclass__(type):
         def __init__(cls, name, bases, classdict):
             super(__metaclass__, cls).__init__(name, bases, classdict)
             cls.sum = sum(xrange(10))


More information about the Python-list mailing list