In Python 3.8.10, consider test.py:
A = 3
def foo():
global A, B
A = A*10
B = 5
print((A,B))
If I import test.py
, no problem:
import test
test.foo() => (30, 5)
test.A => 30
test.B => 5
But if I import *
, which variables A and B are referred to as global?:
from test import *
A => 3
foo() => (30, 5) (it read the existing value of A)
A => 3 (apparently a different A was assigned?)
B => undefined (apparently set a different B?)
Now, if I reimport *, the variables become visible:
(continuation of previous commands)
from test import *
A => 30 (not 3??)
B => 5 (?? B isn't even mentioned at the top level of test)
What is going on? Where do variables A and B 'live'?