In short: you cannot force it to print "ok" without changing the code.
from a import x, changeX equivalent to:
import a x = ax changeX = a.changeX
In other words, from a import x does not create x , which is indirectly related to ax , it creates a new global variable x in module b with the current value of ax . It follows that later changes to ax do not affect bx .
To make your code work as intended, just change the code in b.py to import a :
import a a.changeX() print ax
You will have less cluttered imports, it is easier to read the code (because it clears which identifier comes from without looking at the import list), fewer problems with cyclic import (because not all identifiers are needed right away), and more chances for such tools to work like reload .
source share