Hi there.
I have two files:
<i> a.py:
print('in a') import b print('var') VAR = 1 def p(): print('{}, {}'.format(VAR, id(VAR))) if __name__ == '__main__': VAR = -1 p() bp()
<i> b.py:
print('in b') import a def p(): ap()
I do not understand why there are two different VARs that must be the same.
If I transfer the main unit to another file, everything will be fine, i.e. there is only one var.
<i> c.py:
import a import b if __name__ == '__main__': a.VAR = -1 ap() bp()
So my question is:
Why do the last two lines of a.py print different results?
Do they not print the same VAR variable in a.py?
By the way, I am using python 2.7 on win7.
Thanks.
source share