[Tutor] multiple class instances
Deirdre Saoirse
deirdre@deirdre.net
Mon, 10 May 1999 12:48:33 -0400 (EDT)
On Mon, 10 May 1999, Corran Webster wrote:
> I suspect that you're thinking in C++ terms here - Python is much more
> dynamic, so the correct place to create instance data is in the __init__
> method as follows:
>
> class Spam:
> def __init__(self):
> self.choice = "I'll have the spam."
It's only necessary to create it in __init__ if it's necessary for the
instantiation of the class. Otherwise, it can be done in any method with
the self directive. (I'm more from the C++ school where you'd write a
method to fuss with any variables rather than manipulating them directly
outside the class definition)
_Deirdre * http://www.linuxcabal.org * http://www.deirdre.net
"Everyone needs the luff of a fine penguin" -- Mikey