dynamic function

X

Xaver Hinterhuber

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?
 
T

Terry Reedy

Xaver Hinterhuber said:
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.

If the source is a comple def statement with a know name...
'this works'

Terry J. Reedy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top