Using a class to create several instances in a dictionary, their attribute is not unique. I'd like each of them to have their own unique attribute. How do you do this?
code:
class a(object):
attr_a = {}
def __init__(self, a={}):
self.attr_a = a
if __name__ == '__main__':
b = a()
c = a()
b.attr_a['abc'] = 'abc'
c.attr_a['abc'] = 'def'
print(b.attr_a)
print(c.attr_a)
result:
{'abc': 'def'}
{'abc': 'def'}
wanted result:
{'abc': 'abc'}
{'abc': 'def'}