I am defining some base class, and i want to add dict variable with default values to it like this:
class A(object):
d = {'a':None, 'b': None}
def __init__(self, data):
self.data=data
The problem is: when in one of the instances interacts with dict d
, it affects all instances. Here is an example:
In [109]: f = A([1,2,3])
In [110]: ff = A([4,5,6])
In [111]: f.d['a']="hello"
In [112]: ff.d
Out[112]: {'a': 'hello', 'b': None}
Is there a way to declare this variable in the base class so that when changed it will not affect other instances of the class?