Suppose I have the following module:
blah.py
a = 1
someDict = {'a' : 1, 'b': 2, 'c' : 3}
In the next python session I get the following:
>>> from blah import a, someDict
>>> a
1
>>> someDict
{'a': 1, 'b': 2, 'c': 3}
>>> a = 100
>>> someDict['a'] = 100
>>> del a, someDict
>>> from blah import a, someDict
>>> a
1
>>> someDict['a']
100
>>> import blah
>>> blah.someDict['a']
100
It appears that when I modify an object that I imported from another module, and then re-import that object, it recovers its original value expressed in the module. But this doesn't apply to values in a dictionary. If I want to recover the original value of someDict
after making any modification, I have to close the current python session and open a new one. I find that this is even true if I merely called a function that modifies the dict elements.
Why does this happen? And is there some way I can re-import the dictionary with its original value without starting a new python session?