Re: [Tutor] Hy, I'm a n00b to Python, have some questions

2005-07-18 Thread André Roberge
Alex Nedelcu wrote:
[snip]
 
 Also, why is www.python.org http://www.python.org so ugly :) ? If I'd 
 like to point others to learn Python I would need a site that markets 
 Python through eye-candy case studies, not some boring old site :). Just 
 joking. I don't want to give examples of others. I am sure you guys know 
 what I mean.
 

Well, joke or not, a new draft web site was shown at the recent 
Europython conference.  I looked for it ... but my google skills didn't 
help me.  (Tim Parkin at http://www.pollenation.net/ is the one that 
showed it.)

Be prepared to see something nice :-)

André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Performance difference, ``in'' vs ``has_key()''

2005-07-17 Thread André Roberge
Max Noel wrote:
 
[snip]
 
 
 While we're on that topic, is there a particular reason why  'in', 
 in a dict context, searches the keys instead of doing the  logical thing 
 and searching the values?
animals = { 'cat': a cuddly little mammal who likes to eat birds,
'dog': man's best friend, also a mammal and which also can eat birds,
'parrot': a bird, favoured by Monty Python}

What is more natural?

if parrot in animals: 

or

if a bird, favoured by Monty Python in animals: ...

André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] imbedding python into another program?

2005-06-01 Thread André Roberge
Jeff Peery wrote:
 hello, is it possible to add something like the python IDLE into
 another program, say if I wanted to simply run scripts from within a
 wxPython program? Could someone point me to the correct reference?
 thanks.
 
Hi Jeff,

you may want to have a look at PyCrust, PyShell and the like.
I do something like this in my rur-ple app (on sourceforge).

The relevant lines of code are:

import wx.py as py

[inside a wx.Notebook]
win = py.shell.Shell(self.window, -1,
  introText = tr.INTERPRETER_INTRO_TEXT)
self.window.AddPage(win, tr.PYTHON_INTERPRETER)


HTH,

André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ANN: Version 0.9 of RUR-PLE

2005-05-31 Thread André Roberge
Version 0.9 of RUR: a Python Learning Environment has been released.
Information about RUR-PLE can be obtained at
http://rur-ple.sourceforge.net

Note that the project website is slightly out of date.

Among the changes in this new version:

***Spanish translation added.*

Changed image for language selection to reflect addition.

Changed directory structure of lessons.

Fixed non-existent file problem when changing language
with unstranslated lesson file open in browser; the
browser will open the default file in the chosen language
instead.

Changed dialogs (beepers to robot and resize world)
to use GridBagSizer for layout as opposed to specific
coordinates.

Added parameter  wx.BUFFER_VIRTUAL_AREA in
dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
in world_display.py; this is required to get proper scrolling
since wxPython 2.5.4.1.

Added SetFocus() when positioning sizer on Robot: code and learn
page.  This gets rid of the unwanted grey background.

Changed list of beepers that can be placed at an intersection from
0 ... 15, 16, 17, 18, 19, 20  to
0 ... 15, 20, 40, 60, 80, 99.

Removed the from __future__ import division command to the interpreter.
Since this is not likely to be the default version for a *long* time, it 
seems
a better idea to revert to the default behaviour for the interpreter.
TODO: The lesson needs to be updated to reflect this change.

World redrawn immediately after selecting a new language, so that
the words streets and avenues are updated right away.

Corrected tooltip language setting on speed selection slider.

Added possibility to change background colour of robot world
through user program.  This is to be used in the random maze escape lesson.

Changed the 20 robot images so that their background
is transparent.

Removed obsolete self-testing code in various files as well as
redundant import statements.

Fixed problem with seemingly random
invalid world file error.  This occured when
a robot was removed from the world, and an
attempt was made at resetting the world.

Added SetFocus() to WorldGui.OnLeftDown().  Somehow,
the WorldGUI (i.e. robot world) would no longer get focus
as a matter of course when left-clicked.  This meant that it
was no longer possible to position the robot using the cursor keys.
This problem has appeared since I made the switch to
wxPython 2.6.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ANN: new release of RUR-PLE

2005-05-18 Thread André Roberge
Version 0.8.6a is now available.

This version is mostly a bug fix version.
* unicode problem corrected (bug introduced in version 0.8.5)
* linenumber information on syntax errors corrected
* removed the URL browser capability
* corrected typo and change explanation of next_to_a_beeper() in lessons
* corrected name of robot in one lesson

Addition:
tower of Hanoi solution(.rur file) (with two typical .wld files)
8 queen puzzle solution (.rur file)

Additional changes expected in version 0.8.6b

André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [ANN] new version of rur-ple (0.8.5)

2005-05-10 Thread André Roberge
ZVision wrote:
 Hi Roberge,
 I wanted to give your program a try.
 Absoluted beginner. But there dont seem to be enough instructions
 about how to do this. Maybe I am missing something.

No, you are quite right.  At this stage of development, I still assume 
that someone with more experience than a total beginner is around to get 
the program started.  My mistake; I'll have to correct that and give 
detailed instructions.

 I have py2.4 installed. I installed the wxPython, then I tried to run
 start.py from your program.
 Didnt work.
 So I opened python and tried run/run module
 this is what I get
 IDLE 1.1  
 
 RESTART 

 
 Requested version of wxPython not found
 Can not import wxversion in rur_start.py 
 Will attempt to import existing version of wxPython.
 
 Traceback (most recent call last):
   File C:\Documents and
 Settings\Flo\Desktop\rurple0.8.5\RUR_start.py, line 53, in -toplevel-
 import wx
 ImportError: No module named wx
 

You probably have a newer version of wxPython than I have myself.  I 
need to install the newest one myself and do some tests with it.
I apologize for this.

 

 
 SO I check and wxpyton is installed at C:\Python24\Lib\site-packages
 by the way I installed wxpython ansi for 2.4

I will need to check.
 
 Obviously, I dont know what I am doing, but so will most beginners. So
 maybe some detailed instructions on how to run the program will
 help sorry if I missed it.

No need to apologize; the problem is mine.  Thanks for trying!
André
 thanks
 Zoogie
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [ANN] new version of rur-ple (0.8.5)

2005-05-10 Thread André Roberge
Bob Gailer wrote:
 At 12:41 PM 5/10/2005, Andre Roberge wrote:
 
 On 5/10/05, Bob Gailer [EMAIL PROTECTED] wrote:
   At 08:48 PM 5/9/2005, André Roberge wrote:

 [snip]


   On http://rur-ple.sourceforge.net/en/errors.htm Reeborg
  appears as Egrebor. I assume that's incorrect.
  
 
 You are indeed correct.   Thank you for pointing this out.

 Just for a historical note:  rur-ple is inspired by GvR which stands
 for Guido van Robot.  I can not think of a better name for it (kudos
 to Steve Howell).
 
 
 Any allusion to - RUR Rossums Universal Robots by Karel Capek 1920
 

Actually, yes.  I just forgot to mention it.  In the play by Capek,
Rossum is a mad scientist, unlike Guido (right?).

[Aside:  I can swear I saw (but can't find it after googling for 30 
minutes) that the original play in Czech was known by its acronym RUR 
where the U did not stand for universal. However, the English 
translation, which everyone seems to remember, retained the RUR acronym.]

So, the  RUR was also inspired from the original play by Capek.  And I 
made sure I could use the same acronym in both English and French in 
RUR-PLE  (English; in French it would be RUR: EAP  :-)
(le Robot Usagé de Roberge)
(   Roberge's Used Robot )



 [snip]
 
 Bob Gailer
 mailto:[EMAIL PROTECTED]
 510 558 3275 home
 720 938 2625 cell
 
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [ANN] new version of rur-ple (0.8.5)

2005-05-09 Thread André Roberge
Version 0.8.5 of rur-ple has been released.
The web site has completely changed; it includes over 35 pages.
http://rur-ple.sourceforge.net/

--
Learning to program computer should be fun, for adults and children 
alike. RUR-PLE is an environment designed to help you learn computer 
programming using the language Python. To use RUR-PLE, you need 
wxPython. You can learn more about RUR-PLE or you can go to the download 
page.

===
Apprendre à programmer devrait être amusant,
que l'on soit un adulte ou un enfant.

RUR-PLE est un environnement conçu pour vous aider à apprendre la 
programmation informatique avec le langage Python. Pour utiliser 
RUR-PLE, vous aurez besoin de wxPython. Vous pouvez en apprendre 
davantage au sujet de RUR-PLE ou vous pouvez aller à la page de 
téléchargement.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ANN: version 0.8 of RUR-PLE

2005-05-06 Thread André Roberge
For those interested in a different approach for learning to program 
using Python, I would be interested in your thoughts about RUR-PLE.

The latest version (0.8) is available on sourceforge:
https://sourceforge.net/project/showfiles.php?group_id=125834

Note that the home page for the project is hopelessly out of date. 
RUR-PLE has evolved greatly since.
I really should do something about it... :-(

RUR-PLE requires wxPython.  The download is fairly large, due to the 
many graphical elements included in the lessons.

Even if you can't afford to spend much time with it, I would *really* 
welcome the feedback of at least some of the many experienced tutors on 
this list.  Even if you just had a look at it for 5 minutes (after
the download!)
I have much to thank you for already, as I feel I have learnt *lots* 
from reading messages on this list
==
(one of my first post here:
http://mail.python.org/pipermail/tutor/2004-September/031884.html
...
After many years of doing other stuff, I'm starting to program again,
just for the fun of it (and to teach my kids),
learning Python along the way.
...
==
Thanks in advance to any or all that show some interest and give me some 
feedback.

André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary Inserts...

2005-05-05 Thread André Roberge
Allen John Schmidt, Jr. wrote:
 Ok, I have had enough. I have looked all through the python docs and I 
 cannot find it. How do you insert an entry into a dictionary?
 
 Thanx!
 

  my_dict = {}
  my_dict['new_entry'] = ['simple', 'as', 1, 2, 3]
  my_dict
{'new_entry': ['simple', 'as', 1, 2, 3]}

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Better way to do some parsing?

2005-05-01 Thread André Roberge
[Apologies for the long post.]

Hi all,

I have created a severely restricted environment within with
users can learn the basics of programming in Python.

Within that environment, I want to have the user test the five
valid forms that an import statement can have, by attempting to
import a fake module whose name is useful.  Other import
statements are disallowed.

1. import useful
2. from useful import *
3. from useful import valid_function1 [, valid_function2, ...]
4. from useful import valid_function as better_named_function
5. import useful as not_so_useful_after_all

As far as I can tell, the following works, but it looks rather
clunky to me.  My *very limited* experience with the
re module may have something to do with this.

Any suggestion would be most welcome.

André

===Here's the code formatted (fingers crossed) to work if cut and 
pasted from email =


# test_import.py

import re

isolate_words = re.compile(r'\W+')  # used with .split()

# pre-compiled some regular expression with allowable use of import

imp_use = re.compile('^import useful', re.MULTILINE)
imp_use_as = re.compile('^import useful as (\w+)', re.MULTILINE)
from_use_imp_star = re.compile('^from useful import \*', re.MULTILINE)
from_use_imp_names = re.compile(
^from useful import (\w+(,[ ]*\w+)*),
 re.MULTILINE)
from_use_imp_as = re.compile(
   ^from useful import (\w+) as (\w+),
   re.MULTILINE)


# In the following, r is used so that \b identifies a word boundary,
# and is not interpreted as backslash by Python.

import_misuse = re.compile(r'\bimport\b', re.MULTILINE)

# use to commenting out the valid import statements after processed.

comment_from = re.compile('^from ', re.MULTILINE)
comment_import = re.compile('^import ', re.MULTILINE)

# Create a fake module which can be imported

right = turn_right():\n+\
 turn_left()\n+\
 turn_left()\n+\
 turn_left()\n\n

around = turn_around():\n+\
 turn_left()\n+\
 turn_left()\n\n

up_east = climb_up_east():\n+\
 turn_left()\n+\
 move()\n+\
 turn_left()\n+\
 turn_left()\n+\
 turn_left()\n\n

up_west = climb_up_west():\n+\
 turn_left()\n+\
 turn_left()\n+\
 turn_left()\n+\
 move()\n+\
 turn_left()\n\n

down_west =  climb_down_west():\n+\
 turn_left()\n+\
 move()\n+\
 turn_left()\n+\
 turn_left()\n+\
 turn_left()\n\n

down_east =  climb_down_east():\n+\
 turn_left()\n+\
 turn_left()\n+\
 turn_left()\n+\
 move()\n+\
 turn_left()\n\n

commands = {'turn_right': right, 'turn_around': around,
 'climb_up_east': up_east, 'climb_up_west': up_west,
 'climb_down_east': down_east, 'climb_down_west': down_west}

#=== end of info on fake module

# The following fonctions are helper functions to
# process the import statement:
# they add the appropriate imported commands
# before the import statement,
# before commenting out (by pre-pending #) the import statement line

def import_useful():
 added_text = ''
 for instruction in commands:
 new = def  + 'useful.' + commands[instruction]
 added_text += new
 return added_text, True

def from_useful_import_star():
 added_text = ''
 for instruction in commands:
 new = def  + commands[instruction]
 added_text += new
 return added_text, True

def import_useful_as(syn):
 added_text = ''
 for instruction in commands:
 new = def  + syn + '.' + commands[instruction]
 added_text += new
 return added_text, True

def from_useful_import_names(names):
 added_text = ''
 for instruction in isolate_words.split(names):
 try:
 new = def  + commands[instruction]
 except:
 print instruction,  not found in module useful
 added_text += new
 return added_text, True

def from_useful_import_as(name, syn):
 added_text = ''
 try:
 new = def  + commands[name].replace(name, syn)
 except:
 print name,  not found in module useful
 added_text += new
 return added_text, True

def process_no_import():
 added_text = ''
 return added_text, True

# the basic processing function

def process_file(file_text):
 if imp_use_as.search(file_text): # look for import useful as ...
 syn = imp_use_as.findall(file_text)
 added_text, safe_import_flag = import_useful_as(syn[0])
 file_text = comment_import.sub('#import ', file_text)
 elif imp_use.search(file_text):  # perhaps the as ... part is
  # missing
 added_text, safe_import_flag = import_useful()
 file_text = comment_import.sub('#import ', file_text)
   

[Tutor] Highlighting instructions: pedagogical preferences

2005-04-25 Thread André Roberge
I'm writing a program interpreter which has two windows: a program 
editing window and a program output window.

The interpreter can either step through the program automatically, at a 
slow pace, or step through the program one instruction at a time, as the 
user clicks on a step button.

The instructions being executed are highlighted one by one.
Question: should the highlighted instruction be the one that has just 
been executed, or the one that is about to be executed (when the user 
clicks on the step button, for example)?

At present, I have implemented the second method.  I'm wondering if 
that's the best choice.

Any ideas?
André
P.S.  Btw, this program is part of a python tutorial I am writing - 
hence the relevance to this list :-)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: primes

2005-03-17 Thread André Roberge
[EMAIL PROTECTED] wrote:
Quoting Gregor Lingl [EMAIL PROTECTED]:

[x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]

Heh.  That's quite neat.
I can only offer one suggestion --- if you replace range with xrange, you get a
small speed improvement.
eg: On my system, it took 415 seconds to generate a list of primes  50,000
using range, but only 386 seconds if I use the same code, but with xrange 
instead.
What about using something like range(2, math.sqrt(x)) instead?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using exec with dict

2005-01-30 Thread André Roberge
First things first: I am writing a program which has, among other 
things, an embedded Python interpreter.  So, before telling me that 
using exec is unsafe because one could enter ..., consider that the 
user could just as well enter ... in the interpreter.

(Having gotten this off my chest :-)
In Python in a Nutshell, Martelli writes, in at least two places, 
something like
you should use exec only with specific, explicit dictionaries.

I would like to figure out how to do this [yes, for safety reasons :-), 
and also because I am curious] and, so far, I have been unsuccesful.

I have a robot that can do some actions like move() and 
turn_left().  I can program this robot using python like this:

.def move_and_turn():
.move()
.turn_left()
.
.def draw_square():
.for i in range(4):
.move_and_turn()
.
.draw_square()

To execute such a program within my larger program, I use
exec code in globals()

where code is the little program above, and it works as expected.  The 
question I have is: how do I do this with an explicit dictionary.  I 
would *guess* that this is somehow equivalent to how do I create a 
dictionary that has access only to robot instructions [move(), 
turn_left(), etc.] and Python's basic syntax ... but I don't know how 
to do this.

Any help would be appreciated.
André
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using exec with dict

2005-01-30 Thread André Roberge
Thank you Kent. That worked.

André Roberge wrote:
/ I have a robot that can do some actions like move() and 
// turn_left().  I can program this robot using python like this:
// 
// .def move_and_turn():
[snip]//
// The question I have is: how do I do this with an explicit dictionary.
// I would *guess* that this is somehow equivalent to how do I create a 
// dictionary that has access only to robot instructions [move(), 
// turn_left(), etc.] and Python's basic syntax ... but I don't know how 
// to do this.
/
myGlobals = { 'move':move, 'turn_left':turn_left }
exec code in myGlobals

You don't need to add built-ins to myGlobals. Add whatever of your symbols you want the code to have 
access to.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: [ANN] RUR: a Python Learning Environment (alpha)

2004-12-13 Thread André Roberge
This looks like a very nice effort -- I am trying to get it running,
since I am working with some other newbies to learn more Python. 

I wish there were a link from http://rur-ple.sourceforge.net/index.html
to the download page! 
I will fix that; thanks.
And I am not sure which of the downloaded files to
run. I thought maybe WorldDisplay.py, or RURmain.py? 
Oops! 
RURmain.py

Anyway, I really like the concept, and the screenshots look intriguing.
You have a nice writing style in English, by the way -- I think kids
will pick right up on the fix the robot metaphor.
Thanks!
Andre
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: [ANN] RUR: a Python Learning Environment (alpha)

2004-12-13 Thread André Roberge
This is weird (to me, anyways) as it works well on my computer.
However, I remember that I had to create loadImages() to
initialize the handlers early on, otherwise it was complaining
that it couldn't ConvertToBitmap.
I'll have to see if I can move this statement elsewhere; I will reply
privately when I do it (so as not to clutter the list) and
will report to the list when the problem is solved.
Just to clarify: are you using wxpython 2.4.x under Windows?
Andre
==
Can't get it running -- it keeps saying:
Traceback (most recent call last):
 File C:/source/RUR/RURmain.py, line 28, in ?
   messenger.loadImages()# load them up here after initialising
Handlers
 File C:\source\RUR\messenger.py, line 27, in loadImages
   HIT_WALL_IMAGE = wxImage('ouch2.png').ConvertToBitmap()
 File C:\Python23\Lib\site-packages\wx\_core.py, line 2282, in
ConvertToBitmap
   return _core_.Image_ConvertToBitmap(*args, **kwargs)
wx._core.PyNoAppError: The wx.App object must be created first!
Ron
-- next part ---
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [ANN] RUR: a Python Learning Environment (alpha)

2004-12-12 Thread André Roberge
RUR: a Python Learning Environment is a successor of Karel the Robot,
PyRobot and Guido van Robot. Its purpose is to provide an environment
for beginners, including children, to learn python.
(Note that Guido van Robot still exists and has been upgraded recently.)
Source for the program (python files; requires wxPython 2.4)
can be found on SourceForge.net at
https://sourceforge.net/projects/rur-ple/
The current (first) release has been tested under
Windows and everything (except the radio box) should work.
For those using a platform other than Windows,
I have been told that a much earlier version had problems
displaying the robot world properly. If you're interested in trying and
encounter problems, I suggest changing the window size,
or clicking in the middle panel (the robot's world).
Do not hesitate to give me some feedback.
To my knowledge, no one (other than myself!) has tested it yet.
The project's home page is located at:
http://rur-ple.sourceforge.net/index.html
It features a number of lessons, with an outline for future lessons. 
It should give you an idea of what this program is about, without having 
to try it.

Note: This is my very first Python program
(other than some very simple ones) and the first program
I share with anyone.  Comments, suggestions, criticisms are most welcome.
André Roberge
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor