Reputation: 3407
I need to execute code from my python script and take interpreter-style output like it's done here.
I am creating website on GAE using django, it must run user-entered code and print interpreter-style output as text.
Upvotes: 0
Views: 392
Reputation: 19924
there is code.InteractiveInterpreter
available, but I think you can take an inspiration in the following simpler example:
import code
exprs = [
'd = {}',
'd',
'd["x"] = 1',
'd',
]
for e in exprs:
print '>>> %s' % e
cmd = code.compile_command(e)
r = eval(cmd)
if r:
print repr(r)
producing the following output:
>>> d = {}
>>> d
{}
>>> d["x"] = 1
>>> d
{'x': 1}
Upvotes: 1
Reputation: 29654
There is an open-source console for app engine that does what you want (if I understood the question correctly). Have a look at it: http://con.appspot.com/console/
Instructions to integrate it with your application are available here.
Upvotes: 0