Online Python exercises

Friday 9 September 2011This is more than 13 years old. Be careful.

I’ve been thinking about online Python learners. There have been some cool examples of online code exercises, like Nathan’s Javascript Lessons. These are great because they require absolutely no setup, and can run right on the web page that describes the concepts involved.

But of course, it’s easy to run Javascript in a browser. What are the options for doing something similar for Python?

CodingBat provides exercises for Java and Python. Your code is actually run on the server. Generally, this is risky, because Python’s dynamic nature makes it notoriously difficult to limit its powers. CodingBat does this aggressively, and manages it only because it limits the code it will run to very simple functions. For example, you cannot import anything.

Another server-side solution is the NCSS Challenge, which uses an elaborate sandboxing technique on the server to run arbitrary Python code. The sandbox is explained in this PyCon AU video by Tim Dawborn. It seems prohibitively complex, but makes it possible to run sophisticated Python code from the browser.

There are other server-side online Python execution pages:

Server-side execution solve the problem of executing Python, but introduces the new problem of keeping the server safe. Can we instead execute Python in the browser? There have been some interesting implementations of this also:

  • Try Python is an in-browser Python implementation using IronPython running in Silverlight. This limits its platform viability, somewhat blunting the benefits of in-browser execution. Also, most of the standard library is missing, and OS services are necessarily limited.
  • Gumby is astounding: Tim Dawborn (again!) and Ben Taylor took CPython, compiled it using llvm, then ran it through an llvm-to-Javascript compiler, to produce a full implementation of CPython that runs natively in the browser. This is one of those dancing bear moments where it isn’t that it does it well, it’s amazing that it does it at all. The problems are the 790Kb Javascript download, and the limited environmental support.
  • Skulpt implements Python in Javascript, from scratch, so it’s really its own Python implementation. Alone among these tools, it experiments with Python access to the browser environment, but still suffers from the in-browser problem of how to provide OS services. Also, because it’s implementing from the ground up, it’s incomplete.

Reviewing all these possibilities, none are perfect, and some are far from it. And I started to wonder, are online exercises worth all this? After all, the point of learning a language is to eventually write your own code, and that won’t happen in a sandbox in a browser. The student will have to install a real Python environment at some point, so why not start with that, and get a better learning environment right off the bat?

Are there other possibilities? Is it important? What about an environment on the student’s computer that can communicate result back to the online environment automatically? Or an online environment that can use the student’s local resources so the server doesn’t need protection?

Comments

[gravatar]
Have you considered running jython in Java Applet?
[gravatar]
Python anywhere is a good alternative for running Python on the server side: http://www.pythonanywhere.com
[gravatar]
You write: Or an online environment that can use the student's local resources so the server doesn't need protection?. Crunchy uses the student's local resources. Titus Brown has just started writing an online tutorial that uses Crunchy. With Crunchy, you can have unitest or doctest-based exercises.
[gravatar]
My feeling is that these web-based tools are excellent learning resources if someone simply wants to try a language out. As you point out, sooner or later if one is serious, an install of some kind is going to be required.

For example, I played around with a mirror of why's online resource for Ruby, and that gave me enough to want to use it properly on my machine. I don't think I could have asked for more.
[gravatar]
Perhaps you could run CPython under Linux running on a PC emulator written in JavaScript, http://bellard.org/jslinux/tech.html , or maybe that would be silly.
[gravatar]
For the NCSS crew, the appeal of in-browser execution is that their educational exercises need to work with the government supplied laptops offered to high schools, and those are a locked down, Windows-only system (apparently our government consider it more appropriate to treat students as nascent digital criminals rather than as future adult citizens and potential IT professionals that are better off learning to control their computers rather than getting used to being controlled *by* them).

Victor Stinner's PySandbox is another interesting tool for safer server side execution, but doesn't protect against various things like memory exhaustion. You need OS level tools for that, hence the elaborate NCSS approach.
[gravatar]
Hmm, there seem to be more of these than I knew. Also PyCloud (http://www.jitouch.com/pycloud/)
[gravatar]
There is also the interactive version of How to Think Like a Computer Scientist.
[gravatar]
If you're building a tutorial, AppEngine could be an option (with the usual "(most of) standard lib only" proviso). That environment is already very heavily sand boxed (as they have a relatively homogenous compute environment, this was a requirement from day 1).

There's also a shell example already, with source:

http://shell.appspot.com/
[gravatar]
A friend of mine opened:
http://learnpython.org/

It's pretty fun and everyone can contribute.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.