From: cgw at fnal.gov (Charles G Waldman)
Date: Sun, 11 Apr 1999 06:58:43 GMT
Subject: Python's object model
Message-ID: <199904110658.BAA06796@buffalo.fnal.gov>
X-UID: 1155                                                  

This "Stack" class:


class Stack:
        stack = []

        def push(self, value):
                self.stack.append(value)

        ...

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 = ()

	def push(self, value):
	...

Also note that in the not-quite-yet released Python 1.5.2 the builtin
list objects have a pop() method, which is kind of handy.




