Possible Duplicate:
Global Variable from a different file Python
is that possible to set variable in different file ?
So I have two different files somewhat like this..
tes1.py
import test2
st = 'a'
def main():
mis = input('puts: ')
print tes2.set(mis)
main()
tes2.py
def set(object):
pics = ['''
%s
1st
'''%st,
'''
%s
2nd
''']
return pics[object]
and i execute tes1.py and issued an error:
NameError: global name 'st' is not defined
thanks for the respond
A few tips:
main()function in aif __name__ == '__main__'block. It prevents imported modules from executing code that should not be run when being imported. I usually do away withmain()completely and just write all my main code in theifblock.objectis a built-in type. Don’t name thingsobject. Alsoset, as that is a type as well.Here’s how I would do it:
test1.py:
test2.py: