One function calling another defined in the same file being exec'd

anon anon at
Fri Jan 8 00:39:45 CET 2010

Rather than exec the files, why not import them?

I can get both your examples to work using the 'imp' module.

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)

More information about the Python-list mailing list