dynamic function

Xaver Hinterhuber xaver_hinterhuber at web.de
Mon May 10 05:03:03 EDT 2004


Hello pythonistas,

I have programmed a product in Zope which allows me to source code on the
web.
Now I want to compile the code into a function and execute the function.
The code is as follows:

import new
code = compile(srcString, 'getContent', 'exec')
f = new.function(code, globalDict, 'getContent')

If srcString contains a return statement, then
python returns a CompilationError stating, that I cannot use return outside
a function.
How do I have to compile the sourcecode to get around this problem?

-- 
Mit freundlichen Grüssen
Xaver Hinterhuber





More information about the Python-list mailing list