- I added an "output pane" in the robot world window. Users can now put "print" statements in their programs, and the result will appear in the output pane. This should be useful in "tracing" the program flow.
- I added two new instructions that can be used in robot programs: input_int("optional text") and input_string("optional text: e.g. Enter your name.") This is an undocumented feature for now.
- I fixed an obscure "bug" discovered by Andy. When the "World file" is visible, the display was not updated when giving some beepers to the robot. This did not affect in any way the program execution; furthermore, most of the time, the world file viewer was probably hidden. Still, it should now be fixed.
- Finally, I had removed the requirement to save a program before running it. However, I had made it such that a dialog would pop up if a user was trying to quit without saving a program. Apparently, it would sometimes cause the program to hang. I could not reproduce the bug ...
Monday, May 15, 2006
New version of RUR-PLE (0.9.8)
After receiving some suggestions from Andy Judkis, a high school teacher who uses Rur-ple in his classes, I made the following changes to rur-ple.
Optional typechecking: fun with "with"
A while ago, prompted by various entries [1, 2, 3, 4] on Guido's blog about Adding Optional Static Typing to Python, I mused about different ways of doing this [5, 6, 7], keeping the syntax as Pythonic as possible, but at the cost of introducing a new keyword ("where"). Today's entry is written in the same spirit (i.e. just for fun), but with a different syntax, and makes use of the new "with" keyword. By itself, this blog entry is probably too brief to make much sense.
Let me start by introducing some static typing information that could be extracted from an IDE, or used by pychecker or pylint.
Now, if we wanted to use the typechecking information in some module where gcd() is actually used, we would have to instruct the interpreter to do so ... here's a way we might want to write this:
Granted, this is not currently valid in Python ... but its intent should be understandable!
Let me start by introducing some static typing information that could be extracted from an IDE, or used by pychecker or pylint.
The above is totally valid Python. Just like doctests can be extracted by the doctest module, the "typecheck" assertions could be extracted and used by other programs. However, as they stand, they are "totally optional".
01 def gcd(a, b):
02 '''Returns the Greatest Common Divisor,
03 implementing Euclid's algorithm.
04 with __typecheck__:
05 assert isinstance(a, int), 'First argument must be an integer.'
06 assert isinstance(b, int), 'Second argument must be an integer.'
07 #Some doctests for good measure
08 >>> print gcd(6, 3)
09 3
07 '''
08 while a:
09 a, b = b%a, a
10 return b
Now, if we wanted to use the typechecking information in some module where gcd() is actually used, we would have to instruct the interpreter to do so ... here's a way we might want to write this:
1 with __typecheck__:
2 gcd()
3 some_other_useful_function()
4 # the rest of the code follows...
Granted, this is not currently valid in Python ... but its intent should be understandable!
Wednesday, May 10, 2006
Crunchy Frog 0.3
Version 0.3 of "Crunchy Frog" has been released. It can be found at
https://sourceforge.net/project/showfiles.php?group_id=125834
Crunchy Frog transforms a "traditional" Python tutorial into an interactive session within your favourite web browser. Four modes of interaction are currently possible:
1. One-liner, similar to the typical instruction at the Python interpreter.
2. Embedded Python shell, within an html page.
3. Multi-line Python code, as entered in a traditional editor, and executed by Python.
4. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.
Even though it is an early release, Crunchy Frog could probably already be useful in a classroom situation. To use it, you will also need to have installed Elementtree and CherryPy.
Suggestion: read the 6 page long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in approximately 15 minutes ... if you don't spend too much time playing with the interpreter. :-)
https://sourceforge.net
Crunchy Frog transforms a "traditional" Python tutorial into an interactive session within your favourite web browser. Four modes of interaction are currently possible:
1. One-liner, similar to the typical instruction at the Python interpreter.
2. Embedded Python shell, within an html page.
3. Multi-line Python code, as entered in a traditional editor, and executed by Python.
4. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.
Even though it is an early release, Crunchy Frog could probably already be useful in a classroom situation. To use it, you will also need to have installed Elementtree and CherryPy.
Suggestion: read the 6 page long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in approximately 15 minutes ... if you don't spend too much time playing with the interpreter. :-)
Thursday, May 04, 2006
My first CherryPy app.
Using CherryPy, I've just created version 0.1 of "Crunchy Frog". It can be found at
https://sourceforge.net/project/showfiles.php?group_id=125834
Crunchy Frog is just a temporary name for this app. (Read the tutorial for more details.) What it does is to transform a "traditional" Python tutorial into an interactive session within your favourite web browser. Three modes of interaction are currently possible:
1. one-liner, similar to the typical instruction at the Python interpreter.
2. multi-line Python code, as entered in a traditional editor, and executed by Python.
3. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.
Crunchy Frog is more of a proof-of-concept than a serious application at this point. The code is rather messy, showing my total lack of experience with this type of program (web app). I will very likely rewrite it from scratch for the next release. To use it you will also need to have installed Elementtree (included with Python 2.5?) and CherryPy.
To try it: read the 5 (short) pages long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in less than 10 minutes.
https://sourceforge.net
Crunchy Frog is just a temporary name for this app. (Read the tutorial for more details.) What it does is to transform a "traditional" Python tutorial into an interactive session within your favourite web browser. Three modes of interaction are currently possible:
1. one-liner, similar to the typical instruction at the Python interpreter.
2. multi-line Python code, as entered in a traditional editor, and executed by Python.
3. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.
Crunchy Frog is more of a proof-of-concept than a serious application at this point. The code is rather messy, showing my total lack of experience with this type of program (web app). I will very likely rewrite it from scratch for the next release. To use it you will also need to have installed Elementtree (included with Python 2.5?) and CherryPy.
To try it: read the 5 (short) pages long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in less than 10 minutes.
Saturday, April 29, 2006
Rur-ple 0.9.7a: bug fix
Once again, rur-ple was broken on Linux (and Mac OS); however, this time the bug was reported (only the second ever reported bug through sourceforge since Stas Z guided me to make it work on Linux for the first time!). It is now fixed :-)
There must be some other bugs, somewhere... After all, I did not use any kind of "unit tests" for most of the code. Anyone that tries to use rur-ple and find problems should feel free to report them!
As soon as I can get about a week's worth of time (and inspiration!) to write the last lessons, I will be able to finally release version 1.0. After that, watch for a new version that will use a web browser (instead of wxPython) as its graphical environment. Now, what I need is a new name for that future version...
There must be some other bugs, somewhere... After all, I did not use any kind of "unit tests" for most of the code. Anyone that tries to use rur-ple and find problems should feel free to report them!
As soon as I can get about a week's worth of time (and inspiration!) to write the last lessons, I will be able to finally release version 1.0. After that, watch for a new version that will use a web browser (instead of wxPython) as its graphical environment. Now, what I need is a new name for that future version...
CherryPy is great!
Inspired by Ian Bicking's HTConsole, I wanted to see if I could get a simple "Python compiler", similar to Lightning Compiler but using a browser window instead of basing it on wxPython. Having no experience with any web programming, and looking at Ian's code, I thought it would take me forever to get this going. Also, I didn't really want to have to learn about all the packages used by Ian to produce HTConsole.
After a few simple attempts with Python's webbrowser module, a fruitless query on comp.lang.python, and some wandering on the web, I came accross CherryPy. To be honest, I had heard of CherryPy before, but had never looked at it as I thought it was something I would never need.
Lo and behold, simply after reading the basic tutorials included with CherryPy, I was able to write a very small program which does pretty much the same thing that earlier versions of Lightning Compiler could do. The complete code is included below:
Type in your Python code.
The result of
Thank you CherryPy developpers!
After a few simple attempts with Python's webbrowser module, a fruitless query on comp.lang.python, and some wandering on the web, I came accross CherryPy. To be honest, I had heard of CherryPy before, but had never looked at it as I thought it was something I would never need.
Lo and behold, simply after reading the basic tutorials included with CherryPy, I was able to write a very small program which does pretty much the same thing that earlier versions of Lightning Compiler could do. The complete code is included below:
And here's what it looks like (html code simply pasted below; it doesn't work here!)
import cherrypy
import os
from tempfile import gettempdir
TMP_DIR = gettempdir()
class PythonRunner(object):
title = 'Play with Python'
def header(self):
return '''
<html>
<head>
<title>%s</title>
</head>
<body>
<h2>%s</h2>
''' % (self.title, self.title)
def footer(self):
return '''
</body>
</html>
'''
def index(self, code=None):
cherrypy.session['code'] = code
output = ''
if code is None:
cherrypy.session['output'] = ''
else:
tmp_filename = os.path.join(TMP_DIR, 'my_file.dat')
f = open(tmp_filename, 'w')
f.write(code)
f.close()
f_in, f_out = os.popen4("python %s"%tmp_filename)
output = "The result of"
output += "<pre><font color='blue'>%s</font></pre>is: "%code
output += "<pre><font color='green'>"
for line in f_out.readlines():
output += line
output += "</font></pre>"
cherrypy.session['output'] = output
return self.header()+'''
Type in your Python code.
<form action="index" method="GET">
<textarea name="code" rows=5 cols=80></textarea><br/>
<input type="submit" value="Run Python"/>
</form>
<br/>
%s
''' % output + self.footer()
index.exposed = True
cherrypy.root = PythonRunner()
cherrypy.config.update({'session_filter.on': True})
if __name__ == '__main__':
cherrypy.config.update(file = 'tutorial.conf')
cherrypy.server.start()
Play with Python
Type in your Python code.
The result of
def hello():
print 'Hello from CherryPy!'
hello()
a = 3
print a*3is: Hello from CherryPy!
9
Thank you CherryPy developpers!
Thursday, April 27, 2006
Lightning 2.0
I've upgraded Lightning Compiler significantly. It is now possible to have more than one editing tab. It is now also possible to run doctest suites, with an external file. As usual, it can be found on sourceforge.
Lightning Compiler (LC) is a wxPython based app. LC's purpose is to provide a friendlier environment to tests Python code snippets than the Python interpreter. It does include an interpreter (pyShell) but it is most likely to be used for its editor. You can execute the code that appears in the editing window and the output is redirected to an output window. raw_input() and input() are handled via dialogs. The basic layout (output window to the side or below the editor window) is customisable.
LC comes in a zip file with a sample app, showing how it can be embedded in other applications, as well as a sample script with doctests and a text file containing additional doctest based tests.
Since LC uses wxPython, it can not be run with a basic Python installation. If there is some interest, I might try and adapt it so that it could use Tkinter instead (as an option. However, I have no experience with Tkinter. Any help would, of course, be appreciated :-)
Lightning Compiler (LC) is a wxPython based app. LC's purpose is to provide a friendlier environment to tests Python code snippets than the Python interpreter. It does include an interpreter (pyShell) but it is most likely to be used for its editor. You can execute the code that appears in the editing window and the output is redirected to an output window. raw_input() and input() are handled via dialogs. The basic layout (output window to the side or below the editor window) is customisable.
LC comes in a zip file with a sample app, showing how it can be embedded in other applications, as well as a sample script with doctests and a text file containing additional doctest based tests.
Since LC uses wxPython, it can not be run with a basic Python installation. If there is some interest, I might try and adapt it so that it could use Tkinter instead (as an option. However, I have no experience with Tkinter. Any help would, of course, be appreciated :-)
Subscribe to:
Posts (Atom)