[Python-Dev] Class Methods
Thomas Heller
thomas.heller at ion-tof.com
Sat Apr 21 07:12:31 EDT 2001
[I wrote]
> > > What I want to avoid is
> > >
> > > class X(...):
> > > ....
> > > initialize(X)
> >
[and GvR asked]
> > What would initialize(X) do that you can't write in the class body?
>
[finally Alex gave the answer]
> I'm not sure, maybe use the class object X itself? That object
> isn't available in the class body. For example, initialize(X)
> could among other things enregister class object X with any
> appropriate registrars, as above. But that may not be what
> is meant, as "initialize" may be meant to imply that the
> argument object is modified
Exactly. Initialize(X) would for example calculate (initialize) certain class
attributes from other class attributes.
There are (even in the standard python library) usage
patterns going like this:
class X:
_inited = 0
def __init__(self, ...):
if not _inited:
<code to set some class attributes>
....
This is really not instance but class initialization,
and it is deferred until the first instance has been
created. What if someone need the (calculated) class
attributes before this?
> (and I don't understand why
> one would need to avoid the example usage I proposed,
> anyway).
Which example?
Thomas
More information about the Python-list
mailing list