Possible Duplicate:
Why do attribute references act like this with Python inheritance?
Python: derived classes access dictionary of base class in the same memory location
Lets take the code:
class parent:
book = {'one':1, 'two':2}
class child(parent):
pass
first = child()
second = child()
print first.book
print second.book
second.book['one'] = 3
print first.book
print second.book
When you run this object 'first' has its dictionary edited! WTF? I thought 'first' and 'second' were separate instances of the 'child' class. What is happening here? Why does what you edit in second affect first?
I can 'fix' this by recreating book in each child class but thats not the right way to do it, I want to utilize classes the way they are meant to be used.
What am I doing wrong?
Btw my primary language is cpp so maybe i'm confusing cpp with python or something silly like that...
Any help would be greatly appreciated!