Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Class Methods

Thomas Hellerthomas.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 modifiedExactly. Initialize(X) would for example calculate (initialize) certain classattributes from other class attributes.There are (even in the standard python library) usagepatterns 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 beencreated. What if someone need the (calculated) classattributes 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-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp