Dear tutors,

I have the following code snippet:

class N (object) :

        def __init__ (self, d={}) :
                self.d = d
                
n1 = N ()
n1.d['a'] = 1

n2 = N ()
n2.d['a'] = 2

print n1.d['a']
print n2.d['a']

I assumed that on each call of the __init__ without a dictionary
provided, a new dictionary is created. This turns out to be not the
case:

[EMAIL PROTECTED]:~$ python test.py
2
2

Does anybody know why this is the case? And what would be the most
convenient solution to enforce the dynamic creation of the dictionary?

Many thanks for your time and patience,

Bart.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to