I want to make i into 3 in file s2.py, but it keeps becoming 1.
File s1.py
i=1
class a():
def f():
global i
i = 3
File s2.py
from s1 import *
a.f()
print(i)
I want to make i into 3 in file s2.py, but it keeps becoming 1.
i=1
class a():
def f():
global i
i = 3
from s1 import *
a.f()
print(i)
#s1.py
i=1
class a():
def f():
global i
i += 3
#s2.py
import s1
s1.a.f()
print(s1.i)
I believe you are referencing the local variable i and aren't referencing the instance of i in the class. Try this.
print(a.i)
i in the class. Calling print(a.i) will throw an error. There are only two instances if i, one in s1 and one in s2 (created using from s1 import *).