Try Python update

M

Mike Meyer

After spending time I should have been sleeping working on it, the try
python site is much more functional. It now allows statements,
including multi-line statements and expressions. You can't create code
objects yet, so it's still more a programmable calculator than
anything real.

I've got some of the tutorial text (literally) up as well. I hope to
make it easier to read the tutorial and interact with python at the
same time in the near future.

The url is http://www.mired.org/home/mwm/try_python/. Reports of
problems would appreciated.

If you want to try an online P{ython tool that lets you save code, try
Devan L's at http://www.datamech.com/devan/trypython/trypython.py.

<mike
 
U

UrsusMaximus

Cool. I think its really a good thing. Could come in handy when one is
on a strange Windows machine with no Python installed, or when using a
PDA that doesn't have Python etc.

And its just a neat feat. ;-)))

Ron
 
D

Devan L

Mike said:
After spending time I should have been sleeping working on it, the try
python site is much more functional. It now allows statements,
including multi-line statements and expressions. You can't create code
objects yet, so it's still more a programmable calculator than
anything real.

I've got some of the tutorial text (literally) up as well. I hope to
make it easier to read the tutorial and interact with python at the
same time in the near future.

The url is http://www.mired.org/home/mwm/try_python/. Reports of
problems would appreciated.

If you want to try an online P{ython tool that lets you save code, try
Devan L's at http://www.datamech.com/devan/trypython/trypython.py.

My code uses one of the recipes from the Python Cookbook, 7.6 Pickling
Code Objects. It's limited to closures though, just like in the recipe.
So uh, you can't write closures in mine.

On a side note, my brother has tinkered with the C internals and now
__subclasses__ is restricted and many, many os and posix commands are
restricted (not that you can get them anyways, since importing is
broken!)
 
M

Mike Meyer

Devan L said:
My code uses one of the recipes from the Python Cookbook, 7.6 Pickling
Code Objects. It's limited to closures though, just like in the recipe.
So uh, you can't write closures in mine.

I don't have the dead trees version, and the online version doesn't
have chapter numbers. Is that <URL:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/212565>?
On a side note, my brother has tinkered with the C internals and now
__subclasses__ is restricted and many, many os and posix commands are
restricted (not that you can get them anyways, since importing is
broken!)

I got import to work by pickling pairs of names - the variable name
that references the module, and the name of the module. When it
unpickles the list, it reimports them and points the appropriate
variable at them. This had unwanted effects if you did an "import
this". It also doesn't work for objects that contain references to
modules.

I tried for a bit to restrict things, then gave up and did it
externally. There's no access to any files but those required to run
the script that deals with thing, and some other python modules that I
decided would be nice to have. Normally, nothing in the tree is
writable, either. Once I'm happy with it, I'll save a copy of the tree
somewhere and set up a cron job to "refresh" it at regular intervals.

<mike
 
D

Devan L

Mike said:
I don't have the dead trees version, and the online version doesn't
have chapter numbers. Is that <URL:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/212565>?

It was one of the recipes of the day, actually. They don't keep them up
for more than a week, though, I think. But more or less it has all of
the attributes used for creating an object from types.CodeType in
correct order.
I got import to work by pickling pairs of names - the variable name
that references the module, and the name of the module. When it
unpickles the list, it reimports them and points the appropriate
variable at them. This had unwanted effects if you did an "import
this". It also doesn't work for objects that contain references to
modules.

My general method of storing is to store everything possible. See a
function? Store the function object itself. See a class? Store the
class object. Unfortunately, I can't store builtin methods or
functions, so this breaks on most modules. Don't try to reference the
__builtins__, by the way, otherwise it won't be removed and modjelly
will break.

I tried for a bit to restrict things, then gave up and did it
externally. There's no access to any files but those required to run
the script that deals with thing, and some other python modules that I
decided would be nice to have. Normally, nothing in the tree is
writable, either. Once I'm happy with it, I'll save a copy of the tree
somewhere and set up a cron job to "refresh" it at regular intervals.

I don't have enough control on the server to effectively restrict it
externally (no running as an unprivelleged user!), so I have to lock it
down as tightly as possible internally.
 
M

Mike Meyer

Devan L said:
My general method of storing is to store everything possible. See a
function? Store the function object itself. See a class? Store the
class object. Unfortunately, I can't store builtin methods or
functions, so this breaks on most modules. Don't try to reference the
__builtins__, by the way, otherwise it won't be removed and modjelly
will break.

I think the idea I used for modules would generalize: If you can't
store it, store the information you need to relocate it, and recreate
the binding.
I don't have enough control on the server to effectively restrict it
externally (no running as an unprivelleged user!), so I have to lock it
down as tightly as possible internally.

My ISP provides this facility. They provided a less strict version,
and worked with me to create this facility. While they aren't perfect,
I can't say enough good things about them. If you need internet
connectivity, web hosting, whatever - idiom.com is good people to work
with.

<mike
 
X

Xavier Morel

Mike said:
After spending time I should have been sleeping working on it, the try
python site is much more functional. It now allows statements,
including multi-line statements and expressions. You can't create code
objects yet, so it's still more a programmable calculator than
anything real.

I've got some of the tutorial text (literally) up as well. I hope to
make it easier to read the tutorial and interact with python at the
same time in the near future.

The url is http://www.mired.org/home/mwm/try_python/. Reports of
problems would appreciated.

If you want to try an online P{ython tool that lets you save code, try
Devan L's at http://www.datamech.com/devan/trypython/trypython.py.

<mike

Mike, may I ask whether that box has been secured? And if yes how?

Since Python doesn't have any way to secure the interface built-in, i'd
be interrested in that.
 
M

Mike Meyer

Very nice :)

I found this online Ruby tutorial:
http://tryruby.hobix.com/

That's what inspired me to create my version.
I think it would be cool to have something similar for Python. Want to
go further and make a nice tutorial to accompany this :)

Well, *I* like the python.org tutorial. I've already started steal,
uh, using, material from it. I intend to include more as time goes
by.

One thing that annoyed me about the tryruby version is that it changed
the text - apparently arbitrarily - with each expression. I *detest*
UI's that change things when they want to (I regularly close dialogs
accidently on OSX because they come up while I'm working in *some
other application* and steal the focus from me). I'm not going to do
that; that's why I list all the sections, and you can display (or not)
by clicking on them. I'm planning on adding a "suggested reading" link
(it's already there if you know where to look, but always does the
same thing :) under the console that will do what the ruby thing
does, except when the user asks for it, not when I think it should
happen.

<mike
 
B

browerg

I like the form, no matter what its limitations may be. Three notes:

It might be a good way to catch newbi mistakes (those are the kind I
make :p, thereby providing a feedback loop to improved error messages.

I had no trouble with from math import * followed by print pi, but
there was no >>> prompt after the result appeared .. is that part of
the 'closures' thing mentioned earlier?

Then I followed you "type 'help'" suggestion, which had me in stitches
(sorry, it's been a long day and the Knob Creek was kicking in) -- I
got exactly the message you'd expect, about help not being recognized
and maybe help() would work. That's what triggered the idea for
trapping errors.

Nice work!

George
 
M

Mike Meyer

I like the form, no matter what its limitations may be. Three notes:

It might be a good way to catch newbi mistakes (those are the kind I
make :p, thereby providing a feedback loop to improved error messages.

I'm doing almost no error catching. I think I catch two:

If you muck with the prompt, it throws away what you sent it, because
I'd have to guess at the expression.

There were (I think I worked around them) browser bugs that caused
the result of an expression to get lost - it notices that, and tells
you about it.

Well, I do catch exceptions in general, to tailor the traceback for
the environment. But that's all I do.
I had no trouble with from math import * followed by print pi, but
there was no >>> prompt after the result appeared .. is that part of
the 'closures' thing mentioned earlier?

Hmm. Are you looking at mine <URL:
http://www.mired.org/home/mwm/try_python/ >, or Devans <URL:
http://www.datamech.com/devan/trypython/trypython.py >? Mine doesn't
handle code (though he's provide pointers I plan on using to make it
do so). I think he said his has problems with closures.
Then I followed you "type 'help'" suggestion, which had me in stitches
(sorry, it's been a long day and the Knob Creek was kicking in) -- I
got exactly the message you'd expect, about help not being recognized
and maybe help() would work. That's what triggered the idea for
trapping errors.

Hmm. help seems to work fine in both of them. license() fails the same
way in both of them (it tries to read from stdin, so....), which means
that you can probalby make help fail on them both if you work at it.

thanks,
<mike
 
D

Devan L

I like the form, no matter what its limitations may be. Three notes:

It might be a good way to catch newbi mistakes (those are the kind I
make :p, thereby providing a feedback loop to improved error messages.

I had no trouble with from math import * followed by print pi, but
there was no >>> prompt after the result appeared .. is that part of
the 'closures' thing mentioned earlier?

Then I followed you "type 'help'" suggestion, which had me in stitches
(sorry, it's been a long day and the Knob Creek was kicking in) -- I
got exactly the message you'd expect, about help not being recognized
and maybe help() would work. That's what triggered the idea for
trapping errors.

Nice work!

George

Uh, I'm messing with import right now, but essentially, I wouldn't
recommend importing (one line __import__ hacks only!) or printing.
 
D

Devan L

Mike said:
(e-mail address removed) writes:
[comments about Mike Meyer's try python, I think]
Hmm. Are you looking at mine <URL:
http://www.mired.org/home/mwm/try_python/ >, or Devans <URL:
http://www.datamech.com/devan/trypython/trypython.py >? Mine doesn't
handle code (though he's provide pointers I plan on using to make it
do so). I think he said his has problems with closures.

I'm renaming mine to the Python Online REPL or Online Python REPL,
whichever you prefer, to help differentiate from Mike's.
From the actual recipe:
<http://www.onlamp.com/python/pythoncook2/solution.csp?day=2>
(The url changes every day as they move it one day back)
if co.co_freevars or co.co_cellvars:
raise ValueError, "Sorry, cannot pickle code objects from
closures"

I think that the code constructor (types.CodeType) doesn't take
co_freevars or co_cellvars as an arg, so I can't directly create a new
code object from the attribute of the old one with co_freevars and
co_cellvars. I might be able to set the attributes after,but I'll have
to test it out to see.
Hmm. help seems to work fine in both of them. license() fails the same
way in both of them (it tries to read from stdin, so....), which means
that you can probalby make help fail on them both if you work at it.

Printing and most things not explicitly called by my code isn't done
correctly (strings to lines to strings again!), so most any printing
non-single statements or input will probably break it.
 
J

jason.lai

I think that the code constructor (types.CodeType) doesn't take
co_freevars or co_cellvars as an arg, so I can't directly create a new
code object from the attribute of the old one with co_freevars and
co_cellvars.

Yay for hidden documentation:

"code(argcount, nlocals, stacksize, flags, codestring, constants,
names, varnames, filename, name, firstlineno, lnotab[, freevars[,
cellvars]])

Create a code object. Not for the faint of heart."
 
B

Bas

To expand on this idea:

You could somehow combine the official tuturial (or any other good
introductory text) and make all the examples in the text 'live'. Maybe
use a split screen with the tutorial text on one side and the trypython
console on the other. The newbie could then immediately try the example
by typing it over himself or by clicking a button 'run in console' next
to the example. Target audience should be only the real beginners who
are afraid/too lazy to install the complete Python enviroment. Advanced
users should be able to do a full install themselves.

Cheers,
Bas
 
M

Mike Meyer

Bas said:
You could somehow combine the official tuturial (or any other good
introductory text) and make all the examples in the text 'live'. Maybe
use a split screen with the tutorial text on one side and the trypython
console on the other. The newbie could then immediately try the example
by typing it over himself or by clicking a button 'run in console' next
to the example. Target audience should be only the real beginners who
are afraid/too lazy to install the complete Python enviroment. Advanced
users should be able to do a full install themselves.

This is pretty much what I had in mind. I'm moving the tutorial into
the thing (slowly). I've set it up as two regions one above the
other. The text of the tutorial will scroll in that region if it needs
to. The console region may be scrollable as well, depending on the
fonts and sizes that get used for the console window. I go through the
text of the tutorial typing in the expressions and verifying that I
get the correct results back.

Making the examples links that insesrt the text of the example?
Certainly possible. I'm not sure I want to do that, though. I think
people learn better if they actually do things themselves, and I'm not
sure that clicking a link qualifieas as "doing it themselves."

Thanks,
<mike
 
S

Szabolcs Nagy

Hello
Thanks for trypython, it's a cool idea

I got TryPythonError after an IdentationError and i could not get rid
of it (other than refreshing the page):

Python 2.4.2 (#3, Dec 16 2005, 23:54:20)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits", or "license" for more information..... qwerty
 
M

Mike Meyer

Szabolcs Nagy said:
Hello
Thanks for trypython, it's a cool idea

Thank you.
I got TryPythonError after an IdentationError and i could not get rid
of it (other than refreshing the page):

Python 2.4.2 (#3, Dec 16 2005, 23:54:20)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits", or "license" for more information.... qwerty

Thanks for the report. It's fixed, and all I had to do was totally
restructure the routine that did all the work. But I like the new
structure better.

<mike
 
S

Steven Bethard

Mike said:
The url is http://www.mired.org/home/mwm/try_python/. Reports of
problems would appreciated.

You're probably already aware of this, but the online help utility
doesn't work. It exits before you can type anything into it:

----------------------------------------------------------------------
Welcome to Python 2.4! This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help>
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
 
M

Mike Meyer

Steven Bethard said:
You're probably already aware of this, but the online help utility
doesn't work. It exits before you can type anything into it:

Actually, I'd say the interactive help utility doesn't work. As long
as you don't use it interactively, it works fine. You can do
help(int) (for instance) and so on.

And yes, I know about this. It's listed in "Known Problems". Anything
that tries to read from standard input will fail. I'm thinking about
fixes, but it's not a high-priority item at the moment.

Thanks for the report.
<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,625
Members
45,322
Latest member
ClaritaMcI

Latest Threads

Top