Defining classes
Duncan Booth
duncan.booth at invalid.invalid
Wed Dec 13 16:56:15 EST 2006
nmm1 at cus.cam.ac.uk (Nick Maclaren) wrote:
>
> I am defining a class, and I need to refer to that class when
> setting up its static data - don't ask - like this:
>
> Class weeble :
> wumpus = brinjal(weeble)
You cannot refer to weeble until it has been created which isn't until
after all of the statements in the class body have executed. The usual way
to achieve what you want is to assign the static member from outside the
class.
class weeble:
pass
weeble.wumpus = brinjal(weeble)
Alternatively you can play tricks with metaclasses for a similar effect.
More information about the Python-list
mailing list