global variables or inheritence
Thomas Rasmussen
simpsons at kom.auc.dk
Wed Apr 26 16:09:22 EDT 2000
>>>>> "Jeff" == Jeff Massung <jmassung at magpiesystems.com> writes:
Jeff> Sorry if I get this wrong... but I thought you'd just import
Jeff> your other file.
Jeff> Example:
Jeff> # File1.py myVar = 2
Jeff> # File2.py import File1 print File1.myVar #should print 2
Well that was also what I thought, but the following program wont
execute:
testprog1.py:
import os, sys, string, testprog2
def main():
print 'hello'
myvar = 2
testprog2.second()
if __name__ == '__main__':
main()
testprog2.py:
import os, sys, string, testprog1
def second():
print testprog1.myvar
if __name__ == '__main__':
print 'nope'
and then I execute python testprog1.py and get the following error:
22:03 simpsons at lada% python testprog1.py ~/python
hejsa
Traceback (innermost last):
File "testprog1.py", line 7, in ?
main()
File "testprog1.py", line 5, in main
testprog2.second()
File "testprog2.py", line 3, in second
print testprog1.myvar
AttributeError: myvar
:-(
Thomas
--
KOM Network student helper
"To alcohol! The cause of - and solution to - all of life's problems!"
-- Homer Simpson
More information about the Python-list
mailing list