I have a two-file setup:
File 1:
global test
test = 1
import FooBar
FooBar()
File 2 (FoorBar.py):
class FooBar:
def Foo:
print test
Essentially, I want to pass the variable test from File 1 to File 2. With the above code I get the exception:
NameError: global name not defined (Python)
You could try a different approach:
File 1
File 2
or
File 1
File 2
The difference is that in the first case the “test” variable would be static, i.e. the same for all instances of FooBar, in the second case it would be local to an instance (so different for all instances).