In import in bar.py , the identifier i to i in the module namespace bar.py , which points to the same address as the identifier named i in the module namespace foo.py
This is an important difference ... bar.i does not point to foo.i , but rather to the same space in memory where object 10 is stored, which points to foo.i at the same time. In python, variable names are not memory space .. They are an identifier pointing to memory space. When importing into a bar, you configure the local namespace identifier.
Your code behaves as expected until foo.fi() is called when the identifier i in the namespace foo.py is changed to point to literal 99, which is an object in memory, obviously in other than 10. Now the namespace at the level of the dict module for foo has i identification of another object in memory than the identifier i in bar.py.
Shane and rossfabricant have good suggestions for setting up modules to achieve what they want.
source share