[Edu-sig] Easy Web Environment to post pupils Python Creations

Francois Dion francois.dion at gmail.com
Tue Jan 29 21:43:22 CET 2013


On Fri, Jan 18, 2013 at 7:21 PM, Jurgis Pralgauskis
<jurgis.pralgauskis at gmail.com> wrote:
> http://www.skulpt.org/  or  http://www.brython.info/ ?
> They are made on javascript - so if you don't need to save stuff
> serverside - might be good enough.

I didn't have time to comment on this earlier, but as a follow up on
this Brython will allow you to directly save client side using HTML5
local storage. You can also save through an ajax call, so you could
create a small write() function (in Python) to wrap an ajax call (req
= ajax() and then req.open in synchronous mode and req.send) to post
the data to your server, but it does require some infrastructure.

Regarding the original question, about putting text adventures on the
web, it's a funny thing, because that's what I've had on my mind since
I heard about Brython. Initially it didn't even have print(), and to
me that was a basic requirement. so I created a webprint for brython (
http://raspberry-python.blogspot.com/2012/12/brython-browser-python.html
), but then Pierre (the author) added print(). The next piece of the
puzzle was the raw_input() (or in this case input() since Brython is
Python 3.x ). Pierre, Andre (Roberge, fellow edu-sig member) and I
went through various discussions on how this could work. In the end, I
had to go back to my original thought of having input() bringing up a
web browser prompt (javascript prompt) so the call would be blocking,
to flow just like a Python script.

To test this, I grabbed a simple python text adventure from a blog (
http://livingcode.org/entries/2008-02-22_simple-text-adventure/ ) and
plugged it in the web page, with minimum change, namely to convert it
to Python 3.x syntax. The purpose of getting code I didn't write to
test the idea, was that I knew how to code around the limitations of a
web browser (event driven vs the linear approach of a typical Python
script), so if my code ran ok, it wouldn't prove the suitability of
the solution. So the code from the blog ran, but it's not 100% what
one would expect. You can check it out for yourselves here (it's my
Brython playground, on free hosting so it's not particularly fast to
answer):

http://brython.heliohost.org/demos/simpleadventure.html

A more proper way of doing this does require eliminating the while
True: loop and replacing it with a function, and moving the input to
the end of the function:

http://brython.heliohost.org/demos/simpleadventure1.html

Still, it is close to a solution.

Francois

--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion


More information about the Edu-sig mailing list