How can I use variables in other modules in python? -
How can I use variables in other modules in python? -
that's one.py:
test = {'1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]} import 2 two.example()
and that's two.py:
def example(): print test[1][5]
can tell me why fail next error?
nameerror: global name 'test' not defined
thanks!
you can import in function
def example(): 1 import test print test[1][5]
or can pass test in variable
#one.py two.example(test) #two.py def example(test): print test[1][5]
python
Comments
Post a Comment