Re: [Tutor] Bad time to get into Python?

2008-02-04 Thread Andre Roberge
On Feb 4, 2008 1:26 PM, Eric Brunson [EMAIL PROTECTED] wrote:

  Dotan Cohen wrote:

  Like I mentioned earlier, I'm more interested in my learning being 3.x
 compatible, not my scripts. If all I need to do is learn to print()
 instead of print then that's fine.


  Basically, if you follow a few simple rules you'll avoid 99% of 3.0
 incompatibilities:

  1) Always use:

 print( like it was a function )
  rather than:
  print like it was a statement
  2) Always use:

 class NewStyle( object ):
  rather than:
  class OldStyle():
  3) Never try to be clever with side effects of internal implementations of
 language


  Pretty much everything else you learn in 2.5 will be applicable in 3.0.

  (Others on the list, please feel free to extend my rules with things that
 you feel will be important)


No, this seems about right.  For the record, I have attempted an
experiment to see if I could make my program (Crunchy) run under 2.4,
2.5, 3.0a1 and 3.0a2 simulatenously. This is a program with about 40
different modules, using a number of other modules from the standard
library.   I managed to get everything working almost perfectly using
3.0a1 and about 95% under 3.0a2 - I am convinced that, with a bit more
effort, I could have gotten everything working under all 4 Python
versions.

I have complete unit tests for about 20 of the modules I wrote and it
was very easy to make them work (with no errors) under all 4 Python
versions.   There are only a small number of places where the
transition from 2.x to 3.0 is going to be tricky - and most of these
are related to dealings with strings and unicode characters, something
not everyone has to deal with.

So, based on actual experience, I am confident in telling anyone
interested that they should not fear learning Python 2.x (thinking it
might become obsolete) as 99% of your code (excluding print
statements) is probably going to work unchanged.

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


Re: [Tutor] Suppressing output in interactive mode

2008-01-11 Thread Andre Roberge
You may want to check here:
http://mail.python.org/pipermail/edu-sig/2007-August/008154.html

André

On Jan 11, 2008 7:26 AM, Olivier Lefevre [EMAIL PROTECTED] wrote:
 This is stupid but my python is rusty I can neither
 remember nor find out anew how to enter an expression
 that returns a value w/o being seeing the result printed.
 I would have expected something
 expr;
 as opposed to
 exp
 to do the trick but no dice and I haven't had any luck
 with Google or the docs. Can it be done? Note that I
 don't necessarily want to suppress all output, just
 just for certain expressions (e.g., within a loop,
 so as not to get flooded).

 Thx much,

 -- O.L.

 ___
 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] Suppressing output in interactive mode

2008-01-11 Thread Andre Roberge
On Jan 11, 2008 9:48 AM, Olivier Lefevre [EMAIL PROTECTED] wrote:
 Thanks for both suggestions. The displayhook trick would
 be OK if there was a way to retrieve what _would_ have
 been printed last if the display had not been changed:
 something like a modified '_'. As it stands, it's a bit
 radical.

If you follow the discussion thread look through the link I provided,
I believe this is addressed a bit later.

André


 -- O.L.

 ___
 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] Selecting a browser

2007-12-04 Thread Andre Roberge
Forwarded to the ghop-discussion list :-)

Thanks Kent for the suggestion.

André

On Dec 4, 2007 11:13 AM, Kent Johnson [EMAIL PROTECTED] wrote:

 Tim Golden wrote:
  In addition, for those not following that particular
  story, the Google Highly Open thingy (GHOP) is seeing
  a bunch of updates, additions and corrections to the
  docs being submitted pretty much every day. Which can
  only be a good thing!

 In fact updating the webbrowser docs would make a fine GHOP task.

 Kent
 ___
 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] Question regarding syntax

2007-07-11 Thread Andre Roberge
On 7/11/07, Eric Brunson [EMAIL PROTECTED] wrote:
 Michael Klier wrote:
  Dave Kuhlman wrote:
 
  On Wed, Jul 11, 2007 at 11:03:18AM -0400, John Morris wrote:
 
  I'm editing some code from Mailman and seeing:
 
  legend = _(%(hostname)s Mailing Lists)
 
 
 
  I am no python pro but I guess that funtction _() ist just a wrapper
  function around gettext.gettext from the gettext module (used for
  localization). I`ve seen that in lots of places and I think that`s
  common practise (don`t beat me if I am wrong ;-)).
 
 
  Mailman is a great product. But that bit of code is not, I think,
  very good code.
 
 
  Even the python gettext docs [1] use it that way.
 
  [1] http://docs.python.org/lib/node732.html
 
 

 I've seen it before, too.  From the example in the manual I imagine it's
 more convention than anything hard and fast, probably to make the string
 stand out more than the function call since it's essentially just doing
 a translation.


It is a standard convention.  Lots of tools are built on the
assumption that translatable strings are going to be enclosed in
_(...)
These tools extract the strings from programs, and put them in files
(.po) that are easily editable by human translators.

This convention is *not* limited to Python.

André


 However, by assigning gettext.getttext to the local variable '_', you do
 avoid a module lookup every time it's used.  It's useful when you do
 something like this (contrived example):

 import math

 f = math.cos
 for x in range(0, 10):
 print x, f(x)



 ___
 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] What's wrong with this?

2007-05-03 Thread Andre Roberge
Perhaps the following might be helpful:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f1b60f4739591d6b/4417f807848b4b5d?lnk=gstq=launchingrnum=4#4417f807848b4b5d

(if the link does not work, google for launching python program
cross-platform or go to
http://aspn.activestate.com/ASPN/Mail/Message/python-list/3467794)
André

On 5/3/07, Jason Coggins [EMAIL PROTECTED] wrote:


 I have the following function in a program:

 os.popen('filename.py')

 What I want to do is launch the program in the os.popen() function.  The
 file I am trying to launch is located in the same directory as the program
 the function is contained in.  I also use Linux if that makes a difference.

 Jason
 ___
 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] Questions of Maths

2007-04-18 Thread Andre Roberge
On 4/18/07, Abu Ismail [EMAIL PROTECTED] wrote:
 Hi,

 I am working on an implementation of an L-system in Python. I hate
 using turtle module since it uses Tk and as my IDE also uses Tk I have
 to close my editor before I can test the program. So I am implementing
 the graphics using PIL.

 Now to the problem.

 Say you have a line AB with co-ords (x1,y1) and (x2,y2). Say you also
 have a point C with co-ords (x3,y3).

 Question: how to determine whether point C is to the left or to the
 right of the line AB?

1. Write an equation for the line AB in the form x = Wy + Z  (as
opposed to y = mx + b, which is the usual form).
2. Substitute the value for y3 in that equation - it will give you the
value of x on that line (call it X3).
3. Compare x3 with X3.

A quick derivation gave me (please verify)
x = [(x2-x1) y + x1 y2 - x2 y1]/(y2-y1)
where the multiplication signs are implicit.

Good luck!

André

 Any suggestions would be welcome.

 Ta,
 AH
 ___
 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] problems to install python 2.5

2007-03-11 Thread Andre Roberge
On 3/11/07, Tsila Hassine [EMAIL PROTECTED] wrote:
 I also tried that build as well - it says that installation completed
 succesfully - and when i try to launch IDLE - it won't open...


Could it be that the 2.3 version is still around and that you are
trying to launch the 2.3 version of IDLE?  This happened to me once.

 On 3/11/07, Kent Johnson [EMAIL PROTECTED] wrote:
  Tsila Hassine wrote:
   Hello all
  
   I downloaded Python 2.5 (final release) from python.org. I am trying to
   install it on my Mac 0s 10.4
  
   the current working version i have of python is 2.3 (also built as a
   framework)
  
  
   It goes through the ./configure part ok, but the make install
 produces
   the following errors :
 
  No clue about your errors, but you can download a framework build of
  Python 2.5 from
  http://www.pythonmac.org/packages/py25-fat/index.html
 
  You might have better luck with build questions on the python-mac list:
 
 http://www.python.org/community/sigs/current/pythonmac-sig/
 
  Kent
 


 ___
 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] how to know if a file exists

2007-01-03 Thread Andre Roberge

On 1/4/07, Luke Paireepinart [EMAIL PROTECTED] wrote:


shawn bright wrote:
 hello there,
 i am writing an app for linux. what command would be easiest to test
 and see if a certain file exist ?
 i was going to do something like this
 try:
 file = open('/path/to/file', 'rb')
 return True
 except:
 return False
You should except IOError here, just to be clear and such.

 but i thought that there would be an easier way.
The os module has some function for checking if files exist, I think.



Yes, check out access():
http://docs.python.org/lib/os-file-dir.html

André

Or you could do

if targetfile not in os.listdir(directory): return False
else: return True

But your original solution is okay.
HTH,
-Luke
___
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] Use Python to learn kids (9 yr) to program

2006-11-29 Thread Andre Roberge

HI-

I think Python is a great choice.

You may want to have a look, as a first step, at
rur-plehttp://rur-ple.sourceforge.net.
Then, as a next step (although it might be a bit steep), you may want to
have a look at livewires http://www.livewires.org.uk/python/.   This will
provide a good introduction to pygame http://www.pygame.org.

André

On 11/29/06, Anders Persson [EMAIL PROTECTED] wrote:


Hi!

I have looked around for som language to use to learn my 9 year son
programming.

There is a KPL - Kids Programming Language but my son diden't grasp the
OO, GUI and everyting around this, maby becurse English is not his spoken
language, and for a beginner i think the inviroment was to complex.

So my plan is to use Python, has anyone try to learn kids this way, and
could
giv som ide how-to.
I witch way to introduce every part of the language,,,

best regards
Anders


___
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] Is there Python code for accessing an object's reference count?

2006-10-03 Thread Andre Roberge
On 10/3/06, Dick Moores [EMAIL PROTECTED] wrote:
 Is there Python code for accessing an object's reference count?

See sys.getrefcount.

André Roberge

 And does it matter to Python what this count is, other than whether
 it is zero or greater than zero (for garbage collection)?

 Thanks,

 Dick Moores

 ___
 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] File like object for Windows registry

2006-08-03 Thread Andre Roberge
On 8/3/06, Henry Finucane [EMAIL PROTECTED] wrote:
 On 8/3/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Hello!
 
  My app should run on debian and windows platforms. For storing the 
  configuration data, I use the ConfigParser module.
 
  What I find difficult is to determine a place for my configuration file. On 
  debian, it is simply
 
  os.path.join(os.path.expanduser(~)),myconfig)

This works on Windows as well.  I just tried it :-)

 
  but what am I supposed to do on Windows? I think a clean solution would be 
  to create a file-like object that reads and writes to the registry, is it?

Messing with the registry is (imo)  a bad idea.


 You might be able to do that, I don't know much about win32
 programming, but I believe a better solution is to use the built-in
 windows variables. %APPDATA% is where you should store user-specific
 application data (and even Microsoft is starting to store XML
 configuration files there), and it's an easy variable to get.

  import os
  os.environ[APPDATA]
 'C:\\Documents and Settings\\UserName\\Application Data'

 That should function just fine as a home directory replacement.

...

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


Re: [Tutor] Python Programming Books

2006-07-14 Thread Andre Roberge
On 7/14/06, Terry Carroll [EMAIL PROTECTED] wrote:
 On Thu, 13 Jul 2006, Grady Henry wrote:

  I have three books on Python programming, Learning Python by O'Reilly,
  Beginning Python by Hetland, and Python in a Nutshell by O'Reilly.
  Are these good (recommended) books?  Any others that might be
  recommended?

 I don't know the Hetland book.

I have about 10 Python books including the three books listed above.
Of all the books I own, my first recommendation would be to start with
Hetland's book, which I much prefer over Learning Python.  Python
in a Nutshell is my favourite reference book and I find the Python
Cookbook to be a great reference to learn advanced stuff from.

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


Re: [Tutor] Python Programming Books

2006-07-14 Thread Andre Roberge
On 7/14/06, wesley chun [EMAIL PROTECTED] wrote:
 while it would be a conflict-of-interest for me to give *my* opinion
 of the book, it appears to be pretty well-received (mostly by
 word-of-mouth) based on comments i've seen so far.  :-)

I don't know about others, but I think it might be of benefit if you
could give an assessment that would include a description of the
weaknesses of the book (e.g. [making this up] Core Python is not the
best beginner's book for people primarily interested in making GUI
based applications or games [Dawson's book is better in that
respect.]) as well as its strengths. It might help us in deciding to
point beginners to it (or not) as a potential choice based on their
interests.

[I could be in a minority opinion here.  People like Kent, Alan,
Danny, etc. should probably comment.]
André
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [ANN] RUR-PLE version 0.9.9

2006-06-22 Thread Andre Roberge
Roberge's Used Robot: a Python Learning Environment

Version 0.9.9 of RUR-PLE has been released.  It can be found at:
https://sourceforge.net/project/showfiles.php?group_id=125834

RUR-PLE should work properly on all major platforms (Mac, Linux and
Windows) in 3 different languages (English, French, Spanish).
Feedback would be appreciated to confirm this prior to release of
version 1.0.

--
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 Python. RUR-PLE is a wxPython-based app.

RUR-PLE contains four main elements:
1. Lessons viewable within an incorporated browser. Version 0.9.9
includes over 40 lessons introducing Python.   A few more will be
written for the 1.0 release.
2. A robot world with a robot that can accomplish tasks through Python
programs.
3. A built-in interpreter which can be used to play with Python.
4. A built-in file editor which can be used for futher Python explorations.

This version includes a triilingual (English, French and Spanish)
interface.  Translations to other languages are welcome.

Only English lessons are included.

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


Re: [Tutor] local day names in ascii

2006-06-19 Thread Andre Roberge
May I suggest you look at this
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871
including the comments.  (The last comment in particular looks intriguing...)

André

On 6/19/06, frank h. [EMAIL PROTECTED] wrote:
 Hello List,
 i am trying to convert local Swedish daynames to ASCII

 Måndag should become Mandag
 Lördag should become Lordag
 Söndag should become Sondag

 here is my session

 import locale
 locale.setlocale(locale.LC_ALL, 'sv_Se')
 datetime.date(2006, 06, 19).strftime(%A)
 'M\xc3\xa5ndag'
 datetime.date(2006, 06,
 19).strftime(%A).decode('utf8').encode('ascii','ignore')
 'Mndag'

 Somehow, the Swedish character å gets dropped in the conversion to ascii.
 how can I accomplish the conversion 'å' -- 'a' etc.? should I use a
 dictionary?
 thanks for any insight
  -frank


 ___
 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] Fwd: local day names in ascii

2006-06-19 Thread Andre Roberge
Message forwarded to the list for information.
André

-- Forwarded message --
From: frank h. [EMAIL PROTECTED]
Date: Jun 19, 2006 11:06 AM
Subject: Re: [Tutor] local day names in ascii
To: Andre Roberge [EMAIL PROTECTED]


André,
thank you so much for this spot-on pointer. the last comment indeed nails it.
excellent!!
-frank



On 6/19/06, Andre Roberge  [EMAIL PROTECTED] wrote:
 May I suggest you look at this
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871
 including the comments.  (The last comment in particular looks intriguing...)

 André

 On 6/19/06, frank h.  [EMAIL PROTECTED] wrote:
  Hello List,
  i am trying to convert local Swedish daynames to ASCII
 
  Måndag should become Mandag
  Lördag should become Lordag
  Söndag should become Sondag
 
  here is my session
 
  import locale
  locale.setlocale(locale.LC_ALL, 'sv_Se')
  datetime.date(2006, 06, 19).strftime(%A)
  'M\xc3\xa5ndag'
  datetime.date(2006, 06,
  19).strftime(%A).decode('utf8').encode('ascii','ignore')
  'Mndag'
 
  Somehow, the Swedish character å gets dropped in the conversion to ascii.
  how can I accomplish the conversion 'å' -- 'a' etc.? should I use a
  dictionary?
  thanks for any insight
   -frank
 
 
  ___
  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] Need info regd Singleton class implementation

2006-06-15 Thread Andre Roberge
On 6/15/06, Akanksha Govil [EMAIL PROTECTED] wrote:
 hi,

 I need to implement a singleton class in python.
 Please give me some refernce sites which can help me with the same.

The online Python Cookbook is a good reference site.  Here's the
result from a search:
http://aspn.activestate.com/ASPN/search?query=singletonx=0y=0section=PYTHONCKBKtype=Subsection


I use the following from the printed edition of the Python Cookbook:

class Singleton(object):
From the 2nd edition of the Python cookbook.
   Ensures that only one instance is created per running script
def __new__(cls, *args, **kwargs):
if '_inst' not in vars(cls):
cls._inst = object.__new__(cls, *args, **kwargs)
return cls._inst

André


 Also i want to know to call a destructor for a singleton class.

 Thanks
 Akanksha



  __
 Do You Yahoo!?
 Tired of spam? Yahoo! Mail has the best spam protection around
 http://mail.yahoo.com
 ___
 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] An Introduction and a question

2006-06-09 Thread Andre Roberge
On 6/9/06, Michael Sullivan [EMAIL PROTECTED] wrote:
 My name is Michael Sullivan.  I am a 26 year-old college student in
 Oklahoma. My wife and I have a small (three PCs) computer network that
 we operate out of our home.  We have our own domain (as one could tell
 by examining my email address)  I have novice-level experience with VB,
 C/C++, Java, and PHP, but I'm just starting out with Python.

 Here's the situation:  My wife likes to play the game Chuzzle, found at
 Yahoo Games.  We use primarily Linux, however Chuzzle is written as an
 ActiveX control, which only works on Windows.  I have not been able to
 get Internet Explorer to work correctly through Wine, so I determined to
 write a Chuzzle-like game (with many of my own enhancements) for Linux.
 I've been playing around with some Pygame examples lately, and thought
 that I'd try writing the game in Python (I've been meaning to learn
 Python for years, but just never got around to it.)  Today I started on
 writing the game.  I've decided (at least for now) to call my version,
 LinePuzzle.  For those of you unfamiliar with Chuzzle, here's the basic
 concept:  There are individual pieces of different colors arranged on a
 grid.  The pieces can be moved on a line either vertically or
 horizontally.  The object of the game is to position three similarly
 colored pieces ajacent to each other.  At this point the three pieces
 will disappear, and the pieces above them will fall to take their place.
 As the levels progress, locks are added so that the player cannot move a
 locked piece either horizontally or vertically.  The game is over when
 no more pieces can be removed.

 I started my script by creating a class called LinePuzzlePiece which
 represents a single coloured piece.  I wanted a random colour chosen
 from a list to be assigned to the piece, and then to prove that I had it
 set up correctly, I wanted to call a method that would print out the
 color of the piece.  Here is my code:

 #!/usr/bin/env python

 import random
 import time
 import math

 class LinePuzzlePiece:
This class defines a single playing piece for LinePuzzle
def __init__(self):
   seed(time)
   index = int(math.floor(uniform(1, 10)))   colorlist = [red,
 blue, green yellow, purple]   self.color = colorlist[index]

def printcolor():
   print self.color

 mypiece = LinePuzzlePiece
 mypiece.printcolor

1.  try mypiece.printcolor() instead.

2. I'm cc-ing the pygame user group.  I suggest that future questions
related to pygame be sent over to that group instead.  They are just
as friendly as the folks on the tutor list.

André


 I saved the script and made it chmod +x.  However, when I run it, I get
 this:

 [EMAIL PROTECTED] ~ $ ./linepuzzle.py
 [EMAIL PROTECTED] ~ $

 Now, I'm no expert, but I really think something should have been
 printed, if even a blank line.  What am I doing wrong here?  Why is
 nothing printing?  Is my printcolor method even being called
 successfully?
 -Michael Sullivan-



 ___
 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] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Andre Roberge
On 6/5/06, Peter Jessop [EMAIL PROTECTED] wrote:
Thanks AndreI realise now I did not make it too clear.Basically the variable names are predictable but the values aren't.I assumed that. I just recreated the list as you gave it because it was easy :-)
Maybe I should have expressed it like thisf0_n = arbitrayValue
f0_v =another valulef1_n=something elsef1_v=etc.f100_n = another valuef100_v = nexvalueI then wish to pass the list of 2ples as an argument to a function and
thus I need the variable themselves and not the string values.Ok, the approach I gave you would produce instead:data = [ (arbitraryValue, another valule), (something else,  ]
Why couldn't you pass this to your function? Ok, here's another experiment...1. I will first generate a whole bunch of arbitrary numerical values:import randomfor i in range(101): print 'f%d_n = %d'%(i, 
random.randint(0, 100)) print 'f%d_v = %d'%(i, random.randint(0, 100))===f0_n = 40f0_v = 28f1_n = 49f1_v = 5...2. Next, I will use the approach I gave you before, but with these values, and I will do it with a one-liner:
data = '' + ','.join([(f%d_n, f%d_v)%(i, i) for i in range(101)]) + ']'big_list = eval(data)3. Next, I will define a function that works on these valuesdef find_special(data): for item in data:
 if item[0]  10: print item[1], find_special(big_list)=The result in my case turns out to be:49 50 57 96 98 23 69 16 4Of course this result on its own is meaningless :-)
Nonetheless, does this help? Or do you really, absolutely need to pass the named variables, not their values?André
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] help requested: port not free, under Windows XP

2006-05-25 Thread Andre Roberge
On 5/25/06, Richard Harding [EMAIL PROTECTED] wrote:
Andre Roberge wrote: ===Now the question=== Someone on edu-sig tried to get it working on her computer running Windows XP home edition (just like mine, where it works fine!). However, she gets an error message about
  port 8080 not free on local host. This is after she made sure nothing else internet-related was working.[This kind of message can happen if another instance of Crunchy Frog is already running, which
 she made sure wasn't.] smart and friendly people here that I could find an answer ;-)Ideas:1) Built in XP firewall, what SP is she at vs what you might have?2) 8080 is a common port for proxy servers and alternate web configs so
my first suggestion would be to change the app to not use a port that isso commonly used for something else.3) In the end I would just try to port scan the machine and see if it islistening on port 8080 and then you're stuck trying to find out why.
There are several ports scanners for windows you can download a trialof. I personally just use nmap.Thank you Rick (and Alan) for your suggestions which I forwarded to Catherine, would-be-user of Crunchy Frog. Apparently Catherine
was using port 8080 as a proxy server; changing it made everything
work. This also tells me that I should use a different number as a default.

I'll now go back to just being a reader of this list, with some rare attempts at answering questions.

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


[Tutor] help requested: port not free, under Windows XP

2006-05-24 Thread Andre Roberge
[message re-sent; original seemed not to have been received, according to the archives. Apologies if this is not the case.]Hi all-===Preliminaries===I wrote a new app (Crunchy Frog)
which is meant to transform boring traditional python tutorial into
truly interactive experiences. It is still at an alpha stage but is
promising imo; for those interested, you can find it at:
https://sourceforge.net/project/showfiles.php?group_id=125834

It currently requires both CherryPy and Elementtree as additional packages.Starting the app launch your favourite browser (or open a new tab/window). This is done through the instruction:
cherrypy.server.start_with_callback(webbrowser.open, ('http://localhost:8080',),)===Now the question===
Someone on edu-sig tried to get it working on her computer running
Windows XP home edition (just like mine, where it works fine!).
However, she gets an error message about  port 8080 not free on local host. This is after she
made sure nothing else internet-related was working. [This kind of
message can happen if another instance of Crunchy Frog is already
running, which she made sure wasn't.]
I am stumpedI am thinking it might be a firewall
issue (I have ZoneAlarm installed myself), but I am really not
sure I thought there were enough smart and friendly people here
that I could find an answer ;-)


Thanks in advance for any help, pointers, etc. Of course, you can reply directly on the edu-sig list if you want!André
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] help requested: port not free, under Windows XP

2006-05-24 Thread Andre Roberge
Hi all-===Preliminaries===I wrote a new app (Crunchy Frog) which is meant to transform boring traditional python tutorial into truly interactive experiences. It is still at an alpha stage but is promising imo; for those interested, you can find it at:
https://sourceforge.net/project/showfiles.php?group_id=125834
It currently requires both CherryPy and Elementtree as additional packages.Starting the app launch your favourite browser (or open a new tab/window). This is done through the instruction:
cherrypy.server.start_with_callback(webbrowser.open, ('http://localhost:8080',),)===Now the question===
Someone on edu-sig tried to get it working on her computer running Windows XP home edition (just like mine, where it works fine!). However, she gets an error message about 
 port 8080 not free on local host. This is after she made sure nothing else internet-related was working. [This kind of message can happen if another instance of Crunchy Frog is already running, which she made sure wasn't.]
I am stumpedI am thinking it might be a firewall issue (I have ZoneAlarm installed myself), but I am really not sure I thought there were enough smart and friendly people here that I could find an answer ;-)


Thanks in advance for any help, pointers, etc. Of course, you can reply directly on the edu-sig list if you want!André
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web intefaces?

2006-05-09 Thread Andre Roberge
On 5/9/06, Christian Wyglendowski [EMAIL PROTECTED] wrote:
[on creating a web app...]

 If you do go with CherryPy, check out this recipe I submitted to the
 online Python Cookbook:
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481

 It was written for CherryPy 2.1 but should still work with the current
 2.2 release.

I second this, absolutely. I have started creating such an app
[Crunchy Frog] using CherryPy.  There are 10 tutorial examples
included in the distribution, which are a big help to get started.
André

P.S. Thank you Christian for your CherryPy newbie friendly recipe!
 Christian
 http://www.dowski.com
 ___
 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] Avoiding the use of files to store intermediate results

2006-04-25 Thread Andre Roberge
On 4/25/06, Hugo González Monteverde [EMAIL PROTECTED] wrote:
 Remember duck typing. An object just needs to look like a file in order
 to be used like one.

 Guido's time machine has already forseen your problem. Take a look at
 the StringIO module.  It allows you to use a string where you would
 normally pass a file object.


Since I do something like
os.open(python some_file.py  some_output)
I don't see how I can pass a file-like object.  As far as I can tell
python (the command) looks for a real file on the current path.

André

 Hope that helps,

 Hugo

  ##
  While this works, I find it messy, as it creates some intermediate
  files.  I was wondering if there was a better way to do things all in
  memory, in an OS independent way.
 
  [Note that the complete application is approximately 665 lines long
  ... a bit too much
  to post all here :-)]
 
  André
  ___
  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] Avoiding the use of files to store intermediate results

2006-04-24 Thread Andre Roberge
I wrote a small wxPython based app to test code snippets.
(google for python lightning compiler if you want to see the full code).

In the basic mode, I redirect the standard input and output and
execute the code taken from the editor window so that the result
appears in the output window.

Here are the 4 main lines of code to accomplish this:

sys.stdout = self.outputWindow
sys.stderr = self.outputWindow
user_code = self.PythonEditor.GetText()
exec user_code in myGlobals

For example, if I have the following situation:
input window
print Hello world!


the result of running the program will be this:
output window===
Hello world!


Simple enough :-)  [Actually, there's more to it, but this description
should suffice for illustration purposes.]


Now, I want to be able to test the code using the doctest module.

I can't use exec as doctest.testmod() will be testing my entire
application, not simply the code in the input window!

The solution I chose was to
1. Create a new file which contains the code to be tested with the
appropriate doctest call.
2. Run this file with Python, redirecting the result to a second file.
3. Read the result from the second file into a string.
4. Print the string (which, because of redirection) appears in the
output window.

Here are the main lines of code to do this:

sys.stdout = self.outputWindow
sys.stderr = self.outputWindow
user_code = self.PythonEditor.GetText()

user_code += \nimport doctest\ndoctest.testmod()

f = open('_doctest_file.py', 'w')
f.write(user_code)
f.close()

if verbose:
os.popen(python _doctest_file.py -v _doctest_file.output)
else:
os.popen(python _doctest_file.py _doctest_file.output)
result = open(_doctest_file.output, 'r').read()
print result

##
While this works, I find it messy, as it creates some intermediate
files.  I was wondering if there was a better way to do things all in
memory, in an OS independent way.

[Note that the complete application is approximately 665 lines long
... a bit too much
to post all here :-)]

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


[Tutor] [Summary] Re: unit testing raw_input()

2006-04-19 Thread Andre Roberge
Thank you Michael, Danny and Alan for your suggestions.
I've included below my summary of the three very different
suggestions, my brief analysis of them, and my conclusion.
Anyone is free and welcome to comment!

On 4/18/06, Andre Roberge [EMAIL PROTECTED] wrote:
 Hi all-

 Suppose I had a function like the following:

 def y_n(prompt=Answer yes or no):
 while True:
 answer = raw_input(prompt)
 if answer in ['y', 'Y', 'yes']:
 print You said yes!
 break
 elif answer in ['n', 'N', 'no']:
 print You said no!
 break
 else:
 print %s is an invalid answer.%answer

 How could I go about to write an automated test for it?

 André

Alan Gauld suggested to create a data file that simulate
possible user responses and to use redirection to feed
the data to the program.  Assuming the function to be
tested is in y_n.py, it would look like the following:

$ python y_n.py  fake_user_data  test_result

Then, I assume I would do an automated comparison between
test_result and some expected_result file to ensure everything
is ok.

This, in my opinion, is the cleanest solution.  However, it may
not scale well if one wants to build a test suite with many
functions/methods, some of which require some user-input.
Ideally, one should be able to change the order in which unit tests
are run; with this approach, both the test suite and the user data
file would probably have to be change in sync.



Danny Yoo suggested to change the function to be tested, to
include an extra parameter, i.e. go from
def y_n(prompt=Answer yes or no):
to
def y_n(prompt=Answer yes or no, raw_input=raw_input):

To quote Danny:
But now we can hardcode particular inputs by sending y_n() a mock
raw_input that returns precooked values.

###
def yes1_raw_input(prompt):
return y

def yes2_raw_input(prompt):
return Y

def yes3_raw_input(prompt):
return yes

def yes4_raw_input(prompt):
return YES
###
[end quote]

My first reaction is Neat! :-).   However,
this is only usable if one has access to the original
function.  If one uses a library function like y_n()
(for example, there is a similar function in the livewires module
which some of you probably know)
which is not, in principle, modifyable, this approach fails.



Michael (last name unknown) suggests another approach, which
shares some similarities with Danny's.  Here's Michael's
edited/truncated explanation:

You create a mock for raw_input, put the above code inside a module and rebind
raw_input in the module before calling your function.

ie:
(CONTENTS of y_n.py)
def y_n(prompt=Answer yes or no):
   while True:
   answer = raw_input(prompt)
   if answer in ['y', 'Y', 'yes']:
   print You said yes!
   break
[snip]
(END CONTENTS of y_n.py)

[Michael's explanation using the interpreter is modified below]

Then, one can have a test function in a separate file

--- begin test function
import y_n
def raw_input_mock(prompt): # create a mock
return n
y_n.raw_input = raw_input_mock  # rebind the name inside the module
y_n.y_n() # Run, this now calls our mock instead of the real raw_input
--- end test function
[end of quote]

Note that y_n() should probably return a string
(instead of using a print statement)
so that the output can be compared with the expected result;
otherwise, one has to redirect the output to a file
and do a comparison, as I mentioned with Alan's explanation.

This is a rather clever method; I would never have thought
of rebinding y_n.raw_input in this way.

The only weakness that I see with this approach is if one
wants to test a function like y_n() knowing that it ask
the user for some input ... but not knowing what function
it uses to do so.  This can be the case if one has a compiled
library with only the interface (what values can be passed
to the functions and how; what are the expected outputs) being
known.  Danny's approach would also not work here, whereas
Alan's would.

As it is, I will be working on a very small project with another
programmer, where I will be responsible to write some
unit tests.  I have access to the source code (so I know
which function is used to get input from the user), but I do not want
the other programmer to have to change the way his code
is written simply to accommodate my tests.
The other programmer's code will be in a single module; similarly,
I want to write a single test module myself - without having to
worry about keeping a separate data file.
Therefore, I will go with Michael's approach.

Thanks to everyone, and I hope that I didn't misrepresent any
of the three solutions proposed.  It's been fun!

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


[Tutor] unit testing raw_input()

2006-04-18 Thread Andre Roberge
Hi all-

Suppose I had a function like the following:

def y_n(prompt=Answer yes or no):
while True:
answer = raw_input(prompt)
if answer in ['y', 'Y', 'yes']:
print You said yes!
break
elif answer in ['n', 'N', 'no']:
print You said no!
break
else:
print %s is an invalid answer.%answer

How could I go about to write an automated test for it?

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


Re: [Tutor] checking diagonals on a chessboard

2006-04-13 Thread Andre Roberge
On 4/13/06, Matthew Singletary [EMAIL PROTECTED] wrote:

 first, A disclaimer:
 This isn't directly homework but is related to an assignment of mine

 I'm building a genetic algorithm to solve the queen placement problem, the
 complicated stuff I can do on my own, but I'm not getting one part.
 suppose the queen is on a square, I can check that it is in the same row or
 same col but the diagonals, are less straight-forward.
 I know I could solve this by just smashing away at it, but I was wondering
 if anyone could suggest some tips on directions to work

 I'm NOT looking for any answers, just some tips to an _elegant_ method to
 solve this.

The answer you are looking for most likely depends on how you
represent your chessboard (i.e. single list, list of list, etc.).

Not an answer to your question directly, but a Python solution using
recursion can be found at:
http://en.wikipedia.org/wiki/Eight_queens_puzzle
Of course, it has to include how to check for diagonals, which you can
use for what you are looking for.  I don't know if it can be
considered to be elegant.

[As an aside, I used this solution to write an undocumented visual
solution of this problem using rur-ple (rur-ple.sourceforge.net),
where 8 queens move on a screen to illustrate one such solution,
with colored lines showing which square is attacked by each queen. 
For those that have downloaded rur-ple, you can find this solution
under rur_programs/temp/queen.rur]

André


 The reason I started teaching myself python was it seemed a little more
 concise, and it seems there should be an elegant way to do this but I guess
 I'm not used to thinking the pythonic way

 thanks for any help
 matt


 ___
 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] Watch and control access to an executable

2006-04-08 Thread Andre Roberge
On 4/8/06, Alan Gauld [EMAIL PROTECTED] wrote:
  Desktop to the executable). The problem is, only *one* person at a time
  should run the program.

[snip]

 The usual way of doing this is simply to create an empty file
 when the program starts and delete it when the program closes
 In python:

Couldn't this approach cause problems if the Python program crashes,
leaving behind the empty file?

However, there is a Cookbook solution that does, I believe, that what
the original poster asked:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67663

It is actually so short that I can even reproduce it below.
=
from win32event import CreateMutex
from win32api import GetLastError
from winerror import ERROR_ALREADY_EXISTS
from sys import exit

handle = CreateMutex ( None, 1, 'A unique mutex name' )

if GetLastError ( ) == ERROR_ALREADY_EXISTS:
# take appropriate action if this is the second
# instance of this script; for example,
print 'Oh! dear, I exist already.'
exit ( 1 )

A detailed explanation (of a slightly modified version) can be found
in the second edition of the Python Cookbook [Recipe 9.9].

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


Re: [Tutor] Simple way for i18n ?

2006-03-22 Thread Andre Roberge
On 3/22/06, francois schnell [EMAIL PROTECTED] wrote:

 Hello all,

 I wish to translate a Python script from English to French. I've read the
 offical documentation (python.org doc) but I must admit that I'm lost now
 ...
 I've found some simple explanations here but I can't make it work:
 http://karrigell.sourceforge.net/en/internationalization.htm

 Here's where I'm stuck:

 Let's imagine my app is: myapp.py
 --
  import gettext
 _ = gettext.gettext

 print _(hello friends)
 print _(Bye Bye)
 ---

 Here are my folders on a windows box:

 C:\myappfolder\
 ---\Translations\francais\LC_MESSAGES

 My myapp.py is in myappfolder

 In this folder I've used pygettext.py to produce a messages.pot file = I
 add the translation in it = I have a messages.po file.
 I then used msgfmt.py to produce messages.mo file.

 I then copied messages.po and messages.mo in LC_MESSAGES folder
 C:\myappfolder\
 ---\Translations\francais\LC_MESSAGES

 I now come back to myapp.py and add two lines:

 ---
 import gettext
 _ = gettext.gettext

 t=gettext.translation(messages,c:\myappfolder\Translations,francais)
 t.install()

 print _(hello friends)
 print _(Bye Bye)
 ---

 When I do that Python anwers:

 
 Traceback (most recent call last):
   File C:\myappfolder\myapp.py, line 4, in ?

 t=gettext.translation(messages,c:\myappfolder\Translations,francais)
   File C:\Python24\lib\gettext.py, line 456, in translation
 raise IOError(ENOENT, 'No translation file found for domain', domain)
 IOError: [Errno 2] No translation file found for domain: 'messages'
 

 I'm stuck here.
 I understand it doesn't find the translation file but I can't figure out
 why.


I've always seen standard directory structures (e.g. \locales\fr,
etc.) rather than custom ones as above, so I can't comment for sure
... but: try to either write
rc:\myappfolder\Translations
or
c:\\myappfolder\\Translations
to avoid possible backslash problems...

Bonne chance!
André



 Can you tell me what I'm doing wrong or direct me to an URL (or a Python
 book) where simple internationalisation for Python is gently explained

 Thanks
 francois (...from France)





 ___
 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] Python MP3

2006-03-21 Thread Andre Roberge
On 3/21/06, Johanna [EMAIL PROTECTED] wrote:
 Hallo

 This is my first post, so hallo to everyone. Im just a newbee with python so
 I hope my msg will make some sense.

 Is it possible to work with MP3 in python?


Pygame (http://www.pygame.org/docs/ref/music.html) apparently works
with mp3 files.

There's also a tutorial on using Pygame to work with sound files at
http://takira.freehosting.net/ (check Pygame notes).

I haven't used it myself.

André

 I'm looking for a library to modify MP3s (like fade in, fade out, etc..). I
 know there are actually some libraries for doing this work with .wav but I
 didn't find one for working with MP3. I'm not sure but should be something
 like - http://effbot.org/librarybook/wave.htm . Anyone?



 Thanks.



 Jo
 ___
 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] Opening .py files in firefox

2006-03-21 Thread Andre Roberge
** Copy of a reply sent only to Alan Gauld by mistake.

On 3/20/06, Alan Gauld [EMAIL PROTECTED] wrote:
  If the browser tries to execute the script you will need to go to
  the file types setting in the browser and set .py to plain-text.
 
  This is what I need to do ... but, after looking at all the options
  (within tools-Options), I still can not find a way to do this;

 Neither can I! How odd.

  firefox-snafu: when I try to open a file in my document, firefox
  splits up the path, interprets the request as a series of files to
  open, and start to open a number of totally unrelated webpages.

 You probably need to mess around with quotes.

 Something like %1 after the exectuable name might do it
 %1 is DOS shorthand for the name of the file... Putting it in
 quotes should stop Firefox splitting the path.



Thanks, that solved both problems!  I can now either right-click on a
Python file (icon) and chose to display it in the browser, or open the
file within Firefox (ctrl-o) itself.

Thank you!! :-)

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


[Tutor] Opening .py files in firefox

2006-03-19 Thread Andre Roberge
Hi everyone-

This is not strictly speaking a Python question but it's probably
something that other pythonistas have encountered and, hopefully
solved :-)

When I click on a link to a .py file (either remotely or on my
computer) using firefox, it gives me two options: running the script
with the default Python app, or saving the file.  What I would like is
to display the file as text in the browser.  Any ideas?  This is on
Windows XP.

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


Re: [Tutor] Opening .py files in firefox

2006-03-19 Thread Andre Roberge
On 3/19/06, Alan Gauld [EMAIL PROTECTED] wrote:
  computer) using firefox, it gives me two options: running the script
  with the default Python app, or saving the file.  What I would like is
  to display the file as text in the browser.

 Open Tools-Folder Options in Windows explorer

[snipped useful explanation on setting defaults within Windows explorer]

 If the browser tries to execute the script you will need to go to
 the file types setting in the browser and set .py to plain-text.

This is what I need to do ... but, after looking at all the options
(within tools-Options), I still can not find a way to do this;
firefox insists on executing the script.  This is for a local file.

btw, the deleted part of your explantion contained an unfortunate
firefox-snafu: when I try to open a file in my document, firefox
splits up the path, interprets the request as a series of files to
open, and start to open a number of totally unrelated webpages.

 But I didn't need to do that.

:-( for me!

Thanks for your help, anyway; I'll stick to opening them with an editor for now.

André


 HTH,

 Alan G
 Author of the learn to program web tutor
 http://www.freenetpages.co.uk/hp/alan.gauld














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


Re: [Tutor] Problem wxPython

2006-02-17 Thread Andre Roberge
On 2/17/06, Prabhakar K [EMAIL PROTECTED] wrote:
 Hai to all,

 I installed ActivePython-2.4.1-247-win32-ix86 and
 wxPython2.6-win32-ansi-2.6.2.1-py2 in my system. When i Run
 a wxPython example.. geeting an Errors

[snip]
   File F:\python\wx.py, line 1, in ?
 from wxPython.wx import *
 ImportError: No module named wx



wxPython changed notation between version 2.4 and 2.6 (if memory is
right), and your code is using the old notation with the new package. 
Try (untested) the following changes:

 from wxPython.wx import *
import wx

 class MyApp(wxApp):
class MyApp(wx.App):
 def OnInit(self):   #no change
 frame = wxFrame(NULL, -1, Hello from wxPython)
frame = wx.Frame(None, -1, Hello from wxPython)
 frame.Show(true)
frame.Show(True)
 self.SetTopWindow(frame) #no change
 return true
return True

 app = MyApp(0)
 app.MainLoop()


André
 ___
 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] map vs. list comprehension

2006-02-14 Thread Andre Roberge
On 2/14/06, Michael Broe [EMAIL PROTECTED] wrote:
 I read somewhere that the function 'map' might one day be deprecated
 in favor of list comprehensions.

 But I can't see a way to do this in a list comprehension:

   map (pow, [2, 2, 2, 2], [1, 2, 3, 4])
 [2, 4, 8, 16]

 [2**i for i in [1, 2, 3, 4]]
[2, 4, 8, 16]


André

 Is there a way?

 Cheers,
 Mike
 ___
 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] sys.argv

2006-02-13 Thread Andre Roberge
On 2/13/06, János Juhász [EMAIL PROTECTED] wrote:
 Hi,

 I want to pass args to my python script on XP.
 This code
 print 'argv[0] %s' % sys.argv[0]
 print 'argv[1] %s' % sys.argv[1]
 print 'argv[2] %s' % sys.argv[2]

 shows this:
 argv[0] D:\devel\home\devel\python\db\xlsxml.py
 argv[1] K:\IT\admin\test\Flat
 argv[2] Files\2006\06.02.2006-293753-gy

Your path has a space in it (between Flat and Files). This is probably why it is
broken as two different arguments.
André



 but I would see this:
 argv[0] D:\devel\home\devel\python\db\xlsxml.py
 argv[1] K:\IT\admin\test\Flat Files\2006\06.02.2006-293753-gy
 argv[2] ''


 Yours sincerely,
 __
 János Juhász

 ___
 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] cannonical matrix representation?

2006-02-10 Thread Andre Roberge
On 2/10/06, Mike Cheponis [EMAIL PROTECTED] wrote:
 What's the best way to represent a matrix M with 4 dimensions, such as 
 M[x][y][z][t] where each element in the sparse matrix could be a simple 
 number, or could be an executable Python function snipped that returns a 
 value when that cell is evaluated?

 The user of the program will type in Python functions to be inserted into 
 particular cells in the 4-D matrix.

 I did't see any package that exactly does this; do I write my own Matrix 
 class and base it on lists?

 Thanks!  -Mike

If it is a truly sparse matrix, I would use a dictionary with tuples
as keys; i.e.,
m{(x, y, z, t) = element}

André


 p.s. This seems to me like it ought to be built into the base language - 
 multidimensional object arrays. (Indeed, maybe it is, and I'm just too dense 
 to notice!)

 ___
 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] nutshell review

2006-02-09 Thread Andre Roberge
On 2/9/06, nephish [EMAIL PROTECTED] wrote:
 lo there,
 i know this comes up from time to time. i am considering buying 'python
 in a nutshell'. All the reviews i have read for it are very good. But it
 only covers up to python 2.2. i use 2.3 at work, and tinker with 2.4 at
 home. As good a reference as it is, is it too dated to be that good
 still ? i have 'Learning Python' and 'Programming Python'. Learning is
 awesome for me, Programming is a bit over my head.
 any suggestions?

I own about 10 Python books including Learning Python, Programming
Python and Python in a Nutshell.  Of these three, Python in a Nutshell
is the one I find the most useful.  The Python Cookbook (2nd ed) is my
other favourite.  Your mileage may vary...

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


Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Andre Roberge
On 2/8/06, Danny Yoo [EMAIL PROTECTED] wrote:


 On Wed, 8 Feb 2006, Victor Bouffier wrote:

  Hi to all,
 
  I'd like to split a long string into equally long strings (len(str) =
  3). I did the following using regexes:
 
   n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf'
   o = re.split(r'(...)', n)
   print o
  ['', 'xb1', '', 'jyz', '', 'qnd', '', '1ee', '', 'nko', '', 'kqn', '',
  'hep', '', '6vp', '', '692', '', 'qi9', '', 'tma', '', 'g3o', '', 'wzq',
  '', 'w0s', '', 'dq3', '', 'zjf', '']
 
  Which gives me empty strings between each value.

 Hi Victor,

 Try using re.findall() instead of re.split().  The behavior you're seeing
 with split is perfectly logical: each pair of empty strings is being split
 by that three-character sequence.

There's a tongue-in-cheek quote that I really like:
Sometimes you have a programming problem and it seems like the best
solution is to use regular expressions; now you have two problems.

Given that you are thinking of using re, and that you seem to have a
working solution, I doubt this is a homework problem... so, how about
the untested:

n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf'
length = len(n)
o = []
for i in range(0, length, 3):
o.append(n[i:i+3])

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


Re: [Tutor] IDE - Editors - Python

2006-02-06 Thread Andre Roberge
On 2/6/06, Tim Johnson [EMAIL PROTECTED] wrote:
 * Paul Kraus [EMAIL PROTECTED] [060206 06:04]:
  Which editors does everyone use and why. Please keep the discussion to IDE's
  rather then any editors. I am well versed on Emacs and VI so anything beyond
  them would be appreciative. Why you like the editor and how it helps reduce
  your development time would be productive and helpfull.

   Hello Paul:

   I guess by your mailer that you are using linux. If you were using
   windows, I would recommend pythonwin.

I'm programming under Windows and I haven't found anything better than
Stani's Python Editor (spe).  It should be cross-platform.

I've seen others recommend eclipse+pydev.

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


Re: [Tutor] Sharing Variables Across Modules

2006-02-06 Thread Andre Roberge
On 2/6/06, Rich Shepard [EMAIL PROTECTED] wrote:
I'm developing a wxPython-based application. The UI is a notebook, with the
 contents of each page in a separate module. In one module (modelPage.py), I
 have defined the class modModel, which is an instance of a wx.Panel class.
 Within modModel is a text control widget named tcName.

The main module, eikos.py, imports modModel from modPage.py. The main
 module has two classes: MyNotebook (subclassed from wx.Notebook) and MyFrame,
 which contains the notebook and menus.

The File-New menu calls the method OnFileNew. This displays a directory
 dialog so the user can select the directory in which the new file is to be
 placed. Then it displays a text entry dialog for the name of the new file.

I am able to enter the new file name and it is correctly assigned to the
 variable, projname. What I have not been able to do is have that same
 filename displayed in the text control widget, tcName. Here is OnFileNew from
 the main module:

def OnFileNew(self, event):
   Create a new file and open it.
  self.dirname = ''
  wd = wx.DirDialog(self, Chose the default directory, .,
 style=wx.DD_NEW_DIR_BUTTON)
  if wd.ShowModal() == wx.ID_OK:
dirname = wd.GetPath()
ted = wx.TextEntryDialog(self, Enter the project name, New Project 
 Name, ,
 style=wx.RAISED_BORDER|wx.OK|wx.CANCEL)
if ted.ShowModal() == wx.ID_OK:
  projname = ted.GetValue()
  tcName = self.modModel.tcName
  tcName.WriteText(self, projname)
  ted.Destroy()
wd.Destroy()

While projname has the correct string, tcName remains undefined:

File eikos.py, line 272, in OnFileNew
  tcName = self.modModel.tcName
 AttributeError: 'MyFrame' object has no attribute 'modModel'

I would *guess* that you'd want instead something like
tcName = self.myNotebook.modModel.tcName

As I understand, modModel is a page in a wx.Notebook; you probably
created it within your Notebook instance, and not your Frame instance.
 Meanwhile, your OnFileNew method appears to belong to your Frame
instance.

André


How do I make tcName visible in eikos.py when it's defined in modelPage.py?

 Rich

 --
 Richard B. Shepard, Ph.D.   |   Author of Quantifying 
 Environmental
 Applied Ecosystem Services, Inc. (TM)   |  Impact Assessments Using Fuzzy 
 Logic
 http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863





 ___
 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] Documentation

2006-02-05 Thread Andre Roberge
On 2/5/06, Paul Kraus [EMAIL PROTECTED] wrote:
 I have been working through a couple of books and learning alot. However I
 can't seem to find any easy way to learn more about different methods and
 commands.

 For instance what are all of the methods that can be applied to lists and what
 do they do and how do they work. Or in TKinter what are all the different
 things can I do with a button besides just setting the command and the text
 and such. These are just examples.

 I can't find an easy way to do this.

Python is your friend!Here's the (truncated) result of an
interactive session.

PythonWin 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit
(Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED])
- see 'Help/About PythonWin' for further copyright information.
 a = []
 dir (a)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
'__setslice__', '__str__', 'append', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
 help(a.index)
Help on built-in function index:

index(...)
L.index(value, [start, [stop]]) - integer -- return first index of value

 import Tkinter
 dir(Tkinter)
['ACTIVE', 'ALL', 'ANCHOR', 'ARC', 'At', 'AtEnd', 'AtInsert',
'AtSelFirst', 'AtSelLast', 'BASELINE', 'BEVEL', 'BOTH', 'BOTTOM',
'BROWSE', 'BUTT', 'BaseWidget', 'BitmapImage', 'BooleanType',
'BooleanVar', 'BufferType', 'BuiltinFunctionType',
'BuiltinMethodType', 'Button',

[snip]

 dir(Tkinter.Button)
['_Misc__winfo_getint', '_Misc__winfo_parseitem', '__doc__',
'__getitem__', '__init__', '__module__', '__setitem__', '__str__',
'_bind', '_configure', '_displayof', '_do', '_getboolean',
'_getdoubles', '_getints', '_grid_configure', '_nametowidget',
'_noarg_', '_options', '_register', '_report_exception', '_root',
'_setup', '_subst_format', '_subst_format_str', '_substitute',

[snip]

 help(Tkinter.Button.configure)
Help on method configure in module Tkinter:

configure(self, cnf=None, **kw) unbound Tkinter.Button method
Configure resources of a widget.

The values for resources are specified as keyword
arguments. To get an overview about
the allowed keyword arguments call the method keys.


Try it on your own!  As a rule, stay away from methods that start with
an underscore.

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


Re: [Tutor] Documentation

2006-02-05 Thread Andre Roberge
On 2/5/06, Paul Kraus [EMAIL PROTECTED] wrote:
   help(Tkinter.Button.configure)
 
  Help on method configure in module Tkinter:
 
  configure(self, cnf=None, **kw) unbound Tkinter.Button method
  Configure resources of a widget.
 
  The values for resources are specified as keyword
  arguments. To get an overview about
  the allowed keyword arguments call the method keys.
 
 
  Try it on your own!  As a rule, stay away from methods that start with
  an underscore.
 Thanks for the fast response. This was exactly what I was looking for. One
 last question how would I 'call the method keys'. from the example above.

To be honest ... I don`t know.  I don't use Tkinter myself.  Here's
what I get from the help function:
-
 help(Tkinter.Button.keys)
Help on method keys in module Tkinter:

keys(self) unbound Tkinter.Button method
Return a list of all resource names of this widget.
---
So, I would guess that, after creating a button, through something like
aButton = Button(parent, text=Some label, command=some_action)

You could do:
resources = aButton.keys()

There is a free book on using Tkinter to be found at
http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html

Another great resource is to be found on
http://www.pythonware.com/library/index.htm

You will find there a Tkinter reference book on-line (html version) or
a downloadable one (pdf).  Here's what I found by browsing...
===
The following dictionary method also works for widgets:

keys() = list

Return a list of all options that can be set for this widget. The
name option is not included in this list (it cannot be queried or
modified through the dictionary interface anyway, so this doesn't
really matter).
===

You may have to wait until tomorrow to get your answer, when the real
tutors are online ;-)

Good luck!

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


Re: [Tutor] Todays Learning Python Question From a Newbie ;)

2006-02-02 Thread Andre Roberge
As I indicated in private email yesterday to Jon, there is indeed a
hole in the computer stratey when the following three first moves are
made:
x:2
o:4  (first available best move for the computer)
x:7

I also sketched a solution, which I will rephrase here in a different way.

The next best move from the list leads to a win for the human, if
she/he plays correctly.
So, one has to put in somewhere (there are a few possible places) a
test to see if this combination of the first three moves has occurred;
if so, hard-code a computer response that defeats this strategy; if
not, go and use the standard best move list.

André

On 2/2/06, Jon Moore [EMAIL PROTECTED] wrote:
 All that does is reverse the hole!?!?

 x:2
 o:4
 x:7
 o:0
 x:8
 0:5

 O |   | X
 -
   | O | O
 -
   | X | X


 On 02/02/06, Wolfram Kraus [EMAIL PROTECTED] wrote:
  Jon Moore wrote:
  [...]
 
   Thanks to  André, there is a way to win every time if you take the first
   move (see below), so there MUST be a whole in the computers stratergy!
   Based on what we all know about the game, I would say that you can not
   make it so that the computer can win every time, but it should be
   possable to make it tie.
  
   x: 0
   o: 4
   x: 7
   o: 2
^
  Make this 6,3,8 or 5 and it will be a tie
 
   x: 6
  
   0 | 1 | 2
   -
   3 | 4 | 5
   -
   6 | 7 | 8
  
  
 
 
  Wolfram
 
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
 



 --
 Best Regards

 Jon Moore
 ___
 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] critique my wrapper

2006-02-02 Thread Andre Roberge
On 2/2/06, Christopher Spears [EMAIL PROTECTED] wrote:
 This is a class I created that wraps a list.  Could
 someone please critique the class?

 class MyList:
 def __init__(self, aList=None):
 if aList is None:
 self.mylist = []
 else:
 self.mylist = aList[:]
 def __getitem__(self, index):
 return self.mylist[index]
 def __setitem__(self, index, value):
 self.mylist[index] = value
 def __len__(self):
 return len(self.mylist)
 def __delitem__(self, index):
 del self.mylist[index]
 def __add__(self, other):
 self.mylist = self.mylist + other
 def __repr__(self):
 return '%s' % self.mylist
 def append(self, other):
[snip]

It's hard to critique without knowing your intentions.  Here's a
simpler class that should
do the same as yours!

class MyList2(list):
def __init__(self, aList=[]):
 list(aList)

I may have missed something but, unless you are re-defining a list
method, it is easier to simply subclass list like I have done - and
only re-define the methods whose behaviour you want to redefine, or
add new method.  Otherwise, simply use

a_list = list()  !!!

Then again, perhaps I am missing something obvious...

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


Re: [Tutor] A row of cards, but they're all red

2006-01-30 Thread Andre Roberge
On 1/30/06, -Terry- [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-

[snip]
Try reducing your code to only the following:

 Here's the code:
 - --
 #!/usr/bin/env python

 suits = [red , blue, green, yellow]
 ranks = [ace, two, three, four, five,  six, seven,
   EIGHT, nine, ten, jack, queen, king]
 value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]


 for suit in suits:
  for x, rank in enumerate(ranks):
  cards.append([suit, rank, value[x], images[x]])

And replace the last line by:
print [suit, rank, value[x], x]

You will see that x is not doing what you want it to inside images...
As a hint, I'd suggest looking at writing
for y, suit in enumerate(suits)
and changing the index of images[x].

Good luck!

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


[Tutor] ANN: Rur-ple 0.95 has been released

2006-01-30 Thread Andre Roberge
RUR-PLE 0.95 has been released.

A link to the download page can be found at
http://rur-ple.sourceforge.net

(The site is slightly out of date, and there is no plan to update it
in the future as it provides an excellent idea of what RUR-PLE is about.)

This new version contains a few bug fixes and it should now work properly
on MacOS. wxPython 2.6+ is strongly recommmended.
There has been a few minor changes in the robot instructions, and the
lessons has undergone some major changes.

RUR-PLE stands for Roberge's Used Robot: a Python Learning Environment.

This learning environment contains four main elements:

1. A simple html browser to look at the documentation and, potentially,
the lessons.  However, the new lessons use cascading style sheets which
cannot be interpreted correctly by the browser.  Usage of an external
browser (Firefox :-) is strongly recommended.
2. A robot world with a robot that can accomplish tasks through Python
programs.
3. A built-in interpreter which can be used to play with Python
4. A built-in file editor which can be used for futher Python explorations.

The interface is available in English, French and Spanish.  Translations
are welcome!

Version 0.95 contains 36 complete lessons (English version only).
The lessons are also available as a separate download.

Version 1.0, which will aim to be a complete Python tutorial for
people that have never programmed before, should have approximately
50 lessons.

A few bonus lessons have been included.  In particular, it is
suggested that you have a look at A Robotic Fairy Tale.


=
In 1981, Richard Pattis introduced Karel the Robot
as a tool to teach computer programming.
Reeborg is a robot built on the 1981 Pattis' model...
and it is starting to show its age.
It has an oil leak, which allows us to follow its trail.
Its compass is broken; it only knows if it is
facing north or not, unlike Karel who could
determine its orientation with respect to all four cardinal points.

Pattis' Karel the Robot was named after the author Karel Capek,
who popularized the word robot in his play
Rossum's Universal Robots (RUR).
While RUR-PLE shares the basic RUR acronym,
in this case it stands for Roberge's Used Robot.
However, through the magic of Guido van Rossum's Python,
you can learn how to fix it and design a better one,
worthy of the name Rossum's Universal Robot.


If you've read this far... Version 0.95 contains a new feature, which has
been made available as a separate download: lightning.py
This is a cross between a Python editor and a Python interpreter.
Just enter a script in the Editor window, press run, and you
get the result in the output window.  It handles input() and raw_input()
through dialogs.  I like it so much, that I submitted a simplified version
to the online Python cookbook.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ANN: Rur-ple lessons 0.36

2006-01-29 Thread Andre Roberge
Announcing RUR-PLE lessons 0.36

RUR-PLE stands for Roberge's Used Robot: a Python Learning Environment.

This is the first official release of the lessons, separately
from the application.  The lessons are intended as a somewhat
non-typical introduction to programming using Python, that has
been used for other languages (just google Karel Robot for
some examples).  The version number (0.36) indicates that
36 complete lessons (plus a few more incomplete ones) are included.
The complete introduction to Python (version 1.0) will
probably include 50 lessons in total.

This version contains more than 50% more material than
what is included in the latest rur-ple release on sourceforge.

A link to the download page can be found at
http://rur-ple.sourceforge.net

=
In 1981, Richard Pattis introduced Karel the Robot
as a tool to teach computer programming.
Reeborg is a robot built on the 1981 Pattis' model...
and it is starting to show its age.
It has an oil leak, which allows us to follow its trail.
Its compass is broken; it only knows if it is
facing north or not, unlike Karel who could
determine its orientation with respect to all four cardinal points.

Pattis' Karel the Robot was named after the author Karel Capek,
who popularized the word robot in his play
Rossum's Universal Robots (RUR).
While RUR-PLE shares the basic RUR acronym,
in this case it stands for Roberge's Used Robot.
However, through the magic of Guido van Rossum's Python,
you can learn how to fix it and design a better one,
worthy of the name Rossum's Universal Robot.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Off-topic query for rur-ple users

2006-01-28 Thread Andre Roberge
Please, accept my apologies to bring this slightly off-topic question.
 This is the only way I know to reach RUR-PLE users.

How important is it to have a browser included within rur-ple itself? 
Would there be any objections in eliminating the browser, and using
your favourite browser (firefox, etc.) to read the lessons in a
separate window?

You may want to send your reply directly to me (return address should
be part of the message; if not: andre dot roberge at gmail dot com) so
as to not pollute induly this list.

Thanks,

André

P.S.  Just a note about the fact that this is not *completely*
off-topic for this list:
the PLE in RUR-PLE stands for Python Learning Environment.  It is
designed for learning Python for people that don't know anything about
programming (hence the post to the python-tutor list).  It has been
used by some teachers in a classroom environment (hence the post to
the edu-sig list).  It has been very strongly inspired by Guido van
Robot (hence the post to the gvr-devel list) and has served as the
basis of the world-builder module now included with GvR.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] imbedding python into another program?

2005-08-04 Thread Andre Roberge
On 8/3/05, Jeff Peery [EMAIL PROTECTED] wrote:
 Andre, thanks for the help with this. I put it to work yesterday and it
 works perfectly. 
   
 was wondering if it is possible to import modules without a users having to
 type 'import whatever'. for example in my application I would like the user
 to just start operating on arrays that exist in my program. But I have to
 load both the arrays and Numeric into the python shell that I created. how
 can I do this? thanks.
 
 André Roberge [EMAIL PROTECTED] wrote: 
 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)
 

Just use push.

Here's how I did a similar automatic import in that same program:
win = py.shell.Shell(self.window, -1,
introText = tr.INTERPRETER_INTRO_TEXT)
cmd = from __future__ import division   # so that 1/2 = 0.5
[irrelevant stuff deleted]
win.push(cmd)

HTH,

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 Andre Roberge
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).

I struggled to find the right name.  Initially, I called the robot
Cleese (because of his funny walk in addition to the Monty Python
reference) but that didn't seem right, given the intended audience. 
Then, I chose the reverse of my last name (which you caught, I hope,
the last mention of it).  My spouse suggested an anagram of my name
instead.  This, I assume, led to the following comment on
comp.lang.python:

Surrender to Python - Resistance is futile! 

I like that :-)

André

  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