From: francois.bedard at usa.net (Francois Bedard)
Date: Mon, 12 Apr 1999 01:49:46 GMT
Subject: Python's object model
References: <37102ED0.933EDDA6@usa.net>
Message-ID: <37115155.2B3D6B12@usa.net>
Content-Length: 1337
X-UID: 1467                                                  

Thank you both, Charles and Florent. I'm most familiar with Eiffel's
object model and apparently generalized a bit hastily, but your answers
did clarify things...

Francois

Francois Bedard wrote :
> 
> I'm new at Python. In the following program, "stack_1 pops stack_2's
> content" (that's actually what it prints), which is obviously not what
> I'm after - nor would expect. [...]
> 
> class Stack:
>         stack = []
> [...]
>
> class System:
>         stack_1 = Stack()
>         stack_2 = Stack()
> [...]

Charles G Waldman wrote :
> 
> This "Stack" class [...]
> doesn't work as you expected because the way you've declared it, the
> ".stack" attribute is a class attribute (shared by all instances of
> the class) rather than an instance attribute.  To create instance
> attriubtes, create them in the initializer, like this:
> 
> class Stack:
>         def __init__(self):
>             self.stack = ()
> [...]

Florent Heyworth wrote :
> 
> what you're seeing is the difference between a class and an
> instance variable. To see the behaviour you want you need to
> modify your stack class as follows:
> 
> class Stack:
>         def __init__(self):
>             self.stack = []
> [...]
> 
> Otherwise the stack is a class variable which can be referred as
> Stack.stack() (this would then act as a class global).
> [...]




