I need to access global variable (g). which was present in another python file inside the class. Please suggest me how to access.
test1.py:
class cls():
def m1(self):
inVar = 'inside_method'
global g
g = "Global"
x = 10
y = 20
print("Inside_method", inVar)
print (x)
print (y)
print (g)
obj = cls()
obj.m1()
test2.py:
from test1 import *
print (cls.m1) # I can access all variables in method
print (cls.m1.g) # getting error while accessing variable inside the function
I expected to access variable 'g' from my test2.py. Could you please help me out.
gsimply does not belong tom1.