I am using google app engine and I am trying to basically allow users to upload code, where it will later be executed by the server. I also have to be able to send variables to the scripts, which is why initially when I was running everything on my desktop, I Imported everything dynamically (as in- the name of the script is stored in a variable). But now I can not do this because of the filesystem in the google app engine environment.
I already have a database setup so that I can get the code in plain-text. But now I would like to know if there was any way that I could import a python script, not from a file but from a variable containing python code.
For example, If this was the plain-text code, how could I get this to execute properly:
code = """
def Main(var):
print "you entered: " + var
"""
First, create a module for the code to live in:
You’ll probably want to register that module, too:
Then compile the code:
Then execute the code object in the context of the module: