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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to