Using classes in python
trevor lock
trvr_lock at yahoo.com
Wed Oct 25 15:19:20 EDT 2006
Hello,
I've just started using python and have observed the following :
class foo:
a=[]
def __init__(self, val):
self.a.append ( val )
def getA(self):
print self.a
return self.a
z = foo(5)
y = foo(4)
z.getA()
>> [5, 4]
I was expecting that everytime I created an instance of the class that a unique dictionary was also created, however it seems that only one dictionary is created.
How can I create a new dictionary for each instance?
Thanks,
Trevor.
---------------------------------
All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061025/d7ddddfd/attachment.html>
More information about the Python-list
mailing list