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() -- http://mail.python.org/mailman/listinfo/python-list