I am trying to make a change to a global variable across classes. Here is my code:
file main.py
import class2
class first:
def changeA(self):
global a
print a
a += 2
print a
test0 = first()
test1 = class2.second()
test2 = first()
test3 = class2.second()
test0.changeA()
test1.changeA()
test2.changeA()
test3.changeA()
file class2.py
a = 1
class second:
def changeA(self):
global a
print a
a += 1
print a
But it returns an error: global name 'a' is not defined. Is there any proper way to access and change a global variable across files in python? Thanks in advance