Any advice on running Python code from the user?

I’m working on an app to let my non-CS students play with Python. It’s intended to be a web based version of a Windows only tool I currently use, so that my students who use Macs can use it, too. Plus I can fix some of the issues I have with the current tool.

I had expected to be able to use something like Antlr for parsing the Python the students write and perform actions in the app based on that. I’m familiar with Antlr and comfortable working with it. Unfortunately, apparently Antlr doesn’t work in the browser (it relies heavily on require, for one).

With that approach gone, I wondered if I could leverage Skulpt to run the user’s Python programs. But, I’d need to define some custom built-in functions, and I don’t know if I can do that without messing up Anvil’s runtime.

Can someone who knows Skulpt and Anvil comment on that? Or anyone else with experience with this sort of thing suggest a non-Skulpt option?

I had good experiences with both trinket.io and repl.it
(trinket.io uses skulpt for it’s free python option).

Another option is runestone, which also uses skulpt. It’s an education platform allowing you to author your own textbooks online.

1 Like

Sorry, I guess I wasn’t clear. I’m writing an Anvil app to serve as a mini-IDE for my students, and want to run their Python code inside the Anvil app with customized functions that interact with the app to display results (moving a robot around a 2D room, interacting with objects in the room, etc).

I love repl.it, and have used it for some coding camps, but I’m looking for something more customized/targeted for this audience.

Two things that may help - you can use exec on the client.
You can also incorporate a code editor relatively easily with codemirror and anvil.js.

I’ve already got Codemirror working, and that’s looking great (and was very easy to get working).

It’s just running the Python code that’s still left…I had totally forgotten about exec. That should fit most of what I need, thanks!

1 Like

I myself am making something like that. Although you will have to use Uplink or Server module when it comes to teaching about Pandas and Numpy