When I try to add an entry to a dictionary within a class, it overrides dictionaries in all other instances of that class. Is there a way to make the dictionaries unique to each instance of the class?
class Object:
dictionary = {}
def __init__(self):
return
a = Object()
a.dictionary["abc"] = "Hello, World!"
b = Object()
b.dictionary["abc"] = "Goodbye, World!"
print(a.dictionary["abc"])
In this example, it prints "Goodbye, World!"
. I would think a.dictionary
and b.dictionary
are two separate entities, so changing one should have no effect on the other. Is there a way I can have unique dictionaries for a
and b
so that I can manipulate one without affecting the other, so a.dictionary["abc"]
is "Hello, World!"
and b.dictionary["abc"]
is "Goodbye, World!"
?