[Python-Dev] class_init (original) (raw)
Thomas Heller thomas.heller@ion-tof.com
Thu, 15 Nov 2001 16:06:50 +0100
- Previous message: [Python-Dev] __class_init__
- Next message: [Python-Dev] __class_init__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: "Skip Montanaro" <skip@pobox.com>
>> [classinit]
Tim> [Guido said] ... "The right way" is to define a custom metaclass Tim> instead (whose init plays the role classinit would have Tim> played if defined in the class). It makes sense to me, but I'll Tim> have to play with it to be convinced it's as usable. For those of us with next to no ExtensionClass experience, I think it would be helpful to describe what classinit does. I saw it there in the PyGtk 2.x wrappers before JamesH converted to new-style classes. I had no idea what it did (and blissfully ignored it) and James apparently didn't need any similar functionality after the conversion.
class_init (or was it called init_class?) is a class method which is called when the class is created (the class statement executed).
class X(ExtensionClass.Base): def class_init(cls): print cls, "created"
class Y(X): pass
would first print ' created' and then ' created'.
It can be used to initialize class attributes for example depending on other class attributes (that's at least what I have/had in mind).
Thomas
- Previous message: [Python-Dev] __class_init__
- Next message: [Python-Dev] __class_init__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]