Forums

Python shells on a website?

Can one spawn anonymous python shells on website like one on python.org but with only able to run a single script? If not, what javascript-python shell you'd recommend to use with pythonanywhere account? What is used on python.org?

I have a text game written in python and cmd-module (dunno if I'm going to curses later) that I'd like to put up for testing. I know now that I should have written it with javascript to start with, but now I'd like just to concentrate on developing what I have done so far. On the other hand if I get the terminals running here fine I sure could use the PythonAnywhere server for multiplayer features.

To get embedded consoles like the one on python.org, just do something like this:

<iframe style="width: 640; height: 480; border: none;" name="embedded_python_anywhere" src="http://www.pythonanywhere.com/embedded3/"></iframe>

If you want to limiting it to run a single script, perhaps check out our gist consoles.

Thank you for your reply. What I'd want to do is more like telehack.com -style anonymous consoles to every visitor, running a predefined python-script. I have the impression that pythonanywhere gist console is more like show-and-tell-type of solution. I already installed shell-in-box to my account, but my server-fu is not yet quite enough to get it running. I'm considering other options too like switching to js or running my own server. Funny how little weekend hobby coding project all of the sudden spins out dozen of new projects.

I reckon gist consoles would be able to do pretty much what you want. They are separate anonymous consoles for each visitor, and they can run pretty much any script. Of course, there are limitations on how much CPU they can use... and there is PythonAnywhere-related stuff around the side of the page.

Is it possible to embed a Python console like the one on python.org, but with my own packages installed that are not installed by default?

You could try creating a PythonAnywhere gist console that opens a shell that then installs the packages?

Tried below on https://www.pythonanywhere.com/embedded3/

import pip, site, importlib
pip.main(['install', '--user', 'ystockquote']) # ystockquote could be any package on PyPI
importlib.reload(site)
import ystockquote

It worked! Thanks.