Proper class initialization

Kent Johnson kent at kentsjohnson.com
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))

Kent



More information about the Python-list mailing list