'Once' properties.

Scott David Daniels Scott.Daniels at Acm.Org
Tue Oct 6 10:25:41 EDT 2009


Scott David Daniels wrote:
> ...
> Look into metaclasses:
...
>     class Initialized(ClassBase):
>         @classmethod
>         def _init_class(class_):
>             class_.a, class_.b = 1, 2
>             super(Initialized, class_)._init_class()

Mea culpa:  Here super is _not_ a good idea, and I had tried that
and recoded, but cut and pasted the wrong code.  I just noticed
that I had done so this morning.

     class Initialized(ClassBase):
         @classmethod
         def _init_class(class_):
             class_.a, class_.b = 1, 2
             ClassBase._init_class()

     print Initialized.a, Initialized.b

Much better.  There is probably a way to get to the MRO, but for now,
this should do.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list