One function calling another defined in the same file being exec'd
anon
anon at blank.com
Thu Jan 7 18:39:45 EST 2010
Rather than exec the files, why not import them?
I can get both your examples to work using the 'imp' module.
http://docs.python.org/3.1/library/imp.html#module-imp
I used python 2.6.4. Note that 3.1 also has 'importlib' module.
import imp
# the name of the python file written by a user
name = 'test1'
fp, pathname, description = imp.find_module(name)
test1 = imp.load_module(name, fp, pathname, description)
print test1.result
# remember to close file (see docs)
fp.close()
More information about the Python-list
mailing list