For a few months (ever since I started teaching Intro to CS in Python), I’ve been looking for the easiest way to get brand new students practicing with writing Python as quickly as possible. I soon was convinced that being able to run Python code in the browser was what I really wanted (since trying to support all of them getting set up with their own machines takes a while). While there are great websites out there that let you run Python in the browser, they all require that I send students to that third-party site, which is an extra step that I chafed at. I felt like there had to be an easy way to give them a space to try things out right on this website (since I send them here for readings and labs anyway), but I couldn’t find quite what I was looking for.

The fabulous Acacia Ackles has just solved my problem and I’m ecstatic. PyScript makes it so blissfully easy to put a Python REPL anywhere that JavaScript is supported, and it’s going to open up a whole world of possibility for next year!

I just had to add one JavaScript include line and now I can do this:

Try printing test:

test=2 print(test)

That just looks like this:

<py-repl id="my-repl">