I have two scripts, one calling the other in Python 27. The first script, Script1.py, contains some conditional statements. Then I have a second script, Script2.py that calls the first script and passes an argument to the function, func1 imported from the first script.
However I then get an error when running the second script that the variables in func1 are not defined. Why is this? What should I do to resolve?
Thanks
Script1.py:
def func1(var):
if var == '1':
test1 = 'a'
test2 = 'b'
test3 = 'c'
if var == '2':
test1 = 'd'
test2 = 'e'
test3 = 'f'
Script2.py:
from Script1 import func1
func1('1')
print test1, test2, test3
func1('2')
print test1, test2, test3
Traceback (most recent call last):
File "G:/Python27/Script2.py", line 5, in <module>
print test1, test2, test3
NameError: name 'test1' is not defined
ifand a single=don't go together.return test1, test2, test3; and then you could call it this way:test1, test2, test3 = func1('1').