help with exec statement
jwm-python at sentinelchicken.net
Fri Jan 3 04:55:43 CET 2003
I am trying to pull dynamic code from database and execute it. I have
done this in the past with files; however, the same method is not working
and I keep getting syntax errors back.
I pass a string (coming out of a MySQL db) to this function:
def dyncode(code, name):
module = imp.new_module(name)
exec code in module.__dict__
This is the contents of the string:
And this is the code that executes generate():
dynModule = dyncode('string','test')
dynCode = dynModule.generate()
And, finally, this is my error:
File "<string>", line 2
SyntaxError: invalid syntax
Now, I've the same this with open files objects before, and that works
fine, but no matter what I try, I can't seem to get this to work.
Any help would be greatly appreciated.
More information about the Python-list