I have a program in which I intend to compare the contents of a dictionary from two different instances of a class (I intend to make this a routing protocol simulation where FIB tables are compared) and it seems when I update the dictionary in one object, the other has its dictionary updated with the same information.
class bar:
myName = ""
mydict1 = {'a': '', 'b': ''}
mydict2 = {}
def __init__(self, name):
self.myName = name
def addItem(self, x, y):
self.mydict2[x] = y
foo = bar('a')
foo.addItem('a', 'test')
print(foo.myName, foo.mydict2)
foo2 = bar('b')
print(foo2.myName, foo2.mydict2)
The output of this is:
a {'a': 'test'}
b {'a': 'test'}
I'm not sure if this is a quirk with OOP in Python or if I am missing something else, hanks for the help!