A.py:
X = 10
B.py:
import A
A.X = 100
C.py:
import A
Print("A.X = ",A.X)
If I execute B and then C , I get A.X = 10.
But what about the changes made by module B on X?
Why the changes are not reflecting in module C?
A.py:
X = 10
B.py:
import A
A.X = 100
C.py:
import A
Print("A.X = ",A.X)
If I execute B and then C , I get A.X = 10.
But what about the changes made by module B on X?
Why the changes are not reflecting in module C?
Python scripts run in separate shells with separate process, memories, namespaces, etc. Modifying a module attribute in a script is a in-memory operation: it does not affect the file that the module was loaded from:
$ python B.py
This will create a python process, load B.py, then A.py, and modify the dictionary corresponding to the namespace of module A. Then the process will end, losing anything you didn't write to disk.
$ python C.py
This will create a python process, load C.py, then A.py, and print the freshly loaded value from the dictionary of the newly read-in module A. This will be whatever was in the file A.py.