Python Interactive Interpreter in a Browser

Ok, so I lied. One more entry on Silverlight. I've got a proof of concept 'Interactive Interpreter in the Browser' working with IronPython & Silverlight. There are lots of ways it could be improved (I'll discuss these in a minute), but it is still quite fun.

This could be embedded into web based tutorials (like Crunchy) to provide live examples. Because the Python code executes in the browser (not on the server) there are no security issues to worry about. It doesn't actually use the Silverlight canvas, just an HTML textarea and text input field, so you could have several in a page if you wanted. You could also prepopulate the namespace(s) with live objects.

It has several limitations, most of which someone (you?) could fix and one of which will have to wait for the next update to Silverlight. If you fancy downloading it as it is, head over to my IronPython & Silverlight Page.

It would be greatly improved by being in a single textarea field. Only the last line after the prompt should be editable. This is fiddly to do in a cross-browser way, but not very difficult [1].

Evaluated expressions aren't shown as they are in the 'normal' interactive interpreter (you have to use print to see the result). This is actually due to a bug in IronPython 2, which will be fixed in the next release (basically a one line fix!) [2]!.

You have to provide the standard library if you want it to be available!

In Silverlight the file type doesn't exist (for a good reason), so more stuff than usual is broken.

Note that this does use some standard library modules, which I've modified slightly to work with IronPython & Silverlight. These are included in the download.

Some of the editing code could be borrowed from PyShell which is a wxPython interpreter widget that operates in a control very similar in appearance to a textarea. It also uses the Python standard library code module.

There is code in the DLRConsole IronPython example which could be used if you are desperate to get a working version of this. It takes a very different approach and so would be a lot more code - but the source code is very readable if you are prepared to work with the DLR API.