Re: [Tutor] [tutor] Comparing two images using PIL

2008-01-16 Thread Kent Johnson
Varsha Purohit wrote:
> Hello Everyone,
> I have an application where i am comparing two images(jpg) which 
> are almost identical but have little difference. I wanted to mark the 
> difference with a different colour to highlight the region which is 
> different from 1st image. Can you tell me if there is any image funciton 
> in PIL which will help me to calculate the differences between two 
> different JPEG images.

The ImageChops and ImageMath modules look like they might be helpful.

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


[Tutor] [tutor] Comparing two images using PIL

2008-01-16 Thread Varsha Purohit
Hello Everyone,
I have an application where i am comparing two images(jpg) which are
almost identical but have little difference. I wanted to mark the difference
with a different colour to highlight the region which is different from 1st
image. Can you tell me if there is any image funciton in PIL which will help
me to calculate the differences between two different JPEG images.

-- 
Varsha Purohit,
Graduate Student
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
> Any takers? Eric on the mac side? Some other windows user on the
> windows side? I guarantee OLPC will be running on your computer by the
> end of this.

I'll give this a shot this Saturday – I ought to be an ideal test  
candidate since I'm more or less an installation/configuration idjit.  
I'll let you know how it goes. Will it conflict with an existing pyGTK  
installation?

Both Snakes and Ladders and the pipelines thing sound potentially  
interesting, I'll get back to you guys in a couple days...

Thanks!
Eric


>
>
>   --Michael
>
> On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
>> I'm on a Mac, and it seems the current advice for Sugar emulation on
>> the Mac is "come back next year, or the year after"... I did get  
>> PyGTK
>> working, tho.
>>
>>
>> On Jan 16, 2008, at 10:13 PM, Michael Langford wrote:
>>
>>> No, but this is quite useful for getting it up and going on your PC:
>>> http://wiki.laptop.org/go/OS_images_for_emulation
>>>
>>> I was looking at Metropolis (the non-TM version of SimCity) as its  
>>> gui
>>> is all written in python
>>>
>>> --Michael
>>>
>>>
>>>
>>> On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
 Hey, on this topic, I spent some time this afternoon googling the  
 One
 Laptop Per Child (OLPC) project (the GUI is done with Python and
 PyGTK), to see if there were any collaborative open-source  
 projects I
 could contribute to. Seems like a perfect opportunity to get a  
 little
 more Python experience and actually do something useful. I found  
 lots
 of noble exhortations to help, but very little in the way of
 specifics. Does anyone know of any ongoing projects that could use
 volunteers? Of the middling-capable range?

 Eric

 On Jan 16, 2008, at 9:29 PM, Michael Langford wrote:

> There are programming contests you can enter. I don't know of any
> more
> still running past these two (but would love to hear of more):
>
> Sphere Online Judge:
> http://www.spoj.pl/problems/classical/
>
> Topcoder's Development Contests:
> http://www.topcoder.com/tc?module=ViewActiveContests&ph=113
>
> --Michael
>
>
> On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
>> I've been over google for hours now, and I'm sort of at a lull in
>> my
>> learning, as I don't really have a current "goal". I know I could
>> set some
>> easy goal like to learn a specific function or feature, but I  
>> still
>> have a
>> hard time with that approach also. I was wondering if anyone  
>> knows
>> of any
>> sites where people might request "projects" almost like  
>> rentacoder,
>> but for
>> free stuff and/or just for fun. Almost an 'It would be nice if I
>> had a
>> program that did this.. " type of thing to give me some  
>> direction.
>> Or does
>> anyone else have any ideas for some types of programs that might
>> actually
>> prove useful to people for beginners to work on?
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.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

>>>
>>>
>>> --
>>> Michael Langford
>>> Phone: 404-386-0495
>>> Consulting: http://www.RowdyLabs.com
>>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> -- 
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.com
>

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


Re: [Tutor] Program Specification Request

2008-01-16 Thread Alan Gauld

"johnf" <[EMAIL PROTECTED]> wrote

> > Coming from Scotland I have no idea what that means!
>
> What no Girl Scout cookies in Scotland???:-)

Well we have girls and we have scouts and we have girls
who are in the scouts equivalent for girls - the brownies.
Brownies are a kind of cookie aren't they?

Is that the same thing? ;-)

Alan G


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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Kent Johnson
Michael Langford wrote:

> To run OLPC on mac, you need qemu for mac:
> http://www.kju-app.org/kju/

This gets the main page for Q, a native Mac port of qemu. I downloaded 
the stable build.

> Download the latest (.img.bz2) file from:
> http://xs-dev.laptop.org/cscott/olpc/streams/ship.2/latest/devel_ext3/

olpc-redhat-stream-ship.2-build-656-20080102_1619-devel_ext3.img.bz2
or
olpc-redhat-stream-ship.2-devel_ext3.img.bz2
? I got the first

> Unzip it using bzcat (which you mac guys get via Fink if its not
> natively available or you can't unzip some other way). Unzip it to a
> file called olpc.img
> 
> bzcat whatevertheycalledthe.bz2.img > olpc.img

I used BOMArchiveHelper which seems to be included with Mac OS X 10.4 
and (as Archive Utility) 10.5.

> Then you run it the same way the linux people do:
> qemu -redir tcp:2211::22 -soundhw es1370 -net user -net
> nic,model=rtl8139 -hda olpc.img

This is a bit of a mystery as there is no obvious command line for Q.
 From the qemu docs I find
`-redir [tcp|udp]:host-port:[guest-host]:guest-port'
 When using the user mode network stack, redirect incoming TCP or 
UDP connections to the host port host-port to the guest guest-host on 
guest port guest-port.
-redir tcp:2211::22 seems to correspond most closely to enabling Remote 
Login in the Network preferences though that maps port 2200 to port 22.

-soundhw es1370 I guess means to enable ENSONIQ AudioPCI ES 1370 in the 
Hardware prefs.

-net user ?? can't find a setting for this

  -net nic,model=rtl8139
Set Network card to rtl8139 PCI network adapter in Hardware prefs

-hda olpc.img
Choose the downloaded disk image in Hard disk popup in Hardware pref.

Click the start button, it is booting...

OK, seems to more or less work. It's very slow on my Mac (2.33 GHz Intel 
core 2 duo) and pretty buggy, though I have no way of knowing if that is 
the emulator or the OLPC software. Lots of screen refresh problems. The 
mouse is too sensitive, don't see a way to adjust that offhand.

Ah, looking again at the prefs I see there is a box for "QEMU Arguments" 
in the Advanced panel. No time to try it now though. I guess I'm getting 
pretty far off-topic too :-)

Kent

> If I get someone to test my instructions, I'll happily update the OLPC
> emulation page for Windows and Mac OS X.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program Specification Request

2008-01-16 Thread johnf
On Wednesday 16 January 2008 02:44:25 pm Alan Gauld wrote:
> >   It is, almost, (19 January 2008)GS cookie time in
> > CA.
>
> Coming from Scotland I have no idea what that means!

What no Girl Scout cookies in Scotland???:-)

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


Re: [Tutor] Program Specification Request

2008-01-16 Thread Alan Gauld

"Roger Maxwell" <[EMAIL PROTECTED]> wrote 

>   I would like to learn and teach my 2 girls a mini
> database GUI program in Python and 

Since sqlite is included in the standard distribution 
of Pythn 2.5 you might as well use that. It is easy to administer 
and uses a simplified version of standard SQL.

>   It is, almost, (19 January 2008)GS cookie time in
> CA.

Coming from Scotland I have no idea what that means! :-)

>   Q01:  Is this a 'reasonable' first project?

Maybe but as someone else said a command line 
version first will be easier, GUIs are slightly arcane 
in Python due to the lack of a good visual GUI builder.

>   Q02:  We can use either MAC or WinXP but which? Or
> both?

Either or both Python is very portable.

>   Q03:  Is this the appropriate forum?

Yes

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] Program Specification Request

2008-01-16 Thread R. Alan Monroe

>I would like to learn and teach my 2 girls a mini
> database GUI program in Python and 
>They are Girl Scouts (and advanced MS & HS
> students)

http://davidbau.com/archives/2005/07/29/haaarg_world.html

Alan

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


Re: [Tutor] Program Specification Request

2008-01-16 Thread bhaaluu
Greetings,

Take a look at this page:

http://davidbau.com/python/learning.html

and also this one (by the same programmer):

http://davidbau.com/archives/2005/07/29/haaarg_world.html

Not only are these interesting reads, but also give a glimpse
into what it takes to teach kids computer programming using
the Python Programming language.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html


On Jan 16, 2008 1:12 PM, Roger Maxwell <[EMAIL PROTECTED]> wrote:
> Hi all:
>1st post! Have been lurker 4 some time. Thanks to
> all.
>I am new to Python and a former DOS Clipper
> programmer.
>I would like to learn and teach my 2 girls a mini
> database GUI program in Python and 
>They are Girl Scouts (and advanced MS & HS
> students)
>It is, almost, (19 January 2008)GS cookie time in
> CA.
>S.
>
>Question(s):
>Q01:  Is this a 'reasonable' first project?
>Q02:  We can use either MAC or WinXP but which? Or
> both?
>Q03:  Is this the appropriate forum?
>
> thanx.
>
>
>   
> 
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.  
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
> ___
> 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] Program Specification Request

2008-01-16 Thread Ben Bartrum
>Question(s):
>Q01:  Is this a 'reasonable' first project?

Yes.  But I'd say do it in 2 phases.  First do a command-line version, then do 
the GUI.

>Q02:  We can use either MAC or WinXP but which? Or both?

It realy doesn't matter

>Q03:  Is this the appropriate forum?

Yes


GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most 
webmails
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Program Specification Request

2008-01-16 Thread Roger Maxwell
Hi all:
   1st post! Have been lurker 4 some time. Thanks to
all.
   I am new to Python and a former DOS Clipper
programmer.
   I would like to learn and teach my 2 girls a mini
database GUI program in Python and 
   They are Girl Scouts (and advanced MS & HS
students)
   It is, almost, (19 January 2008)GS cookie time in
CA.
   S.
   
   Question(s):
   Q01:  Is this a 'reasonable' first project?
   Q02:  We can use either MAC or WinXP but which? Or
both?
   Q03:  Is this the appropriate forum?

thanx.


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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


[Tutor] Pycron - Does anyone have experience with this?

2008-01-16 Thread Garry Bettle
Howdy all,

Hope this finds everyone well - roll on the weekend.

I've been using pycron for months now with no trouble at all.

It's a great scheduling program.

I'm now trying to schedule a file copy from a network share.

However, Pycron chokes, as it requires the share to fully qualified.

Instead of:

s:\subdir1\subdir2\file.ext

it wants:

\\servername\share\subdir1\subdir2\file.ext

But no matter how I try to do the file copy - batch file, WSH and
Win32API calls - it still refuses to run.

It seems a shame to have to look for another scheduling solution.

Can anyone help?

Many thanks!

Cheers,

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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread bob gailer
Yet one more offering: en.wikipedia.org/wiki/Python_Pipelines

This is my project - and a way you could help is:

I'd give you the specification of a "stage" and you'd develop a python 
function or class that would implement that stage. The first stages 
would be fairly simple, then things would get more involved.

I'd give you a testing framework in which to test a stage.

So the task would look like:

Specification of stage "foo": print the length of the input and if the 
length is less that 10 send the input to the output.

The simplest solution you could code is:

def run(input, output, spec=None):
print len(input) # input is a character string of arbitrary length
if len(input) < 10:
output(input) # output is a function that sends its argument to 
"the output".

Then you'd test it thusly:

import pipetest
pipetest.test("Short")
pipetest.test("Longer than 10")

Running the above should display:

5
Short
14

Is that clear? Is that interesting? There are a lot of stages to be 
developed; many of them are much more complex, so this could provide for 
a step-by-step evolution of your skills.

Let me know one way or the other or ask clarifying questions.

Bob Gailer


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


Re: [Tutor] A faster x in S

2008-01-16 Thread Dinesh B Vadhia
I used the s.intersection(t) function in the set type as it was the most 
appropriate.  The performance was phenomenal.  Thank-you!

Dinesh


- Original Message - 
From: bob gailer 
To: Dinesh B Vadhia 
Cc: tutor@python.org 
Sent: Tuesday, January 15, 2008 2:03 PM
Subject: Re: [Tutor] A faster x in S


Dinesh B Vadhia wrote:
> For some significant data pre-processing we have to perform the 
> following simple process:
>  
> Is the integer x in a list of 13K sorted integers.  That's it except 
> this has to be done >100m times with different x's (multiple times).  
> Yep, a real pain! 
>  
> I've put the 13K integers in a list S and am using the is 'x in S' 
> function.
>  
> I was wondering if there is anything faster?
I agree with Kent.

 >>> l = range(13000)
 >>> s=set(l)
 >>> d=dict(enumerate(l))
 >>> import time
 >>> def f(lookupVal, times, values):
.. st=time.time()
.. for i in range(times):
.. z = lookupVal in values
.. return time.time()-st   
 >>> f(6499,1000,l)
0.3126376037598
 >>> f(6499,100,s)
0.3123623962402

So set is 1000 times faster than list!

 >>> f(6499,100,d)
0.31300020217895508

And dict is (as expected) about the same as set.

So 100,000,000 lookups should take about 30 seconds. Not bad, eh?

Let's explore another angle. What range are the integers in (min and max)?

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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread James Newton
Eric Abrahamsen wrote
> I spent some time this afternoon googling the One Laptop Per Child
> (OLPC) project (the GUI is done with Python and PyGTK), to see if 
> there were any collaborative open-source projects I could contribute 
> to. Seems like a perfect opportunity to get a little more Python 
> experience and actually do something useful. I found lots of noble 
> exhortations to help, but very little in the way of specifics. Does 
> anyone know of any ongoing projects that could use volunteers? Of the 
> middling-capable range?

Hi Eric,

I've got a project that I could use help on :-)

I'm a long-time game developer, but a newbie to Python.  I'm currently
working on a Snakes and Ladders game, as I see this as a good way for
young children to learn:

* Putting numbers in the right order
* Associating a value with the name of a number
* fFamiliarity with written numbers
* Taking turns
* ... and a whole range of concepts associated with numeracy.

You can find my latest build at:
  .


Things that need to be done:

* Distribute counters evenly if there are more than one on
  the same square
* Set up a multi-user environment, so that players can join
  a game hosted on a different machine
* Provide a system for selecting the voice-over language
  and other preferences
* Tweak the game play
* Ensure that the activity is as miserly with CPU-time and
  disk space as possible
* ...

Nice to have:
* Allow users to select their own graphics (created in a
  different activity) for the background, dice and counters
* Add an arrow or a pointing finger to indicate which
  square to click on next
* Advanced mode using:
  - two dice
  - drag and drop to move the counter to its final square
* Choice of writing system for the numbers
* ...

I've just received a couple of XO machines from the Give One Get One
initiative, and am currently looking into getting the game to run on the
laptop.

I have a number of other game ideas that I want to bring to the XO:

* Matching images (more flexible than the built-in Memorize game)
* Drawing Letters
* Abacus Shapes
* Black boxes (a game to develop mental imagery)
* Picture Book Reader

I also have plans for an activity that helps children to understand
musical notation, without having to learn the theory or the practice
first.  But that is currently way out of my depth, as far as my Python
abilities are concerned. 

I'm based in Ottawa, Canada.

Do Snakes and Ladders (or any of the other ideas) inspire you?

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


Re: [Tutor] Reading Input Data

2008-01-16 Thread lechtlr
  Thank you all for your suggestions.
The purpose of this script to read values for initialization of a class 
that calls functions from another software program for chemically reacting 
flows (www.cantera.org). I have around 25 input variables with distinct 
variable names (don’t follow any patterns) with 5 strings (i.e., last five 
variables that contain chemical species names). Currently, I use a csv file to 
provide the initial values.  I hope this answers your questions.
  Lex

Michael Langford <[EMAIL PROTECTED]> wrote: I'd like to be clear, this isn't a 
clean thing for the middle of a big
program. I was thinking the entire time I was testing it "I wonder why
anyone would need to do this"

But if you have a python program you'd probably call a script, used
for one simple task, it can be appropriate (with Kent's catch on the
globals/local thing). I assumed you were using your approach for
something like that. (would you tell us what you're doing this for
btw? The suspense ... :o))

If you're doing something like multivariable analysis or something
else that you would do in software like maple, this approach can
greatly simplify the notation over the list/dict approach.

If you're not using python as a huge substitute for a math solver,
then avoid what I said like the plague and use a dict.

  --Michael

On 1/15/08, Michael Langford  wrote:
> Accidentally cut off a 0 there...
> Think about using ConfigParser instead of your csv. Doug Hellman wrote
> a good article on that:
> http://blog.doughellmann.com/2007/04/pymotw-configparser.html
>
> But if you really want to load your data this way, this will work:
>
> for subscript,line in enumerate(file("file.csv")):
>  s = line.split(",")[1]
>  try:
>  f = float(s)
>  locals()["x%i" % subscript]=f
>  except:
>  locals()["x%i" % subscript]=s
>
> print x1
> print x0
>
> On Jan 15, 2008 3:47 PM, Michael Langford  wrote:
> > for subscript,line in enumerate(file("file.csv")):
> >  s = line.split(",")[1]
> >  try:
> >  f = float(s)
> >  locals()["x%i" % subscript]=f
> >  except:
> >  locals()["x%i" % subscript]=s
> >
> > print x1
> > print x
> >
> > On Jan 15, 2008 3:26 PM, lechtlr  wrote:
> >
> > > I want to read an input file (file.csv) that has two columns. I want to 
> > > read
> > > 2nd column and assign variables that are strings and floats. Currently, I
> > > use the following split() function to read from the input file and create 
> > > a
> > > list, and then assign each element to a variable.
> > >
> > > I am wondering there is any other easier (and elegant) way of doing this ?
> > >
> > > data = []
> > > for line in open("file.csv"):
> > >  columns = line.split(',')
> > >  data.append([columns[1]])
> > >
> > > This script returns, say:
> > > data = [ ['20.0'], ['0.34'], ,[ 'a:0.20, b:0.30, c:0.50' 
> > > ]]
> > >
> > > Then, I assign to a set of variables, say:
> > >
> > > x1 = float(data[0][0]) ; x2 = float(data[1][0]);.;xn =
> > > data[-1][0]
> > >
> > >
> > > Thanks,
> > > Lex
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >  
> > > Never miss a thing. Make Yahoo your homepage.
> >
> > > ___
> > > Tutor maillist  -  Tutor@python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> > >
> >
> >
> >
> > --
> > Michael Langford
> > Phone: 404-386-0495
> > Consulting: http://www.RowdyLabs.com
> >
>
>
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.com
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com


   
-
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Michael Langford
First off OLPC still needs help with:
http://wiki.laptop.org/go/Journal
http://wiki.laptop.org/go/Bitfrost
http://wiki.laptop.org/go/School_Server

Secondly: To start playing with python on the OLPC, click pippy the python :o)

Lastly, you can emulate the build on most computers, Mac/Win/Linux:
Qemu is cross platform.  And OLPC is cool to mess around with for
python people. Its like what windows would be if all of the API's were
in python (and they were made simple enough a child could use it).

To run OLPC on mac, you need qemu for mac:
http://www.kju-app.org/kju/

For you windows people:
http://www.h7.dion.ne.jp/~qemu-win/
and
http://www.davereyn.co.uk/qem/source.zip for the nice GUI

For you linux people:
Well, you probably get if from your package manager

Download the latest (.img.bz2) file from:
http://xs-dev.laptop.org/cscott/olpc/streams/ship.2/latest/devel_ext3/

Unzip it using bzcat (which you mac guys get via Fink if its not
natively available or you can't unzip some other way). Unzip it to a
file called olpc.img

bzcat whatevertheycalledthe.bz2.img > olpc.img

Then you run it the same way the linux people do:
qemu -redir tcp:2211::22 -soundhw es1370 -net user -net
nic,model=rtl8139 -hda olpc.img

If you're in windows, use the command line inside the launcher or on
the command line.

(The command line stuff is about stuff inside the emulator, not about
your setup).

If I get someone to test my instructions, I'll happily update the OLPC
emulation page for Windows and Mac OS X.

Any takers? Eric on the mac side? Some other windows user on the
windows side? I guarantee OLPC will be running on your computer by the
end of this.

   --Michael

On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> I'm on a Mac, and it seems the current advice for Sugar emulation on
> the Mac is "come back next year, or the year after"... I did get PyGTK
> working, tho.
>
>
> On Jan 16, 2008, at 10:13 PM, Michael Langford wrote:
>
> > No, but this is quite useful for getting it up and going on your PC:
> > http://wiki.laptop.org/go/OS_images_for_emulation
> >
> > I was looking at Metropolis (the non-TM version of SimCity) as its gui
> > is all written in python
> >
> >  --Michael
> >
> >
> >
> > On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> >> Hey, on this topic, I spent some time this afternoon googling the One
> >> Laptop Per Child (OLPC) project (the GUI is done with Python and
> >> PyGTK), to see if there were any collaborative open-source projects I
> >> could contribute to. Seems like a perfect opportunity to get a little
> >> more Python experience and actually do something useful. I found lots
> >> of noble exhortations to help, but very little in the way of
> >> specifics. Does anyone know of any ongoing projects that could use
> >> volunteers? Of the middling-capable range?
> >>
> >> Eric
> >>
> >> On Jan 16, 2008, at 9:29 PM, Michael Langford wrote:
> >>
> >>> There are programming contests you can enter. I don't know of any
> >>> more
> >>> still running past these two (but would love to hear of more):
> >>>
> >>> Sphere Online Judge:
> >>> http://www.spoj.pl/problems/classical/
> >>>
> >>> Topcoder's Development Contests:
> >>> http://www.topcoder.com/tc?module=ViewActiveContests&ph=113
> >>>
> >>>  --Michael
> >>>
> >>>
> >>> On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
>  I've been over google for hours now, and I'm sort of at a lull in
>  my
>  learning, as I don't really have a current "goal". I know I could
>  set some
>  easy goal like to learn a specific function or feature, but I still
>  have a
>  hard time with that approach also. I was wondering if anyone knows
>  of any
>  sites where people might request "projects" almost like rentacoder,
>  but for
>  free stuff and/or just for fun. Almost an 'It would be nice if I
>  had a
>  program that did this.. " type of thing to give me some direction.
>  Or does
>  anyone else have any ideas for some types of programs that might
>  actually
>  prove useful to people for beginners to work on?
> 
>  ___
>  Tutor maillist  -  Tutor@python.org
>  http://mail.python.org/mailman/listinfo/tutor
> 
> 
> >>>
> >>>
> >>> --
> >>> Michael Langford
> >>> Phone: 404-386-0495
> >>> Consulting: http://www.RowdyLabs.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
> >>
> >
> >
> > --
> > Michael Langford
> > Phone: 404-386-0495
> > Consulting: http://www.RowdyLabs.com
> >
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Michael Langford
Phone: 404-386-049

Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Kent Johnson
Fiyawerx wrote:
> I've been over google for hours now, and I'm sort of at a lull in my 
> learning, as I don't really have a current "goal". I know I could set 
> some easy goal like to learn a specific function or feature, but I still 
> have a hard time with that approach also. I was wondering if anyone 
> knows of any sites where people might request "projects" almost like 
> rentacoder, but for free stuff and/or just for fun. Almost an 'It would 
> be nice if I had a program that did this.. " type of thing to give me 
> some direction. Or does anyone else have any ideas for some types of 
> programs that might actually prove useful to people for beginners to 
> work on?

This is a common question here; you might want to look at some previous 
answers:
http://search.gmane.org/?query=project+ideas&group=gmane.comp.python.tutor

You might look for a Python project at Google Code or SourceForge that 
interests you and work on that:
http://code.google.com/hosting/search?q=label%3aPython
http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=python

If you are in high school you might like to participate in the Google 
Highly Open Participation Contest:
http://code.google.com/p/google-highly-open-participation-psf/

Even if you are not in high school, the list of GHOP Python tasks shows 
you some projects that are actively looking for help:
http://code.google.com/p/google-highly-open-participation-psf/issues/list

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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
I'm on a Mac, and it seems the current advice for Sugar emulation on  
the Mac is "come back next year, or the year after"... I did get PyGTK  
working, tho.


On Jan 16, 2008, at 10:13 PM, Michael Langford wrote:

> No, but this is quite useful for getting it up and going on your PC:
> http://wiki.laptop.org/go/OS_images_for_emulation
>
> I was looking at Metropolis (the non-TM version of SimCity) as its gui
> is all written in python
>
>  --Michael
>
>
>
> On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
>> Hey, on this topic, I spent some time this afternoon googling the One
>> Laptop Per Child (OLPC) project (the GUI is done with Python and
>> PyGTK), to see if there were any collaborative open-source projects I
>> could contribute to. Seems like a perfect opportunity to get a little
>> more Python experience and actually do something useful. I found lots
>> of noble exhortations to help, but very little in the way of
>> specifics. Does anyone know of any ongoing projects that could use
>> volunteers? Of the middling-capable range?
>>
>> Eric
>>
>> On Jan 16, 2008, at 9:29 PM, Michael Langford wrote:
>>
>>> There are programming contests you can enter. I don't know of any  
>>> more
>>> still running past these two (but would love to hear of more):
>>>
>>> Sphere Online Judge:
>>> http://www.spoj.pl/problems/classical/
>>>
>>> Topcoder's Development Contests:
>>> http://www.topcoder.com/tc?module=ViewActiveContests&ph=113
>>>
>>>  --Michael
>>>
>>>
>>> On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
 I've been over google for hours now, and I'm sort of at a lull in  
 my
 learning, as I don't really have a current "goal". I know I could
 set some
 easy goal like to learn a specific function or feature, but I still
 have a
 hard time with that approach also. I was wondering if anyone knows
 of any
 sites where people might request "projects" almost like rentacoder,
 but for
 free stuff and/or just for fun. Almost an 'It would be nice if I
 had a
 program that did this.. " type of thing to give me some direction.
 Or does
 anyone else have any ideas for some types of programs that might
 actually
 prove useful to people for beginners to work on?

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


>>>
>>>
>>> --
>>> Michael Langford
>>> Phone: 404-386-0495
>>> Consulting: http://www.RowdyLabs.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
>>
>
>
> -- 
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.com
>

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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Noufal Ibrahim
Fiyawerx wrote:
> I've been over google for hours now, and I'm sort of at a lull in my 
> learning, as I don't really have a current "goal". I know I could set 
> some easy goal like to learn a specific function or feature, but I still 
> have a hard time with that approach also. I was wondering if anyone 
> knows of any sites where people might request "projects" almost like 
> rentacoder, but for free stuff and/or just for fun. Almost an 'It would 
> be nice if I had a program that did this.. " type of thing to give me 
> some direction. Or does anyone else have any ideas for some types of 
> programs that might actually prove useful to people for beginners to 
> work on?

You can check out http://projecteuler.net/


-- 
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Michael Langford
No, but this is quite useful for getting it up and going on your PC:
http://wiki.laptop.org/go/OS_images_for_emulation

I was looking at Metropolis (the non-TM version of SimCity) as its gui
is all written in python

  --Michael



On 1/16/08, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> Hey, on this topic, I spent some time this afternoon googling the One
> Laptop Per Child (OLPC) project (the GUI is done with Python and
> PyGTK), to see if there were any collaborative open-source projects I
> could contribute to. Seems like a perfect opportunity to get a little
> more Python experience and actually do something useful. I found lots
> of noble exhortations to help, but very little in the way of
> specifics. Does anyone know of any ongoing projects that could use
> volunteers? Of the middling-capable range?
>
> Eric
>
> On Jan 16, 2008, at 9:29 PM, Michael Langford wrote:
>
> > There are programming contests you can enter. I don't know of any more
> > still running past these two (but would love to hear of more):
> >
> > Sphere Online Judge:
> > http://www.spoj.pl/problems/classical/
> >
> > Topcoder's Development Contests:
> > http://www.topcoder.com/tc?module=ViewActiveContests&ph=113
> >
> >   --Michael
> >
> >
> > On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
> >> I've been over google for hours now, and I'm sort of at a lull in my
> >> learning, as I don't really have a current "goal". I know I could
> >> set some
> >> easy goal like to learn a specific function or feature, but I still
> >> have a
> >> hard time with that approach also. I was wondering if anyone knows
> >> of any
> >> sites where people might request "projects" almost like rentacoder,
> >> but for
> >> free stuff and/or just for fun. Almost an 'It would be nice if I
> >> had a
> >> program that did this.. " type of thing to give me some direction.
> >> Or does
> >> anyone else have any ideas for some types of programs that might
> >> actually
> >> prove useful to people for beginners to work on?
> >>
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >>
> >
> >
> > --
> > Michael Langford
> > Phone: 404-386-0495
> > Consulting: http://www.RowdyLabs.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
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Eric Abrahamsen
Hey, on this topic, I spent some time this afternoon googling the One  
Laptop Per Child (OLPC) project (the GUI is done with Python and  
PyGTK), to see if there were any collaborative open-source projects I  
could contribute to. Seems like a perfect opportunity to get a little  
more Python experience and actually do something useful. I found lots  
of noble exhortations to help, but very little in the way of  
specifics. Does anyone know of any ongoing projects that could use  
volunteers? Of the middling-capable range?

Eric

On Jan 16, 2008, at 9:29 PM, Michael Langford wrote:

> There are programming contests you can enter. I don't know of any more
> still running past these two (but would love to hear of more):
>
> Sphere Online Judge:
> http://www.spoj.pl/problems/classical/
>
> Topcoder's Development Contests:
> http://www.topcoder.com/tc?module=ViewActiveContests&ph=113
>
>   --Michael
>
>
> On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
>> I've been over google for hours now, and I'm sort of at a lull in my
>> learning, as I don't really have a current "goal". I know I could  
>> set some
>> easy goal like to learn a specific function or feature, but I still  
>> have a
>> hard time with that approach also. I was wondering if anyone knows  
>> of any
>> sites where people might request "projects" almost like rentacoder,  
>> but for
>> free stuff and/or just for fun. Almost an 'It would be nice if I  
>> had a
>> program that did this.. " type of thing to give me some direction.  
>> Or does
>> anyone else have any ideas for some types of programs that might  
>> actually
>> prove useful to people for beginners to work on?
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> -- 
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.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] parsing html.

2008-01-16 Thread Paul McGuire
Here is a pyparsing approach to your question.  I've added some comments to
walk you through the various steps.  By using pyparsing's makeHTMLTags
helper method, it is easy to write short programs to skim selected data tags
from out of an HTML page.

-- Paul


from pyparsing import makeHTMLTags, SkipTo

html = """
Table of Contents
.
Preface
"""

# define the pattern to search for, using pyparsing makeHTMLTags helper
# makeHTMLTags constructs a very tolerant mini-pattern, to match HTML
# tags with the given tag name:
# - caseless matching on the tag name
# - embedded whitespace is handled
# - detection of empty tags (opening tags that end in "/")
# - detection of tag attributes
# - returning parsed data using results names for attribute values
# makeHTMLTags actually returns two patterns, one for the opening tag
# and one for the closing tag
aStart,aEnd = makeHTMLTags("A")
bStart,bEnd = makeHTMLTags("B")
pattern = aStart + aEnd + bStart + SkipTo(bEnd)("text") + bEnd

# search the input string - dump matched structure for each match
for pp in pattern.searchString(html):
print pp.dump()
print pp.startA.name, pp.text

# parse input and build a dict using the results
nameDict = dict( (pp.startA.name,pp.text) for pp in
pattern.searchString(html) )
print nameDict


The last line of the output is the dict that is created:

{'5': 'Preface', '4': 'Table of Contents'}




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


Re: [Tutor] Programming Ideas, need some focus

2008-01-16 Thread Michael Langford
There are programming contests you can enter. I don't know of any more
still running past these two (but would love to hear of more):

Sphere Online Judge:
http://www.spoj.pl/problems/classical/

Topcoder's Development Contests:
http://www.topcoder.com/tc?module=ViewActiveContests&ph=113

   --Michael


On 1/16/08, Fiyawerx <[EMAIL PROTECTED]> wrote:
> I've been over google for hours now, and I'm sort of at a lull in my
> learning, as I don't really have a current "goal". I know I could set some
> easy goal like to learn a specific function or feature, but I still have a
> hard time with that approach also. I was wondering if anyone knows of any
> sites where people might request "projects" almost like rentacoder, but for
> free stuff and/or just for fun. Almost an 'It would be nice if I had a
> program that did this.. " type of thing to give me some direction. Or does
> anyone else have any ideas for some types of programs that might actually
> prove useful to people for beginners to work on?
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help, thanks very much.

2008-01-16 Thread Kent Johnson
bill.wu wrote:
>  
> i am new guy.
> i ask a easy question.

There is no need to ask twice.

Please post messages in plain-text, not HTML.

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


Re: [Tutor] parsing html.

2008-01-16 Thread Kent Johnson
Shriphani Palakodety wrote:
> Hello,
> I have a html document here which goes like this:
> 
> Table of Contents
> .
> Preface
> 
> Can someone tell me how I can get the string between the  tag for
> an a tag for a given value of the name attribute.

In [30]: from BeautifulSoup import BeautifulSoup
In [31]: text = '''Table of Contents
: .
: Preface'''
In [32]: soup = BeautifulSoup(text)
In [40]: soup.find('a', dict(name='5'))
Out[40]: 
In [41]: soup.find('a', dict(name='5')).next
Out[41]: Preface
In [42]: soup.find('a', dict(name='5')).next.string
Out[42]: u'Preface'

Note BeautifulSoup lower-cases the tag name.
http://www.crummy.com/software/BeautifulSoup/

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


[Tutor] Programming Ideas, need some focus

2008-01-16 Thread Fiyawerx
I've been over google for hours now, and I'm sort of at a lull in my
learning, as I don't really have a current "goal". I know I could set some
easy goal like to learn a specific function or feature, but I still have a
hard time with that approach also. I was wondering if anyone knows of any
sites where people might request "projects" almost like rentacoder, but for
free stuff and/or just for fun. Almost an 'It would be nice if I had a
program that did this.. " type of thing to give me some direction. Or does
anyone else have any ideas for some types of programs that might actually
prove useful to people for beginners to work on?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why Won't My Pizza Fall?

2008-01-16 Thread Alan Gauld

"Tiger12506" <[EMAIL PROTECTED]> wrote>
>> [Background from Alan]
>> ... Thus the context object should respond to some message
>> from Pizza and in this case the Pizza should hold a reference
>> to its context manager(probably a screen or grid of some sort).
>
> [disclaimer]
> This email has particularly strong personal opinions about coding 
> practices.
> I do not wish to personally offend anyone, and if you feel that you 
> have
> been offended as such, or that you disagree, please do not bother 
> emailing
> this list to tell me, excepting that you provide an excellent case 
> promoting
> your views that someone may be able to apply to make their code more
> intuitive/sensible. This email was provided for just such a reason.
> [/disclaimer]

Noted :-)

>> The context manager is responsible for tracking the objects
>> being managed, but the objects remain responsible for
>> managing their own state.
>
> [rant]
> This phrase right here is a dead giveaway to me that Pizza should 
> have
> little control over how it moves. A Pizza must be completely aware 
> of its
> current position (being part of its state) and at the very *most* a 
> set of
> rules governing general falling behaviour. I like the idea of a 
> context
> manager that is perhaps a container for Pizzas that oversees their 
> behavior,
> but I dislike the idea that a Pizza knows specifics about its rules 
> for
> positioning such as collisions or etc. that it has to communicate to 
> the
> context manager and/or other Pizzas.

I'm confused about what you dislike about this. You agree that
the Pizza shouldn't know about other Pizzas and is thus unable
to do its own collision monitoring. But if the Pizza is, as I 
surmised,
a Pizza that falls under its own control as implied by the description
"a Falling Pizza", then without it notifying the context manager 
(screen,
board, collection or whatever) how will the thing that does know
about the context be able to determine whether a collision has
occured - assuming that it needs to.

> Maybe I am becoming too used to lower
> level languages, not fully siding with abstraction.

That's possible :-). OOP was introduced to add abstraction
to lower level concepts and sometimes that abstraction hits
performance and requires extra code at the micro level,
but usually does so by simplifying design at the macro
level. This is one reason that true OOP(as opposed to using
objects) is rarely used on small programs and classes in those
problems tend to be used more as data containers somewhat
like an old fashioned C struct or Pascal record.

> I just see that we have suddenly introduced to new levels
> of redirection to achieve the same result,

Not entirely, by using indirection we have decoupled the class
from the solution thus increased reusability. If you will never
need to reuse a FallingPizza then of course it may be just
as effective to use direct intervention but in doing so you
break one of the fundamental principles of OOP. (And my
comments were explicitly concerned with good OOP style)

> instead of the list changing the elements. Definite benefits for 
> messaging
> models, but this /feels/ akin to filling out tax forms so that the
> government can tell you how you filled them out incorrectly.

The messaging overhead in Python (as in most OOP languages)
is not onerous and if dealing with lots of different Pizza objects
might even save code due to the potential to remove if/elif
constructs by relying on polymorphism. It would be different
if we were talking about setting the objects up in different
processes and communicating via an ORB but in practice
its only a couple of function calls. (Of course if we did later
need to split the objects over proceesses the messaging
solution is much easier to adapt to using an ORB...)

> A similar somewhat questionably connected problem involves my 
> dealings with
> the Render method of the IPicture interface. Sure, you can directly 
> apply
> the picture to the device context or if you like we have a Render 
> method
> that will automatically change the coordinates so that you have to 
> convert
> them back to display it. Abstraction isn't everything.

No, I agree, abstaction isn't everything and occasionally for
performance reasons you need to break down an abstraction layer.
But in my experience I've only had to do that a couple of times.
And Abstraction does give huge benefits. For example in the Picture
example if you follow the protocol approach its trivial to swap device
contexts from screen to printer to terminal to braille panel etc etc.
But rendering by hand will usuially involve completely rewriting the
renderer for each new device. If you know you will only ever have
one device then direct rendering is a valid option.

One of the interesting things about engineering (any branch, not
just software) is that "rules" are there for guidance and engineering
skill and experience tells us when it will be safe to break them.
The smaller and more specific th

Re: [Tutor] parsing html.

2008-01-16 Thread Alan Gauld

"Shriphani Palakodety" <[EMAIL PROTECTED]> wrote in

> I have a html document here which goes like this:
>
> Table of Contents
> .
> Preface
>
> Can someone tell me how I can get the string between the  tag for
> an a tag for a given value of the name attribute.

Heres an example using the standard library HTML parser
(from an unfinished topic in tutorial...). You could also
use BeautifulSoup and I recommend that if your needs get
any more complex...

--
In practice we usually want to extract more specific data from a page, 
maybe the content of a particular row in a table or similar. For that 
we need to use the handle_starttag() and handle_endtag() methods. As 
an example let's extract the text of the second H1 level header:
html = '''
Test page


Here is the first heading

A short paragraph
A second heading
A paragraph containing a
hyperlink to google

'''

from HTMLParser import HTMLParser

class H1Parser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.h1_count = 0
self.isHeading = False

def handle_starttag(self,tag,attributes=None):
if tag == 'h1':
self.h1_count += 1
self.isHeading = True

def handle_endtag(self,tag):
if tag == 'h1':
self.isHeading = False

def handle_data(self,data):
if self.isHeading and self.h1_count == 2:
print "Second Header contained: ", data

parser = H1Parser()
parser.feed(html)
parser.close()
--Hopefully you can see how to alter that 
pattern to suit your scenario.-- Alan GauldAuthor of the Learn to 
Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] help, thanks very much.

2008-01-16 Thread Alan Gauld

"bill.wu" <[EMAIL PROTECTED]> wrote 

> i ask a easy question.
> 
> why the first one have"x",the second one 
> doesn't have "x". what is different? 

The first is using x as the name of a parameter
of the function and is only used inside the function.
The second one takes no parameter and relies on 
explicit knowlege that an variable called x 
exists in the global namespace.

The second form is considered bad practice 
unless you have a very good reason to use it
since it forces the function to know about 
things outside its control.

> when write "x",when don't write "x".

Using a parameter (usually called something 
more meaningful than x!) is normally the best 
way. Version 2 should be avoided if possible.

> in my point,the second one don't def variable.

Corect it uses the global variable defined 
at the module level. That is why the global 
statement is used.

> (1)
> 
> def func(x):
>print 'x is', x
>x = 2
>print 'Changed local x to', x
> 
> x = 50
> func(x)
> print 'x is still', x (2)

This defines a global x with value 50.
It then calls func passing in the value 
50 to the parameter x which acts like a 
local variable, only seen inside the 
function.
The func internally assigns a value 
of 2 to that local x which does not 
affect the global x. It then prints 
the local value and exits
The next line of code then prints 
the global x to show that it has 
not changed.

If a different name had been used for the 
parameter it would be much clearer but 
I assume the author is trying to demonstrate 
how names are controlled.

def func(y):
   print 'y =',y
   y = 2
   print 'y =',y

x = 50
func(x)
print 'x =',x

The code here is identical in function 
to the first version but because we 
chose y as the parameter name it is 
obvious that they are different variables.

> def func():
>global x
> 
>print 'x is', x
>x = 2
>print 'Changed local x to', x

This function has no local variables and 
instead acts on the global x. It could 
be better written with a parameter like this:

def func(y)
print 'y =',y
y = 2
print 'y=',y
return y# allows it to affect the global
 
> x = 50
> func()

And this line becomes

x = func(x)

> print 'Value of x is', x 

Now x will reflect the changes made by func()

You will find more about namespaces in the 
"Whats in a name?" topic of my tutorial.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] Input

2008-01-16 Thread Ricardo Aráoz
Kent Johnson wrote:
> Ricardo Aráoz wrote:
> 
>> _validChars = {
>> 'X' :
>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
>> , '9' : '1234567890'
>> , '-' : '-1234567890'
>> , 'A' :
>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>> , '!' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}
>> _validKeys = _validChars.keys()
> 
> 
>> while maskChar not in _validKeys :
> 
> There is no need to make _validKeys, you can write
>   while maskChar not in _validChars
> which is actually more efficient, in general, because it is a hash table
> lookup instead of searching a list.
> 
> Kent
> 

Thanks Kent, I'll wait to see if there are more corrections and re-post
the corrected code.


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


Re: [Tutor] Input

2008-01-16 Thread Alan Gauld
"Tiger12506" <[EMAIL PROTECTED]> wrote
>> Of course I know and use reg. exps., the point of the function is 
>> not to
>> validate input but to force the proper input.
>
> So? Are you going to try to tell me that you can force particular 
> input
> without actually determining if its valid or not first? ;-)

regex is great for testing strings but the function posted tests
each character as it is input. Using regex you would need to
test the complete string after it was entered before getting
a reliable result.

I think thats the difference.

Alan G.



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


Re: [Tutor] Input

2008-01-16 Thread Ricardo Aráoz
Tiger12506 wrote:
>> Of course I know and use reg. exps., the point of the function is not to
>> validate input but to force the proper input.
> 
> So? Are you going to try to tell me that you can force particular input 
> without actually determining if its valid or not first? ;-)
> 
> Just a thought. 
> 


Are you going to try to tell me that it is better to check if ONE
character is valid with a reg.exp. that with a simple 'in' statement?

The purpose of the code is not to check input but to force it a
character at a time according to an input mask, it's a common enough
concept. Just do a bunch of raw_inputs inscribed in while loops with
their validations, then do it with this function and check the
readability of your code (not to talk about the length). Anyway it was
presented as a help for those who want it and as an exercise program to
be improved and learn from.


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


Re: [Tutor] how to change the values of keyboard keys in TKINTER

2008-01-16 Thread ALAN GAULD
> i dont want to change alt+f4 for every application on the computer 
> permanently...
> i just want to change it a particular area
> do we have any options for this

In that case all you need to do is to bind the key to the same action as the 
Enter key. Enter usually is a default action so you will likely have to work 
out what that ,means in your context but it should not be too hard.

An alternative might be to write a handler that posts a message onto the Tk 
event queue that looks like it comes from the Enter key, this would then get 
picked up by the mainloop and processed as if Enter had been pressed. 
I think Tk does have a way to do this but I can't remember how and 
don't have time to research it just now.

HTH,

Alan G




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