0

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.

10
  • 2
    Is there a specific problem that you are having that you need help with? Commented Jan 14, 2010 at 14:01
  • What context are you doing this? From the command line you do python script >log. Are you writing a desktop application, like IDLE? Are you creating a web site that runs Python code? What are you talking about? Commented Jan 14, 2010 at 14:13
  • I am creating website on GAE using django, it must run dynamic code and print interpreter-style output. How can I take interpreter-style output if I have code in a string form? Commented Jan 14, 2010 at 14:18
  • @Dmitry: Do you want to format the code as HTML or text? Commented Jan 14, 2010 at 14:27
  • What do you mean by "dynamic code"? Commented Jan 14, 2010 at 14:28

2 Answers 2

1

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}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.