Newbie question about dictionaries in classes

Jacek Pliszka pliszka at fuw.edu.pl
Mon Apr 23 15:24:15 EDT 2001


Hi!

I just started to learn Python and I got stuck with the following
problem:

class myclass:
    aaa={}
    def add(self,u):
        (self.aaa)[u]=1
    def show(self):
        print self.aaa

ula=myclass({})

ula.add(13)

ola=myclass({})

ula.add(11)

ola.add(11)

ula.show()

ola.show()

then I get the result that aaa in both ula and ola
is identical!!! I thought that aaa will be different for
ula and ola!!

What am I doing wrong?

Thanks in advance for any help,

Jacek





More information about the Python-list mailing list