` pyworksheet, an online tool for experimenting with python

pyworksheet, an online tool for experimenting with python

I was recently inspired by the Scala worksheet plugin for Eclipse and could see how it was a great resource for learning to program in Scala. I started working on trying to create something similar for Python.

I've hosted an initial effort hosted on Google App Engine. To try it, visit http://pyworksheet.appspot.com. You can enter Python code into the widget and press the Go button to execute it - execution results are pasted into the code as comments and the widget display is refreshed.

The widget uses the excellent CodeMirror JavaScript library (http://codemirror.net) to provide the code editor component with Python-specific smart indenting and syntax coloring (CodeMirror also supports a large number of other languanges).

The pyworksheet app works by using Python's AST module to parse the submitted code. The result is a parse-tree of nodes representing the code. Each top level Node is then executed sequentially. The values and types of top level expressions and assignments are pasted into the code as comments. Any output written to stdout is also collected and pasted into the code that is displayed back to the user. Any errors encountered are also pasted into the code as comments.

There are a few restrictions I've imposed. Importing from the Google App Engine packages or from urllib,urllib2 or httplib packages is not permitted. Also, Google App Engine limits execution time to 60 seconds. Otherwise, it should be possible to experiment with and run a wide range of Python programs in the app. The version of Python supported is Python 2.7.


 

Leave a comment

Anti-Spam Check
Comment