From horses_kayla10 at hotmail.com  Wed Oct  1 04:47:59 2008
From: horses_kayla10 at hotmail.com (kayla bishop)
Date: Tue, 30 Sep 2008 21:47:59 -0500
Subject: [Tutor] (no subject)
Message-ID: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>


I can't figure out how to write a program where you flip a coin 100 times and it keeps track of how many heads and tails you flipped but it has to be random. Can you please help
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080930/9d5c7847/attachment.htm>

From pierre.dagenais at ncf.ca  Wed Oct  1 05:44:46 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Tue, 30 Sep 2008 23:44:46 -0400
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
 file or directory
In-Reply-To: <333efb450809301405m47c52c32t178e8b2e0d65c34e@mail.gmail.com>
References: <48E284D2.7040201@ncf.ca>
	<333efb450809301405m47c52c32t178e8b2e0d65c34e@mail.gmail.com>
Message-ID: <48E2F22E.2080306@ncf.ca>

W W wrote:
> On Tue, Sep 30, 2008 at 2:58 PM, Pierre Dagenais <pierre.dagenais at ncf.ca>wrote:
>
>   
>> The file test.py is in I:\Python25\MyCode,
>> if I enter:
>>
>>  C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works
>> as I would expect.
>>
>> However when I enter the same command from any other directory I get this
>> error:
>>
>>  C:\>python test.py
>>   python: can't open file 'test.py' : [Errno 2] No such file or directory
>>
>> I've set the environment variable pythonpath as
>>  C:\>set pythonpath = C:\\Python25\\MyCode
>>
>>     
>
> I'm not entirely sure about Windows, but my guess is that your problem is
> that the pythonpath isn't what you need to set. I would venture to guess
> that it's searching for test.py in your current path. If I'm correct in my
> thinking, all it does when you set the python path is tells python to
> execute in that directory, so if your script contains something like f =
> open("myfile.txt", "w") it will put it in that directory.
>
> You may want to try this:
>
> The path is now managed by Windows 2000 / Windows XP and not the
> autoexec.bat or autoexec.nt files. To change the system environment
> variables, follow the below steps.
>
>    1. From the desktop <http://www.computerhope.com/jargon/d/desktop.htm>,
>    right-click My Computer and click properties.
>    2. In the System Properties
> window<http://www.computerhope.com/jargon/w/window.htm>,
>    click on the Advanced tab <http://www.computerhope.com/jargon/t/tab.htm>.
>    3. In the Advanced section, click the Environment Variables
> button<http://www.computerhope.com/jargon/p/pushbutt.htm>
>    .
>    4. Finally, in the Environment Variables window, highlight the path
>    variable in the Systems Variable section and click edit. Add or modify the
>    path lines with the paths you wish the computer to access. Each different
>    directory is separated with a semicolon as shown below.
>
>    C:\Program Files;C:\Winnt;C:\Winnt\System32
>
> from:
> http://www.computerhope.com/issues/ch000549.htm
>
> Try adding the path to your code in that way, and see if it works. HTH,
> Wayne
>
>   
Thank you Wayne,
My path does include C:\python25;C\python25\mycode among other things. 
Is that is what you meant?

From pierre.dagenais at ncf.ca  Wed Oct  1 06:01:44 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 00:01:44 -0400
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
 file or directory
In-Reply-To: <e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
References: <48E284D2.7040201@ncf.ca>
	<e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
Message-ID: <48E2F628.1090106@ncf.ca>

Timothy Grant wrote:
> On Tue, Sep 30, 2008 at 12:58 PM, Pierre Dagenais
> <pierre.dagenais at ncf.ca> wrote:
>   
>> The file test.py is in I:\Python25\MyCode,
>> if I enter:
>>
>>  C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works as
>> I would expect.
>>
>> However when I enter the same command from any other directory I get this
>> error:
>>
>>  C:\>python test.py
>>   python: can't open file 'test.py' : [Errno 2] No such file or directory
>>
>> I've set the environment variable pythonpath as
>>  C:\>set pythonpath = C:\\Python25\\MyCode
>> what am I doing wrong,
>> Thank u for your help,
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>     
>
> You need to give the full path to your test.py file.
>
> PYTHONPATH sets the python library search path.
>
>
>   
> Thank you Tim,
> Definitively C:\python \python25\mycode\test.py does work. If you're right about having to give the full path, and I suspect you are, Then this means that python knows to search the currennt working directory for  the file to execute, but nowhere else. It seems a strange behavior. Maybe this is on Mr. Guido van Rossum todo list.
>   

From pierre.dagenais at ncf.ca  Wed Oct  1 06:18:51 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 00:18:51 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
Message-ID: <48E2FA2B.3040701@ncf.ca>

kayla bishop wrote:
> I can't figure out how to write a program where you flip a coin 100 times and it keeps track of how many heads and tails you flipped but it has to be random. Can you please help
> _________________________________________________________________
> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
>   
> ------------------------------------------------------------------------
> Which part are you having a problem with? Flipping the coin or keeping track of the results, or both? Try to be little more explicit please.




From cbabcock at asciiking.com  Wed Oct  1 06:40:31 2008
From: cbabcock at asciiking.com (Chris Babcock)
Date: Tue, 30 Sep 2008 21:40:31 -0700
Subject: [Tutor] Question on DOMImplementation Objects
Message-ID: <20080930214031.60d0ec8f@mail.asciiking.com>

Does the DOMImplementation interface support schemas? 

I'm tweaking an example from a book to process a flat file registration
database:

from xml.dom     import implementation

class RegistrationParser:
  def parseFile(self, fileAsString):

    # Create DocType Declaration
    doctype = implementation.createDocumentType('registrations', '',
                                                'archive.xsd')

    # Create empty DOM Document and get root element
    doc = implementation.createDocument('', 'registrations', doctype)
    elemDoc = doc.documentElement
    
    . . . 


If I leave archive.xsd out of createDocumentType will it just generate
an XML document without validation?

Chris

-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.

From pierre.dagenais at ncf.ca  Wed Oct  1 07:20:53 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 01:20:53 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
Message-ID: <48E308B5.6030405@ncf.ca>

kayla bishop wrote:
> I can't figure out how to write a program where you flip a coin 100 times and it keeps track of how many heads and tails you flipped but it has to be random. Can you please help
> _________________________________________________________________
> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.5/1698 - Release Date: 29/09/2008 7:25 PM
>
>   
Here is how one newbie would do it:


import random

# Initialize variables
head = 0
tail = 0

# Flip the coin a hundred times
for x in range(100):
    choice = random.randint(1,2)
   
# Is it 'head'?
    if choice == 1 :
        head = head + 1
       
# If not 'head' then it must be tail
    else :
        tail = tail + 1
       
print "head = ",head
print "tail = ",tail


   

From tomar.arun at gmail.com  Wed Oct  1 07:26:04 2008
From: tomar.arun at gmail.com (Arun Tomar)
Date: Wed, 01 Oct 2008 10:56:04 +0530
Subject: [Tutor] list to csv
Message-ID: <1222838764.1971.3.camel@terminator.solution.internal>

hi!

I've a list

new_array = ['n1', 'm1', 'p1', 'n2', 'm2', 'p2', 'n3', 'm3', 'p3']

I am trying to convert this to a csv in 3 columns so that the final
output would look something like this

"n1","m1","p1"
"n2","m2","p2"
"n3","m3","p3"

regds,
arun.




From steve at alchemy.com  Wed Oct  1 07:32:19 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Tue, 30 Sep 2008 22:32:19 -0700
Subject: [Tutor] list to csv
In-Reply-To: <1222838764.1971.3.camel@terminator.solution.internal>
References: <1222838764.1971.3.camel@terminator.solution.internal>
Message-ID: <48E30B63.6060904@alchemy.com>

Arun Tomar wrote:
> hi!
> 
> I've a list
> 
> new_array = ['n1', 'm1', 'p1', 'n2', 'm2', 'p2', 'n3', 'm3', 'p3']
> 
> I am trying to convert this to a csv in 3 columns so that the final
> output would look something like this
> 
> "n1","m1","p1"
> "n2","m2","p2"
> "n3","m3","p3"

This can easily be done with the "csv" module in the Python standard 
library.  Just create a csv.writer object, and call the writerow() 
method in it for every three elements in new_array and you're done.

> regds,
> arun.
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From timothy.grant at gmail.com  Wed Oct  1 07:54:25 2008
From: timothy.grant at gmail.com (Timothy Grant)
Date: Tue, 30 Sep 2008 22:54:25 -0700
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
	file or directory
In-Reply-To: <48E2F628.1090106@ncf.ca>
References: <48E284D2.7040201@ncf.ca>
	<e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
	<48E2F628.1090106@ncf.ca>
Message-ID: <e775286d0809302254y139e8a45xc613d88d9f8e0efc@mail.gmail.com>

On Tue, Sep 30, 2008 at 9:01 PM, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:
> Timothy Grant wrote:
>>
>> On Tue, Sep 30, 2008 at 12:58 PM, Pierre Dagenais
>> <pierre.dagenais at ncf.ca> wrote:
>>
>>>
>>> The file test.py is in I:\Python25\MyCode,
>>> if I enter:
>>>
>>>  C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works
>>> as
>>> I would expect.
>>>
>>> However when I enter the same command from any other directory I get this
>>> error:
>>>
>>>  C:\>python test.py
>>>  python: can't open file 'test.py' : [Errno 2] No such file or directory
>>>
>>> I've set the environment variable pythonpath as
>>>  C:\>set pythonpath = C:\\Python25\\MyCode
>>> what am I doing wrong,
>>> Thank u for your help,
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>> You need to give the full path to your test.py file.
>>
>> PYTHONPATH sets the python library search path.
>>
>>
>>  Thank you Tim,
>> Definitively C:\python \python25\mycode\test.py does work. If you're right
>> about having to give the full path, and I suspect you are, Then this means
>> that python knows to search the currennt working directory for  the file to
>> execute, but nowhere else. It seems a strange behavior. Maybe this is on Mr.
>> Guido van Rossum todo list.
>>
>

Why is that strange? Would you expect any other program not on the
path to execute without a fully qualified path? Make your python code
executable, and put it somewhere on the path and I'm quite sure it
would run as expected (though it has been over 10 years since I last
had to work on a Windows box so I'm not quite sure how to do that).

-- 
Stand Fast,
tjg.  [Timothy Grant]

From timothy.grant at gmail.com  Wed Oct  1 08:05:31 2008
From: timothy.grant at gmail.com (Timothy Grant)
Date: Tue, 30 Sep 2008 23:05:31 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <48E308B5.6030405@ncf.ca>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<48E308B5.6030405@ncf.ca>
Message-ID: <e775286d0809302305p6f4d439dk89ef559978454207@mail.gmail.com>

On Tue, Sep 30, 2008 at 10:20 PM, Pierre Dagenais
<pierre.dagenais at ncf.ca> wrote:
> kayla bishop wrote:
>>
>> I can't figure out how to write a program where you flip a coin 100 times
>> and it keeps track of how many heads and tails you flipped but it has to be
>> random. Can you please help
>> _________________________________________________________________
>> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
>>
>> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
>>  ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>  ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
>> 270.7.5/1698 - Release Date: 29/09/2008 7:25 PM
>>
>>
>
> Here is how one newbie would do it:
>
>
> import random
>
> # Initialize variables
> head = 0
> tail = 0
>
> # Flip the coin a hundred times
> for x in range(100):
>   choice = random.randint(1,2)
>  # Is it 'head'?
>   if choice == 1 :
>       head = head + 1
>      # If not 'head' then it must be tail
>   else :
>       tail = tail + 1
>      print "head = ",head
> print "tail = ",tail
>
>
>  _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Please let us know if Pierre gets an an "A" on that assignment or not Kayla.

-- 
Stand Fast,
tjg.  [Timothy Grant]

From pierre.dagenais at ncf.ca  Wed Oct  1 09:55:53 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 03:55:53 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <e775286d0809302305p6f4d439dk89ef559978454207@mail.gmail.com>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<48E308B5.6030405@ncf.ca>
	<e775286d0809302305p6f4d439dk89ef559978454207@mail.gmail.com>
Message-ID: <48E32D09.2010605@ncf.ca>

Timothy Grant wrote:
> On Tue, Sep 30, 2008 at 10:20 PM, Pierre Dagenais
> <pierre.dagenais at ncf.ca> wrote:
>   
>> kayla bishop wrote:
>>     
>>> I can't figure out how to write a program where you flip a coin 100 times
>>> and it keeps track of how many heads and tails you flipped but it has to be
>>> random. Can you please help
>>> _________________________________________________________________
>>> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
>>>
>>> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
>>>  ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>  ------------------------------------------------------------------------
>>>
>>>
>>> No virus found in this incoming message.
>>> Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
>>> 270.7.5/1698 - Release Date: 29/09/2008 7:25 PM
>>>
>>>
>>>       
>> Here is how one newbie would do it:
>>
>>
>> import random
>>
>> # Initialize variables
>> head = 0
>> tail = 0
>>
>> # Flip the coin a hundred times
>> for x in range(100):
>>   choice = random.randint(1,2)
>>  # Is it 'head'?
>>   if choice == 1 :
>>       head = head + 1
>>      # If not 'head' then it must be tail
>>   else :
>>       tail = tail + 1
>>      print "head = ",head
>> print "tail = ",tail
>>
>>
>>  _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>     
>
> Please let us know if Pierre gets an an "A" on that assignment or not Kayla.
>
>   
If that's what it is, and I thought it might be, he won't learn how to 
program but on exam day he'll realize that cheating is very expensive. A 
great lesson to learn early in life if possible. On the other hand if 
Kayla is just new to programming and learning on his own, then some 
silly mistake can take weeks to figure out and is a huge waste of time, 
as I experienced when learning basic on my beloved ZX81. Besides any 
teacher worth it's wiff should scan this list for cheaters, right?
Have a nice day, both of you.

From pierre.dagenais at ncf.ca  Wed Oct  1 10:00:55 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 04:00:55 -0400
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
 file or directory
In-Reply-To: <e775286d0809302254y139e8a45xc613d88d9f8e0efc@mail.gmail.com>
References: <48E284D2.7040201@ncf.ca>
	<e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
	<48E2F628.1090106@ncf.ca>
	<e775286d0809302254y139e8a45xc613d88d9f8e0efc@mail.gmail.com>
Message-ID: <48E32E37.4070000@ncf.ca>

Timothy Grant wrote:
> On Tue, Sep 30, 2008 at 9:01 PM, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:
>   
>> Timothy Grant wrote:
>>     
>>> On Tue, Sep 30, 2008 at 12:58 PM, Pierre Dagenais
>>> <pierre.dagenais at ncf.ca> wrote:
>>>
>>>       
>>>> The file test.py is in I:\Python25\MyCode,
>>>> if I enter:
>>>>
>>>>  C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works
>>>> as
>>>> I would expect.
>>>>
>>>> However when I enter the same command from any other directory I get this
>>>> error:
>>>>
>>>>  C:\>python test.py
>>>>  python: can't open file 'test.py' : [Errno 2] No such file or directory
>>>>
>>>> I've set the environment variable pythonpath as
>>>>  C:\>set pythonpath = C:\\Python25\\MyCode
>>>> what am I doing wrong,
>>>> Thank u for your help,
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>>
>>>>         
>>> You need to give the full path to your test.py file.
>>>
>>> PYTHONPATH sets the python library search path.
>>>
>>>
>>>  Thank you Tim,
>>> Definitively C:\python \python25\mycode\test.py does work. If you're right
>>> about having to give the full path, and I suspect you are, Then this means
>>> that python knows to search the currennt working directory for  the file to
>>> execute, but nowhere else. It seems a strange behavior. Maybe this is on Mr.
>>> Guido van Rossum todo list.
>>>
>>>       
>
> Why is that strange? Would you expect any other program not on the
> path to execute without a fully qualified path? Make your python code
> executable, and put it somewhere on the path and I'm quite sure it
> would run as expected (though it has been over 10 years since I last
> had to work on a Windows box so I'm not quite sure how to do that).
>
>   
> ------------------------------------------------------------------------
> Yes Tim, but both PATH and PYTHONPATH are set to \python25 and \python25\MyCode, so I don't understand why python searches the CWD but neither the path nor pythonpath directories.


From alan.gauld at btinternet.com  Wed Oct  1 11:09:48 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 1 Oct 2008 10:09:48 +0100
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
	file or directory
References: <48E284D2.7040201@ncf.ca><e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
	<48E2F628.1090106@ncf.ca>
Message-ID: <gbveop$i4t$1@ger.gmane.org>


"Pierre Dagenais" <pierre.dagenais at ncf.ca> wrote


>>> The file test.py is in I:\Python25\MyCode,

There is an inconsistency here.
You say at this point that the drive is I

>>> I've set the environment variable pythonpath as
>>>  C:\>set pythonpath = C:\\Python25\\MyCode

But here you add a folder in the C drive?

>> Definitively C:\python \python25\mycode\test.py does work.
> If you're right about having to give the full path, and I suspect 
> you are, Then this means that python knows to search the currennt 
> working directory for  the file to execute, but nowhere else.

Correct, just like every other program.
If you run notepad foo.txt notepad will open a new foo.txt
in the current folder it will not search your drive to find some
other foo.txt that you created prevbiously.
Why would python be any different?

The trick to do what you want is not to execute python but
to execute the script and allow the OS to associate Python
with it.

So either just type the script name into the prompt (assuming
it is on the PATH) or double click in explorer and Windows will
find Python itself.

HTH,

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



From davholla2002 at yahoo.co.uk  Wed Oct  1 11:04:01 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Wed, 1 Oct 2008 09:04:01 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
Message-ID: <235353.94243.qm@web25607.mail.ukl.yahoo.com>

At work I have windows XP service pack 3 and although I have sys admin I can not use idle.
I have googled but no success - any ideas?


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081001/c2d48fdd/attachment.htm>

From alan.gauld at btinternet.com  Wed Oct  1 11:13:21 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 1 Oct 2008 10:13:21 +0100
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
	file or directory
References: <48E284D2.7040201@ncf.ca><e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com><48E2F628.1090106@ncf.ca><e775286d0809302254y139e8a45xc613d88d9f8e0efc@mail.gmail.com>
	<48E32E37.4070000@ncf.ca>
Message-ID: <gbveve$iqa$1@ger.gmane.org>

"Pierre Dagenais" <pierre.dagenais at ncf.ca> wrote 

> Yes Tim, but both PATH and PYTHONPATH are set 
> to \python25 and \python25\MyCode, so I don't understand 
> why python searches the CWD but neither the path nor 
> pythonpath directories.

Because that's how Windows works, its how Bill Gates 
decided it should be... Its what Windows calls the 
Working Folder and by default for the command prompt 
its the one you are in.

It  can be argued that it is "A Good Thing" since it allows you 
to have several python scripts of the same name and not 
have the wrong script accidentally being started.

HTH,

Alan G.


From alan.gauld at btinternet.com  Wed Oct  1 11:20:12 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 1 Oct 2008 10:20:12 +0100
Subject: [Tutor] Heads & Tails was Re: (no subject)
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
Message-ID: <gbvfc9$k2r$1@ger.gmane.org>

"kayla bishop" <horses_kayla10 at hotmail.com> wrote 

Please use a sensible subject line

> I can't figure out how to write a program where you flip a 
> coin 100 times and it keeps track of how many heads 
> and tails you flipped but it has to be random. 

This sounds like homework so we cannot give you a solution.

But here are some questions that may help you find a solution:

1) could you write a program to ask the user for a head or 
a tail and store the answer?

2) could you make that program repeat 10 times and store 
the count of heads only?

3) could you store the total for heads and tails into two 
separate totals?

4) could you replace the user input with a random number?

5) could you make the random number result be one of two 
values - say head and tail?

6) could you increase the repetitions to 100?

Done all that? Then you've solved your problem.
If you didn't where did you get stuck?
Show us your code and any errors.

HTH,

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


From kent37 at tds.net  Wed Oct  1 12:34:39 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 1 Oct 2008 06:34:39 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <48E32D09.2010605@ncf.ca>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<48E308B5.6030405@ncf.ca>
	<e775286d0809302305p6f4d439dk89ef559978454207@mail.gmail.com>
	<48E32D09.2010605@ncf.ca>
Message-ID: <1c2a2c590810010334jf305f1bm1b4437e92d700359@mail.gmail.com>

On Wed, Oct 1, 2008 at 3:55 AM, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:
> Timothy Grant wrote:

> If that's what it is, and I thought it might be, he won't learn how to
> program but on exam day he'll realize that cheating is very expensive. A
> great lesson to learn early in life if possible. On the other hand if Kayla
> is just new to programming and learning on his own, then some silly mistake
> can take weeks to figure out and is a huge waste of time, as I experienced
> when learning basic on my beloved ZX81. Besides any teacher worth it's wiff
> should scan this list for cheaters, right?

Regardless of how you feel about cheating, or whether the teacher is
reading the list, the policy on this list is not to knowingly supply
explicit answers to homework questions. We give hints and help
learners when they are stuck. You didn't even give Kayla a chance to
get stuck.

Kent

From bhaaluu at gmail.com  Wed Oct  1 14:57:25 2008
From: bhaaluu at gmail.com (bhaaluu)
Date: Wed, 1 Oct 2008 08:57:25 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
Message-ID: <ea979d70810010557q78421651se408c9bd44f18298@mail.gmail.com>

Since an answer has already been given (by Pierre Dagenais),
let's see if we can help you "figure it out".

The first step is to read the program specification, or, in your
case, read the homework problem very carefully. Since most
computer programs have INPUT, PROCESS, and OUTPUT, let's
try to look at the problem from that viewpoint, shall we?

On Tue, Sep 30, 2008 at 10:47 PM, kayla bishop
<horses_kayla10 at hotmail.com> wrote:
> I can't figure out how to write a program where you flip a coin 100 times
> and it keeps track of how many heads and tails you flipped but it has to be
> random. Can you please help

Well, since you said the magic word, I'll try.

First of all, a hash mark designates a comment.
A comment isn't read by the computer. Everything
after a hash mark isn't read by the computer, BUT
you can read it, and that's why it is always a good
idea to use comments in your program.

We can break down the problem into INPUT, PROCESS
and OUTPUT as follows:

> I can't figure out how to [INPUT, PROCESS, OUTPUT]
> write a program
> where you flip a "coin" [INPUT]
> 100 times [PROCESS]
> and it keeps track of how many heads and tails you flipped [OUTPUT]
> but it has to be random. [PROCESS]

You have a coin which has two sides "heads" and "tails",
so that is the INPUT.
You flip the coin 100 times, and each time you flip it, the result is random.
That is the PROCESS.
You keep track of how many times it comes up heads and tails.
That is the OUTPUT.
That wasn't too difficult, was it?

Python has a lot of modules that are already written
for you. That's way cool because you don't have to
figure that part out! Doing random things is one of
those things you don't have to figure out, because
there is a module called random. You can use the
stuff in random by importing it into your program.
Find out more about random in the Python documentation.
This is usually done at the top of the program.

#!/usr/bin/python
# flipCoin.py
# 2008-10-01
# b h a a l u u at g m a i l dot c o m

import random

#Next you need some INPUT. I think we decided that the
#coin would be INPUT, right? And the coin has 'heads' and 'tails'?
#Let's make a "list" for the coin:

coin = ['heads', 'tails']

#Lists are surrounded by square brackets.
#But the program needs to choose those randomly, right?

flip = random.choice(coin)

#Now, let's count how many times you flip the coin.

count = 100

#Finally, keep track of heads and tails:

heads = 0
tails = 0

#They're zero because you haven't flipped the coin yet.

#Now, let's flip the coin (PROCESS).

while count != 0:
    #each time through the loop, flip will randomly choose a side of the coin
    flip = random.choice(coin)
    #if/else selection. There are only two choices.
    if flip == "heads":
        heads += 1
    else:
        tails += 1
    #decrement the counter, or you'll be in an infinite loop
    #it started at 100, so subtract one each iteration
    count -= 1

#Finally, let's print the OUTPUT:
print "Heads: ", heads
print "Tails: ", tails

Not the indentation after the while loop line.
That's a Python thing.

Since I've put so much time into this tutorial, I have a
challenge for you: Write a program that rolls a pair of
ten-sided dice, and tell me what the outcome of the roll is?
How about the outcome of three rolls?

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!

From gslindstrom at gmail.com  Wed Oct  1 14:46:31 2008
From: gslindstrom at gmail.com (Greg Lindstrom)
Date: Wed, 1 Oct 2008 07:46:31 -0500
Subject: [Tutor] PyCon 2009 (US) - Call for Tutorials
Message-ID: <a9f39a410810010546r7a11e054w378dd88ba54ab150@mail.gmail.com>

The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
"pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at <
http://us.pycon.org/2009/tutorials/proposals/>.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact pycon-tutorials at python.org.

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081001/62ecb752/attachment.htm>

From emile at fenx.com  Wed Oct  1 15:10:26 2008
From: emile at fenx.com (Emile van Sebille)
Date: Wed, 01 Oct 2008 06:10:26 -0700
Subject: [Tutor] unable to import Image module from my application
In-Reply-To: <BAY121-W2D8CF7AFFAA1BD7718B10F6430@phx.gbl>
References: <BAY121-W2D8CF7AFFAA1BD7718B10F6430@phx.gbl>
Message-ID: <gbvsoh$d8$1@ger.gmane.org>

ShivKumar Anand wrote:
> I am using Python Image library on windows and it is running well.
>  
> I am using RHEL E4 on another machine and when I installed 
> "python-imaging-1.1.6-2.el4.rf.i386.rpm", still i am not able to call 
> the Image and ImagOps modules from my application on this Linux machine.
>  
> After that --I manually added Imaging1.1.4 folder in 
> /usr/lib/Python2.4/site-packages and added entry in easy_install.pth.
> After that, I am able to import the modules from python prompt, but 
> still I am not able to import from my application.

It's likely you've still got a path issue.  When you import from the 
command line the contents of your current directory is importable.  I'd 
suspect you were in the PIL directory when you tested from the command line.

To verify a path problem, add
sys.path.append('/usr/lib/Python2.4/site-packages//usr/lib/Python2.4/site-packages')
prior to the import in your application.  If that works, double check 
your path setup.

HTH,

Emile


>  
> I am not able to figure out the exact reason for this.
>  
>  
> Kindly guiide me.
> Thanks in anticipation.
>  
>  
> Shiv
> 
> ------------------------------------------------------------------------
> MSN Technology brings you the latest on gadgets, gizmos and the new hits 
> in the gaming market. Try it now! <http://computing.in.msn.com/>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From davholla2002 at yahoo.co.uk  Wed Oct  1 15:21:26 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Wed, 1 Oct 2008 13:21:26 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <1c2a2c590810010335k2cb91f99v3186d23c094d17b1@mail.gmail.com>
Message-ID: <884917.85069.qm@web25603.mail.ukl.yahoo.com>

The program does not start up.? I think it is a firewall issue but I am having problems changing my firewall to allow idle.

--- On Wed, 1/10/08, Kent Johnson <kent37 at tds.net> wrote:
From: Kent Johnson <kent37 at tds.net>
Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Date: Wednesday, 1 October, 2008, 11:35 AM

On Wed, Oct 1, 2008 at 5:04 AM, David Holland <davholla2002 at yahoo.co.uk>
wrote:
> At work I have windows XP service pack 3 and although I have sys admin I
can
> not use idle.
> I have googled but no success - any ideas?

What problem are you having?



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081001/eb2c9f06/attachment.htm>

From srilyk at gmail.com  Wed Oct  1 15:46:50 2008
From: srilyk at gmail.com (W W)
Date: Wed, 1 Oct 2008 08:46:50 -0500
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <884917.85069.qm@web25603.mail.ukl.yahoo.com>
References: <1c2a2c590810010335k2cb91f99v3186d23c094d17b1@mail.gmail.com>
	<884917.85069.qm@web25603.mail.ukl.yahoo.com>
Message-ID: <333efb450810010646l2e019d25u6f8e4bac39d86e5e@mail.gmail.com>

Why would your firewall be blocking idle? Does idle connect to the internet?

On Wed, Oct 1, 2008 at 8:21 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:

> The program does not start up.  I think it is a firewall issue but I am
> having problems changing my firewall to allow idle.
>
> --- On *Wed, 1/10/08, Kent Johnson <kent37 at tds.net>* wrote:
>
> From: Kent Johnson <kent37 at tds.net>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: davholla2002 at yahoo.co.uk
> Date: Wednesday, 1 October, 2008, 11:35 AM
>
> On Wed, Oct 1, 2008 at 5:04 AM, David Holland <davholla2002 at yahoo.co.uk>
> wrote:
> > At work I have windows XP service pack 3 and although I have sys admin I
> can
> > not use idle.
> > I have googled but no success - any ideas?
>
> What problem are you having?
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081001/1dc0aa03/attachment-0001.htm>

From amonroe at columbus.rr.com  Wed Oct  1 15:49:23 2008
From: amonroe at columbus.rr.com (R. Alan Monroe)
Date: Wed, 1 Oct 2008 09:49:23 -0400
Subject: [Tutor] Text Scatter Plots?
In-Reply-To: <48E0BD38.9000904@sbcglobal.net>
References: <48E0BD38.9000904@sbcglobal.net>
Message-ID: <117875730794.20081001094923@columbus.rr.com>

> Is there a text graphics module that does say scatter plots or
> histograms? I'm thinking of stuff prior to the graphics era of
> computing. I'm looking for something really simple.

Here's a quick and dirty way to do basic histogram of dice rolls:


import random

rolls={}

for x in range(10000):
    a = [random.randint(1,10) for x in range(2)]
    v = sum(a)
    
    try:
        rolls[v] += 1
    except KeyError:
        rolls[v] = 1

m = max(rolls.values())
stretch = (m/70.0)

for x in rolls.keys():
    print x, rolls[x], '*' * ( int(rolls[x] / stretch)  )


From lie.1296 at gmail.com  Wed Oct  1 17:02:54 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Wed, 01 Oct 2008 22:02:54 +0700
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <mailman.15842.1222868814.3486.tutor@python.org>
References: <mailman.15842.1222868814.3486.tutor@python.org>
Message-ID: <1222873374.6541.21.camel@lieryan-laptop>

On W W wrote:
> 
> Message: 6
> Date: Wed, 1 Oct 2008 08:46:50 -0500
> From: "W W" <srilyk at gmail.com>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: davholla2002 at yahoo.co.uk
> Cc: tutor python <tutor at python.org>
> Message-ID:
>         <333efb450810010646l2e019d25u6f8e4bac39d86e5e at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Why would your firewall be blocking idle? Does idle connect to the
> internet?

No, but since IDLE itself is written in Python, it use a really weird
way to communicate with the python process. I don't know the details of
that really weird way, but it involves the possibility of a firewall
blocking IDLE. The safe way if you can't configure firewall is to open
IDLE without subprocess.

> On Wed, Oct 1, 2008 at 8:21 AM, David Holland
> <davholla2002 at yahoo.co.uk>wrote:

(snip)
> >
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> 
> 
> -- 
> To be considered stupid and to be told so is more painful than being
> called
> gluttonous, mendacious, violent, lascivious, lazy, cowardly: every
> weakness,
> every vice, has found its defenders, its rhetoric, its ennoblement and
> exaltation, but stupidity hasn't. - Primo Levi
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20081001/1dc0aa03/attachment.htm>
> 
> ------------------------------
> 


From emile at fenx.com  Wed Oct  1 19:29:26 2008
From: emile at fenx.com (Emile van Sebille)
Date: Wed, 01 Oct 2008 10:29:26 -0700
Subject: [Tutor] unable to import Image module from my application
In-Reply-To: <gbvsoh$d8$1@ger.gmane.org>
References: <BAY121-W2D8CF7AFFAA1BD7718B10F6430@phx.gbl>
	<gbvsoh$d8$1@ger.gmane.org>
Message-ID: <gc0bu4$r5g$1@ger.gmane.org>

Emile van Sebille wrote:
> To verify a path problem, add
> sys.path.append('/usr/lib/Python2.4/site-packages//usr/lib/Python2.4/site-packages') 

erhhmmm...

sys.path.append('/usr/lib/Python2.4/site-packages/Imaging1.1.4')

EvS


From jeremiah.jester at panasonic.aero  Wed Oct  1 19:28:48 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Wed, 01 Oct 2008 10:28:48 -0700
Subject: [Tutor] sample python twill scripts?
Message-ID: <1222882128.6536.7.camel@jeremiah-laptop>

Just wondering if anyone here would be interested in sharing a python
twill script?  I'd just like to take a gander at how others are
engineering their scripts.

Thanks,
JJ



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From alan.gauld at btinternet.com  Wed Oct  1 19:41:42 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 1 Oct 2008 18:41:42 +0100
Subject: [Tutor] Idle and windows XP firewall
References: <1c2a2c590810010335k2cb91f99v3186d23c094d17b1@mail.gmail.com><884917.85069.qm@web25603.mail.ukl.yahoo.com>
	<333efb450810010646l2e019d25u6f8e4bac39d86e5e@mail.gmail.com>
Message-ID: <gc0coj$utf$1@ger.gmane.org>


"W W" <srilyk at gmail.com> wrote in message 
news:333efb450810010646l2e019d25u6f8e4bac39d86e5e at mail.gmail.com...
> Why would your firewall be blocking idle? Does idle connect to the 
> internet?

It connects to itself via a socket. But I thought that problem had 
been fixed
several releases ago...

> On Wed, Oct 1, 2008 at 8:21 AM, David Holland 
> <davholla2002 at yahoo.co.uk>wrote:
>
>> The program does not start up.  I think it is a firewall issue but 
>> I am
>> having problems changing my firewall to allow idle.

Which version of Python are you using?

Alan G. 



From pierre.dagenais at ncf.ca  Wed Oct  1 21:48:25 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 15:48:25 -0400
Subject: [Tutor] python: can't open file 'test.py' : [Errno 2] No such
 file or directory
In-Reply-To: <gbveop$i4t$1@ger.gmane.org>
References: <48E284D2.7040201@ncf.ca>
	<e775286d0809301406q6da64590m6b5149c011b65e0@mail.gmail.com>
	<48E2F628.1090106@ncf.ca> <gbveop$i4t$1@ger.gmane.org>
Message-ID: <48E3D409.5040802@ncf.ca>


>> If you're right about having to give the full path, and I suspect you 
>> are, Then this means that python knows to search the currennt working 
>> directory for  the file to execute, but nowhere else.
>
> Correct, just like every other program.
> If you run notepad foo.txt notepad will open a new foo.txt
> in the current folder it will not search your drive to find some
> other foo.txt that you created prevbiously.
> Why would python be any different?
I didn't realize other program were also behaving that way, I don't work 
much with the command prompt anymore :-)
>
> The trick to do what you want is not to execute python but
> to execute the script and allow the OS to associate Python
> with it.
That is what I was missing, C:\test.py will execute.
>
> So either just type the script name into the prompt (assuming
> it is on the PATH) or double click in explorer and Windows will
> find Python itself.
>
> HTH,
It sure does, thanks everybody for the great replies,

From pierre.dagenais at ncf.ca  Wed Oct  1 22:15:37 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Wed, 01 Oct 2008 16:15:37 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <BLU117-W54CD8B6B3DA192AF4C38F7FF420@phx.gbl>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<48E2FA2B.3040701@ncf.ca> <BLU117-W54CD8B6B3DA192AF4C38F7FF420@phx.gbl>
Message-ID: <48E3DA69.9080109@ncf.ca>

kayla bishop wrote:
> ok i imported the random module and set it up with a 2... i can't get it to loop correctly to where it keeps going until the total of heads and tails is 100> Date: Wed, 1 Oct 2008 00:18:51 -0400> From: pierre.dagenais at ncf.ca> CC: tutor at python.org> Subject: Re: [Tutor] (no subject)> > kayla bishop wrote:> > I can't figure out how to write a program where you flip a coin 100 times and it keeps track of how many heads and tails you flipped but it has to be random. Can you please help> > 
Hi Kayla,
Have you read the other posts on the list? bhaaluu sent you a great 
little tutorial showing how a pro would go about solving this problem. 
Read it carefully, it's really worth all the time you will spend on it. 
Your problem seems to be that you expect the random module to return a 
100 answers, it won't. Random returns only one choice for everytime you 
run it. That's why we use a loop, to run random a 100 times.
Don't despair, in the beginning everybody trips on silly details like 
that, keep at it and soon you'll be the expert.

Kent,
I didn't realize the list had a policy, I'm sorry for breaking it. Were 
can I read it? ignorance not being an excuse.

From bhaaluu at gmail.com  Wed Oct  1 22:45:58 2008
From: bhaaluu at gmail.com (bhaaluu)
Date: Wed, 1 Oct 2008 16:45:58 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <ea979d70810010557q78421651se408c9bd44f18298@mail.gmail.com>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<ea979d70810010557q78421651se408c9bd44f18298@mail.gmail.com>
Message-ID: <ea979d70810011345i2470a8bdpb1240f5796bf0c21@mail.gmail.com>

Correction of post typo follows.....

On Wed, Oct 1, 2008 at 8:57 AM, bhaaluu <bhaaluu at gmail.com> wrote:
>
> #Now, let's flip the coin (PROCESS).
>
> while count != 0:
>    #each time through the loop, flip will randomly choose a side of the coin
>    flip = random.choice(coin)
>    #if/else selection. There are only two choices.
>    if flip == "heads":
>        heads += 1
>    else:
>        tails += 1
>    #decrement the counter, or you'll be in an infinite loop
>    #it started at 100, so subtract one each iteration
>    count -= 1
>
> Not the indentation after the while loop line.
> That's a Python thing.

That should be "NOTE the indentation after the while loop".
Also note the indentation after the if and else lines. Python
uses indentation to define 'blocks' of code. Another little
detail that may escape one's notice is that the first line
of each block ends with a colon. A block is finished when
the indentation ends. Blocks of code may be nested
within each other, as long as they are properly indented.

>
> Since I've put so much time into this tutorial, I have a
> challenge for you: Write a program that rolls a pair of
> ten-sided dice, and tell me what the outcome of the roll is?
> How about the outcome of three rolls?
>

The programming challenge still stands! Kayla? (BTW, when
I say "tell me what the outcome is", I'm asking for your program
to produce some OUTPUT!)

Happy [Python] Programming!
-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!

From alecwh at gmail.com  Wed Oct  1 22:56:08 2008
From: alecwh at gmail.com (Alec Henriksen)
Date: Wed, 01 Oct 2008 14:56:08 -0600
Subject: [Tutor] Finding the "streaks" in heads/tails list
Message-ID: <1222894568.6779.52.camel@alecwh-laptop>

Hello,

I thought it'd be cool to write a program for my logic/critical thinking
class, and right now we're evaluating randomness - and the deception of
it. A previous post inspired it - coin flipping.

So, I've written a program that flips a coin 1000 times and records it
all in a dictionary, like this:

# 0 = heads, 1 = tails
flips = [0,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1]

What I want to do, is find out the largest "streak" of digits. In the
above example, the streak would be 5, because there are 5 tails flips in
a row.

I've thought about this, and it seems like regular expressions would be
needed.

Can someone help/hint? Thanks in advance!



From kent37 at tds.net  Wed Oct  1 23:23:47 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 1 Oct 2008 17:23:47 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <48E3DA69.9080109@ncf.ca>
References: <BLU117-W8C4F0E0C12A4B3359CC96FF420@phx.gbl>
	<48E2FA2B.3040701@ncf.ca>
	<BLU117-W54CD8B6B3DA192AF4C38F7FF420@phx.gbl>
	<48E3DA69.9080109@ncf.ca>
Message-ID: <1c2a2c590810011423x4ce88e57ua861a5aefe259a48@mail.gmail.com>

On Wed, Oct 1, 2008 at 4:15 PM, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:

> I didn't realize the list had a policy, I'm sorry for breaking it. Were can
> I read it? ignorance not being an excuse.

Hmm, it doesn't seem to be written down. I'll have to add it to the
list info page and the welcome message.

Kent

From kent37 at tds.net  Wed Oct  1 23:27:07 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 1 Oct 2008 17:27:07 -0400
Subject: [Tutor] Finding the "streaks" in heads/tails list
In-Reply-To: <1222894568.6779.52.camel@alecwh-laptop>
References: <1222894568.6779.52.camel@alecwh-laptop>
Message-ID: <1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>

On Wed, Oct 1, 2008 at 4:56 PM, Alec Henriksen <alecwh at gmail.com> wrote:
> Hello,
>
> I thought it'd be cool to write a program for my logic/critical thinking
> class, and right now we're evaluating randomness - and the deception of
> it. A previous post inspired it - coin flipping.
>
> So, I've written a program that flips a coin 1000 times and records it
> all in a dictionary, like this:
>
> # 0 = heads, 1 = tails
> flips = [0,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1]
>
> What I want to do, is find out the largest "streak" of digits. In the
> above example, the streak would be 5, because there are 5 tails flips in
> a row.
>
> I've thought about this, and it seems like regular expressions would be
> needed.

Regular expressions are for processing strings, not loops.

I would loop through the list with a for loop, keeping track of the
last value seen and the current count. If the current value is the
same as the last, increment the count; if it is different, reset the
count.

You don't actually have to put the flips into a list, you could count
the runs directly as you make the flips.

Kent

From michael at yavarsity.com  Wed Oct  1 23:01:33 2008
From: michael at yavarsity.com (Michael yaV)
Date: Wed, 1 Oct 2008 17:01:33 -0400
Subject: [Tutor] newbee needs direction
Message-ID: <CBBA2D42-1C52-4A44-A66D-6B631167C925@yavarsity.com>

Here is my problem and my coding knowledge consists of html. I have  
all the time in the world to play with this so I thought I would at  
least ask how to get started.
I want to create a web base program that would output team standings.  
The only given will be the names of each team and their division (ie:  
division 1, division 2). What will be supplied is the score of an  
event (game played between 2 teams), and weather it is a division game  
(two teams in the same division playing each other) or out of division  
game (two teams in different divisions playing each other). The out- 
put will then be, the team with the highest percent of winnings will  
show up at the top of a list and the worst win/loss percentage team  
will show up at the bottom of a list. Also, for out-put, their will be  
a total of 7 columns beside each team name. 4 columns for Division  
play, a win column, a loss column, a tie column and then the win/loss  
percentage column. then their will be 3 columns for Non-Division play,  
a win column, a loss column, a tie column.
So, based on an entered score, a number will be added to one of the  
columns, the win column, loss column or tie column and will also be  
used to compute a win/loss percentage. The win loss percentage will be  
total games won, divided by total games played (ie: A team that is 3-2  
has a .600 win percentage because 3 divided by five equals .600). For  
ties you would have to Add up the number of wins and half the number  
of ties, and divide by the total number of games played. (ie: For  
instance, a team with a 10-5-1 record would have a 10.5/16 or .656  
winning percentage). If a team plays in a non-division game it will  
have no barring to the standings unless their are two or more teams  
with the same record. Therefore, if 2 teams have the same division  
wins (win/loss percentage) but one team has more non-division wins,  
that team should show up higher on the list.
I would also like that all teams' scores would have to be added before  
a standings change would be calculated and made week to week. However,  
their might have to be a "bye" button or just add zeros, in case a  
particular team does in fact have a bye while other teams play. Also,  
this way I will know which teams need their scores to be added.
I will most likely be adding the scores to an admin page and the  
results will them be posted on a website.
OK... how should I get started and how tough will this be?

Thanks, Mike

From dyoo at cs.wpi.edu  Thu Oct  2 00:00:05 2008
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Wed, 1 Oct 2008 18:00:05 -0400
Subject: [Tutor] Finding the "streaks" in heads/tails list
In-Reply-To: <1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>
References: <1222894568.6779.52.camel@alecwh-laptop>
	<1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>
Message-ID: <d06401780810011500w3f7ae356q72b978f55ee38561@mail.gmail.com>

> Regular expressions are for processing strings, not loops.

>From a theoretical point of view, this isn't quite true: regular
expressions can deal with sequences of things.  It's true that most
regular expression libraries know how to deal only with characters,
but that's a matter of specializing the library for efficiency, and
not a general property of regexes.

But what regular expressions (i.e. finite-state automata) can't do
very well is count with memory, and the task you're asking for is
fundamentally an anti-regexp one.


> I would loop through the list with a for loop, keeping track of the
> last value seen and the current count. If the current value is the
> same as the last, increment the count; if it is different, reset the
> count.

Agreed.  This seems direct.

If we want to be cute, we can also use the itertools.groupby()
function to do the clumping of identical sequential values for us.
For example:

#################################################
>>> for group in itertools.groupby('aaaabbbbcaaabaaaacc'):
...     print group[0], len(list(group[1]))
...
a 4
b 4
c 1
a 3
b 1
a 4
c 2
#################################################

See the standard library documentation for more details on itertools.groupby():

    http://www.python.org/doc/lib/itertools-functions.html

From kent37 at tds.net  Thu Oct  2 01:01:04 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 1 Oct 2008 19:01:04 -0400
Subject: [Tutor] Finding the "streaks" in heads/tails list
In-Reply-To: <d06401780810011500w3f7ae356q72b978f55ee38561@mail.gmail.com>
References: <1222894568.6779.52.camel@alecwh-laptop>
	<1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>
	<d06401780810011500w3f7ae356q72b978f55ee38561@mail.gmail.com>
Message-ID: <1c2a2c590810011601s5be86d6el85b3f67f3889b29f@mail.gmail.com>

On Wed, Oct 1, 2008 at 6:00 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
>> Regular expressions are for processing strings, not loops.
>
> From a theoretical point of view, this isn't quite true: regular
> expressions can deal with sequences of things.

Sheesh! OK, *Python* regular expressions are for processing strings :-)

> If we want to be cute, we can also use the itertools.groupby()
> function to do the clumping of identical sequential values for us.
> For example:
>
> #################################################
>>>> for group in itertools.groupby('aaaabbbbcaaabaaaacc'):
> ...     print group[0], len(list(group[1]))

Hmm, I smell a one-liner here:
max(len(list(group[1])) for group in itertools.groupby('aaaabbbbcaaabaaaacc'))

Kent

From alan.gauld at btinternet.com  Thu Oct  2 02:27:39 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 2 Oct 2008 01:27:39 +0100
Subject: [Tutor] Finding the "streaks" in heads/tails list
References: <1222894568.6779.52.camel@alecwh-laptop>
	<1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>
Message-ID: <gc14hp$nsm$1@ger.gmane.org>


"Kent Johnson" <kent37 at tds.net> wrote

>> What I want to do, is find out the largest "streak" of digits. In 
>> the
>> above example, the streak would be 5, because there are 5 tails 
>> flips in
>> a row.

> I would loop through the list with a for loop, keeping track of the
> last value seen and the current count. If the current value is the
> same as the last, increment the count; if it is different, reset the
> count.

You need to store the count before resetting it since you want
to know the largest value of count over the list. Or at least keep a
separate max variable that you update if count > max.

But as Kent also said the easiest way is probably to just track the
runs and their count as the data is generated rather than waiting
till the end and post-processing the results.

HTH,


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



From alan.gauld at btinternet.com  Thu Oct  2 02:37:36 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 2 Oct 2008 01:37:36 +0100
Subject: [Tutor] newbee needs direction
References: <CBBA2D42-1C52-4A44-A66D-6B631167C925@yavarsity.com>
Message-ID: <gc154d$ph0$1@ger.gmane.org>

"Michael yaV" <michael at yavarsity.com> wrote

> Here is my problem and my coding knowledge consists of html.

OK, The first step is to pause your project long enough to learn
the basics of programming - with Python since you are asking
on a Python list! :-)

> I want to create a web base program that would output team 
> standings.

The second stage is to write the program as a non web
application first. Keeping the novelty factors down helps
when learning to program!

> The only given will be the names of each team and their division 
> (ie:  division 1, division 2). What will be supplied is the score of 
> an  event (game played between 2 teams), and weather it is a 
> division game  (two teams in the same division playing each other) 
> or out of division  game (two teams in different divisions playing 
> each other).

Sounds OK so far.

> The output will then be, the team with the highest percent of 
> winnings will  show up at the top of a list and the worst win/loss 
> percentage team  will show up at the bottom of a list. Also, for 
> out-put, their will be  a total of 7 columns beside each team name. 
> 4 columns for Division  play, a win column, a loss column, a tie 
> column and then the win/loss  percentage column. then their will be 
> 3 columns for Non-Division play,  a win column, a loss column, a tie 
> column.

A good idea when trying to define this kind of thing is to produce
a sample output form - in html since you know it already.

< lots more snipped>
> OK... how should I get started and how tough will this be?

Its a pretty good aspirational beginners project.
Not too hard for a newbie and easy enough to chunk up into bite
sized morsels.

But first focus on getting the basics of Python programming clear
because otherwise you will wind up getting the details of your
problem all mixed up with the details of Python! Stick to solving
one problem at a time, so take a week or so out to learn Python 
basics.
Then go back to the problem and focus on building a command
line solution first. Once thats done its relatively easy to convert
it for the web.

For learning Python pick one of the Non Programmers tutorials
on the Python web site and follow it through.
[ If you pick mine to only need to go as far as the end of the
  Basics section before returning to your problem...]

HTH,

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



From michael at yavarsity.com  Thu Oct  2 04:24:45 2008
From: michael at yavarsity.com (Michael Waltemeyer)
Date: Wed, 1 Oct 2008 22:24:45 -0400
Subject: [Tutor] newbee needs direction
In-Reply-To: <gc154d$ph0$1@ger.gmane.org>
References: <CBBA2D42-1C52-4A44-A66D-6B631167C925@yavarsity.com>
	<gc154d$ph0$1@ger.gmane.org>
Message-ID: <6514c7c7d8f9bab50a67118713676005@yavarsity.com>

Thanks Alan.
On Oct 1, 2008, at 8:37 PM, Alan Gauld wrote:

> "Michael yaV" <michael at yavarsity.com> wrote
>
>> Here is my problem and my coding knowledge consists of html.
>
> OK, The first step is to pause your project long enough to learn
> the basics of programming - with Python since you are asking
> on a Python list! :-)
>
>> I want to create a web base program that would output team standings.
>
> The second stage is to write the program as a non web
> application first. Keeping the novelty factors down helps
> when learning to program!
>
>> The only given will be the names of each team and their division (ie: 
>>  division 1, division 2). What will be supplied is the score of an  
>> event (game played between 2 teams), and weather it is a division 
>> game  (two teams in the same division playing each other) or out of 
>> division  game (two teams in different divisions playing each other).
>
> Sounds OK so far.
>
>> The output will then be, the team with the highest percent of 
>> winnings will  show up at the top of a list and the worst win/loss 
>> percentage team  will show up at the bottom of a list. Also, for 
>> out-put, their will be  a total of 7 columns beside each team name. 4 
>> columns for Division  play, a win column, a loss column, a tie column 
>> and then the win/loss  percentage column. then their will be 3 
>> columns for Non-Division play,  a win column, a loss column, a tie 
>> column.
>
> A good idea when trying to define this kind of thing is to produce
> a sample output form - in html since you know it already.
>
> < lots more snipped>
>> OK... how should I get started and how tough will this be?
>
> Its a pretty good aspirational beginners project.
> Not too hard for a newbie and easy enough to chunk up into bite
> sized morsels.
>
> But first focus on getting the basics of Python programming clear
> because otherwise you will wind up getting the details of your
> problem all mixed up with the details of Python! Stick to solving
> one problem at a time, so take a week or so out to learn Python basics.
> Then go back to the problem and focus on building a command
> line solution first. Once thats done its relatively easy to convert
> it for the web.
>
> For learning Python pick one of the Non Programmers tutorials
> on the Python web site and follow it through.
> [ If you pick mine to only need to go as far as the end of the
>  Basics section before returning to your problem...]
>
> HTH,
>
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
Michael Waltemeyer (yaVarsity)
michael at yavarsity.com


From d.conca at gmail.com  Thu Oct  2 09:52:40 2008
From: d.conca at gmail.com (Daniele)
Date: Thu, 2 Oct 2008 09:52:40 +0200
Subject: [Tutor] audio splitting with python
Message-ID: <537341c70810020052l69eddbbbwaa44b1e8cb6274a9@mail.gmail.com>

Hi list,
I'd like to split an ogg audio file into pieces (small enough to fit
in an audio cd). Can anybody suggest me a python module to do that?
Thanks,
Daniele

From kent37 at tds.net  Thu Oct  2 12:30:02 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 2 Oct 2008 06:30:02 -0400
Subject: [Tutor] audio splitting with python
In-Reply-To: <537341c70810020052l69eddbbbwaa44b1e8cb6274a9@mail.gmail.com>
References: <537341c70810020052l69eddbbbwaa44b1e8cb6274a9@mail.gmail.com>
Message-ID: <1c2a2c590810020330hf55ba3fx9e4098df020b8f75@mail.gmail.com>

On Thu, Oct 2, 2008 at 3:52 AM, Daniele <d.conca at gmail.com> wrote:
> Hi list,
> I'd like to split an ogg audio file into pieces (small enough to fit
> in an audio cd). Can anybody suggest me a python module to do that?

Perhaps PyOgg or oggpy:
http://ekyo.nerim.net/software/pyogg/
http://dingoskidneys.com/oggpy/

Or use Audacity or another tool:
http://audacity.sourceforge.net/
http://www.exefind.com/split-ogg/

Kent

From sdragon1984 at gmail.com  Thu Oct  2 15:10:36 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Thu, 2 Oct 2008 09:10:36 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <109363.20638.qm@web52007.mail.re2.yahoo.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
Message-ID: <111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>

Okay, I'm resurrecting this project. I did a little more work on it then
what you see here, but that ended up getting accidentally deleted, and I
haven't done anything with Python since.

I'm running into one problem already, and I haven't really added any extra
code. In the content (at this point, the rooms still have Bob's
descriptions), the very first line of actual code (third line in the
program) is returning an error.

Offending code:

# Content
# retrieve data for current room
room == start
while true:
    if room == start:
        desc = "Ahead of you, you see a chasm."
        ques = "Do you wish to try jumping over it? Y/N"
        destY = 2
        destN = 3

Error:

Traceback (most recent call last):
  File "samplegame.py", line 3, in <module>
    room == start
NameError: name 'room' is not defined


What's going on here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/ad9acdcf/attachment.htm>

From rabidpoobear at gmail.com  Thu Oct  2 15:18:34 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 08:18:34 -0500
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
Message-ID: <dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>

room == start is a comparison (check if room is equal to start - doesn't
make a whole lot of sense to be doing that here).  The "room" variable name
doesn't exist in the current namespace, so it can't be compared to start.
It looks like you wanted room = start.

On 10/2/08, nathan virgil <sdragon1984 at gmail.com> wrote:
>
> Okay, I'm resurrecting this project. I did a little more work on it then
> what you see here, but that ended up getting accidentally deleted, and I
> haven't done anything with Python since.
>
> I'm running into one problem already, and I haven't really added any extra
> code. In the content (at this point, the rooms still have Bob's
> descriptions), the very first line of actual code (third line in the
> program) is returning an error.
>
> Offending code:
>
> # Content
> # retrieve data for current room
> room == start
> while true:
>     if room == start:
>         desc = "Ahead of you, you see a chasm."
>         ques = "Do you wish to try jumping over it? Y/N"
>         destY = 2
>         destN = 3
>
> Error:
>
> Traceback (most recent call last):
>   File "samplegame.py", line 3, in <module>
>     room == start
> NameError: name 'room' is not defined
>
>
> What's going on here?
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/0062840d/attachment.htm>

From ldl08 at gmx.net  Thu Oct  2 16:35:12 2008
From: ldl08 at gmx.net (David)
Date: Thu, 02 Oct 2008 22:35:12 +0800
Subject: [Tutor] syntax error with a simple print command
Message-ID: <48E4DC20.9030408@gmx.net>

Dear list,

I was just trying the following code:

for i in range(0, 10, 2):
     print i
print "done!"

But I do get a syntax error, and I don't understand why:

 >>> for i in range(0, 10, 2):
...     print i
... print "done!"
   File "<stdin>", line 3
     print "done!"
         ^

As far as I understand, the for loop is executed, and once the loop is 
done Python exits the for loop and continues with the next command 
(print "done!").
Why is he complaining??

Many thanks for enlightening me!

David

From rabidpoobear at gmail.com  Thu Oct  2 16:42:21 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 09:42:21 -0500
Subject: [Tutor] syntax error with a simple print command
In-Reply-To: <48E4DC20.9030408@gmx.net>
References: <48E4DC20.9030408@gmx.net>
Message-ID: <dfeb4470810020742v5a2fe252h5fa587beafd1e658@mail.gmail.com>

You are having an issue with the interpreter.  You can only submit 1 command
at a time to the interpreter.
Therefore, you need to finish your for loop and hit enter *twice* so that
the interpreter knows you're done with the loop.
The reason you're getting an error is it's trying to put your "print
'done!'" statement in the for loop, but it's not tabbed correctly.
it works like this because otherwise you could only have single-line for
loops!

On Thu, Oct 2, 2008 at 9:35 AM, David <ldl08 at gmx.net> wrote:

> Dear list,
>
> I was just trying the following code:
>
> for i in range(0, 10, 2):
>    print i
> print "done!"
>
> But I do get a syntax error, and I don't understand why:
>
> >>> for i in range(0, 10, 2):
> ...     print i
> ... print "done!"
>  File "<stdin>", line 3
>    print "done!"
>        ^
>
> As far as I understand, the for loop is executed, and once the loop is done
> Python exits the for loop and continues with the next command (print
> "done!").
> Why is he complaining??
>
> Many thanks for enlightening me!
>
> David
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/d175ae11/attachment.htm>

From rabidpoobear at gmail.com  Thu Oct  2 16:43:41 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 09:43:41 -0500
Subject: [Tutor] syntax error with a simple print command
In-Reply-To: <dfeb4470810020742v5a2fe252h5fa587beafd1e658@mail.gmail.com>
References: <48E4DC20.9030408@gmx.net>
	<dfeb4470810020742v5a2fe252h5fa587beafd1e658@mail.gmail.com>
Message-ID: <dfeb4470810020743j20a98a4ds7eae2c5cf3e630f9@mail.gmail.com>

note that I meant it's not tabbed correctly *to be part of the for loop*.

On Thu, Oct 2, 2008 at 9:42 AM, Luke Paireepinart <rabidpoobear at gmail.com>wrote:

> You are having an issue with the interpreter.  You can only submit 1
> command at a time to the interpreter.
> Therefore, you need to finish your for loop and hit enter *twice* so that
> the interpreter knows you're done with the loop.
> The reason you're getting an error is it's trying to put your "print
> 'done!'" statement in the for loop, but it's not tabbed correctly.
> it works like this because otherwise you could only have single-line for
> loops!
>
>
> On Thu, Oct 2, 2008 at 9:35 AM, David <ldl08 at gmx.net> wrote:
>
>> Dear list,
>>
>> I was just trying the following code:
>>
>> for i in range(0, 10, 2):
>>    print i
>> print "done!"
>>
>> But I do get a syntax error, and I don't understand why:
>>
>> >>> for i in range(0, 10, 2):
>> ...     print i
>> ... print "done!"
>>  File "<stdin>", line 3
>>    print "done!"
>>        ^
>>
>> As far as I understand, the for loop is executed, and once the loop is
>> done Python exits the for loop and continues with the next command (print
>> "done!").
>> Why is he complaining??
>>
>> Many thanks for enlightening me!
>>
>> David
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/b172cadf/attachment.htm>

From bgailer at gmail.com  Thu Oct  2 17:21:20 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 02 Oct 2008 11:21:20 -0400
Subject: [Tutor] sample python twill scripts?
In-Reply-To: <1222882128.6536.7.camel@jeremiah-laptop>
References: <1222882128.6536.7.camel@jeremiah-laptop>
Message-ID: <48E4E6F0.7010206@gmail.com>

jeremiah wrote:
> Just wondering if anyone here would be interested in sharing a python
> twill script?  I'd just like to take a gander at how others are
> engineering their scripts.
>   

twill?



-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From davholla2002 at yahoo.co.uk  Thu Oct  2 17:31:20 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Thu, 2 Oct 2008 15:31:20 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
Message-ID: <20968.87683.qm@web25608.mail.ukl.yahoo.com>

I am using python 2.5.2.? Is there an alternative to idle that does not have this problem?
(I also fixed that this was no longer a problem).



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/f6efd98f/attachment.htm>

From davholla2002 at yahoo.co.uk  Thu Oct  2 17:55:25 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Thu, 2 Oct 2008 15:55:25 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <dfeb4470810020853n3a416fc3wbbd0fdcadfd87a72@mail.gmail.com>
Message-ID: <599220.95240.qm@web25603.mail.ukl.yahoo.com>

No that does not work.? When I click on idle it just does not open - very annoying.

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
From: Luke Paireepinart <rabidpoobear at gmail.com>
Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org
Date: Thursday, 2 October, 2008, 4:53 PM



On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:


I am using python 2.5.2.? Is there an alternative to idle that does not have this problem?
(I also fixed that this was no longer a problem).






      Open IDLE without using the "edit with IDLE" link.
Or use a different editor. 




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/46ceefdb/attachment.htm>

From rabidpoobear at gmail.com  Thu Oct  2 17:53:46 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 10:53:46 -0500
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <20968.87683.qm@web25608.mail.ukl.yahoo.com>
References: <20968.87683.qm@web25608.mail.ukl.yahoo.com>
Message-ID: <dfeb4470810020853n3a416fc3wbbd0fdcadfd87a72@mail.gmail.com>

On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:

> I am using python 2.5.2.  Is there an alternative to idle that does not
> have this problem?
> (I also fixed that this was no longer a problem).
>
> Open IDLE without using the "edit with IDLE" link.
Or use a different editor.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/e17203eb/attachment.htm>

From rabidpoobear at gmail.com  Thu Oct  2 18:01:56 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 11:01:56 -0500
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <599220.95240.qm@web25603.mail.ukl.yahoo.com>
References: <dfeb4470810020853n3a416fc3wbbd0fdcadfd87a72@mail.gmail.com>
	<599220.95240.qm@web25603.mail.ukl.yahoo.com>
Message-ID: <dfeb4470810020901l44da91d6g404fc65e324d6683@mail.gmail.com>

Where are you running it from?  it needs some weird command line parameters,
so you probably need to use the shortcut in the start bar that Python made
for you.

On Thu, Oct 2, 2008 at 10:55 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:

> No that does not work.  When I click on idle it just does not open - very
> annoying.
>
> --- On *Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com>* wrote:
>
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: davholla2002 at yahoo.co.uk
> Cc: tutor at python.org
> Date: Thursday, 2 October, 2008, 4:53 PM
>
>
>
>
> On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:
>
>>  I am using python 2.5.2.  Is there an alternative to idle that does not
>> have this problem?
>> (I also fixed that this was no longer a problem).
>>
>> Open IDLE without using the "edit with IDLE" link.
> Or use a different editor.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/8802b018/attachment.htm>

From davholla2002 at yahoo.co.uk  Thu Oct  2 18:31:42 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Thu, 2 Oct 2008 16:31:42 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <dfeb4470810020901l44da91d6g404fc65e324d6683@mail.gmail.com>
Message-ID: <483364.96146.qm@web25606.mail.ukl.yahoo.com>

I just using the short cut and nothing happens :(.

I have managed to do this before just not in my new job

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
From: Luke Paireepinart <rabidpoobear at gmail.com>
Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org
Date: Thursday, 2 October, 2008, 5:01 PM

Where are you running it from?? it needs some weird command line parameters, so you probably need to use the shortcut in the start bar that Python made for you.

On Thu, Oct 2, 2008 at 10:55 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:


No that does not work.? When I click on idle it just does not open - very annoying.

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:

From: Luke Paireepinart <rabidpoobear at gmail.com>

Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org

Date: Thursday, 2 October, 2008, 4:53 PM



On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:




I am using python 2.5.2.? Is there an alternative to idle that does not have this problem?
(I also fixed that this was no longer a problem).







      Open IDLE without using the "edit with IDLE" link.
Or use a different editor. 






      




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/f377cbe3/attachment.htm>

From rabidpoobear at gmail.com  Thu Oct  2 18:33:33 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 11:33:33 -0500
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <483364.96146.qm@web25606.mail.ukl.yahoo.com>
References: <dfeb4470810020901l44da91d6g404fc65e324d6683@mail.gmail.com>
	<483364.96146.qm@web25606.mail.ukl.yahoo.com>
Message-ID: <dfeb4470810020933o31956921h72f1c9820ea31e77@mail.gmail.com>

Try installing pythonwin, it's an editor by the guy that made the win32all
extensions.
Or use eclipse with Python plugin, maybe?

On Thu, Oct 2, 2008 at 11:31 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:

> I just using the short cut and nothing happens :(.
>
> I have managed to do this before just not in my new job
>
> --- On *Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com>* wrote:
>
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: davholla2002 at yahoo.co.uk
> Cc: tutor at python.org
> Date: Thursday, 2 October, 2008, 5:01 PM
>
>
> Where are you running it from?  it needs some weird command line
> parameters, so you probably need to use the shortcut in the start bar that
> Python made for you.
>
> On Thu, Oct 2, 2008 at 10:55 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:
>
>> No that does not work.  When I click on idle it just does not open - very
>> annoying.
>>
>> --- On *Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com>* wrote:
>>
>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>> Subject: Re: [Tutor] Idle and windows XP firewall
>> To: davholla2002 at yahoo.co.uk
>> Cc: tutor at python.org
>> Date: Thursday, 2 October, 2008, 4:53 PM
>>
>>
>>
>>
>> On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk>wrote:
>>
>>>  I am using python 2.5.2.  Is there an alternative to idle that does not
>>> have this problem?
>>> (I also fixed that this was no longer a problem).
>>>
>>> Open IDLE without using the "edit with IDLE" link.
>> Or use a different editor.
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/c5abc2fc/attachment-0001.htm>

From rabidpoobear at gmail.com  Thu Oct  2 18:51:25 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 11:51:25 -0500
Subject: [Tutor] syntax error with a simple print command
In-Reply-To: <48E4FA0F.2020002@gmx.net>
References: <48E4DC20.9030408@gmx.net>
	<dfeb4470810020742v5a2fe252h5fa587beafd1e658@mail.gmail.com>
	<48E4FA0F.2020002@gmx.net>
Message-ID: <dfeb4470810020951u2aa55192i362366d820e28dcd@mail.gmail.com>

On Thu, Oct 2, 2008 at 11:42 AM, David <ldl08 at gmx.net> wrote:

> Thanks, Luke, that makes sense.
>
This is only applicable to the interpreter, though.  It's perfectly legal to
have a statement on the line immediately following a loop when you're
writing code files.

Also, please use "reply all" or "reply to group" so that it goes back to the
mailing list, so that people reading the archives and such can see your
reply, and other people know that you understand the issue and don't need
further assistance.  Everyone forgets once in a while, so we just try to
remind each other.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/070aaea9/attachment.htm>

From davholla2002 at yahoo.co.uk  Thu Oct  2 19:00:30 2008
From: davholla2002 at yahoo.co.uk (David Holland)
Date: Thu, 2 Oct 2008 17:00:30 +0000 (GMT)
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <dfeb4470810020933o31956921h72f1c9820ea31e77@mail.gmail.com>
Message-ID: <500412.53696.qm@web25601.mail.ukl.yahoo.com>

That works thanks

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
From: Luke Paireepinart <rabidpoobear at gmail.com>
Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org
Date: Thursday, 2 October, 2008, 5:33 PM

Try installing pythonwin, it's an editor by the guy that made the win32all extensions.
Or use eclipse with Python plugin, maybe?

On Thu, Oct 2, 2008 at 11:31 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:


I just using the short cut and nothing happens :(.

I have managed to do this before just not in my new job

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:

From: Luke Paireepinart <rabidpoobear at gmail.com>

Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org

Date: Thursday, 2 October, 2008, 5:01 PM

Where are you running it from?? it needs some weird command line parameters, so you probably need to use the shortcut in the start bar that Python made for you.


On Thu, Oct 2, 2008 at 10:55 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:



No that does not work.? When I click on idle it just does not open - very annoying.

--- On Thu, 2/10/08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:


From: Luke Paireepinart <rabidpoobear at gmail.com>


Subject: Re: [Tutor] Idle and windows XP firewall
To: davholla2002 at yahoo.co.uk
Cc: tutor at python.org


Date: Thursday, 2 October, 2008, 4:53 PM



On Thu, Oct 2, 2008 at 10:31 AM, David Holland <davholla2002 at yahoo.co.uk> wrote:






I am using python 2.5.2.? Is there an alternative to idle that does not have this problem?
(I also fixed that this was no longer a problem).








      Open IDLE without using the "edit with IDLE" link.
Or use a different editor. 






      






      




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/2ab00803/attachment.htm>

From ldl08 at gmx.net  Thu Oct  2 19:06:29 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 01:06:29 +0800
Subject: [Tutor] dealing with user input whose value I don't know
Message-ID: <48E4FF95.6070803@gmx.net>

Hello,

I am trying to do some exercises in John Zelle's book (chapter 4).
I got stuck:

"Write a program that finds the average of a series of numbers entered 
by the user. The program should first ask the user how many numbers 
there are. Note: the average should always be a float, even if the user 
inputs are all ints."

Okay, I can ask how many number are to be added:

numbers = input("How many number do you want me to calculate? ")

If I then get a reply, say "5", what I would have to do next is to ask 
for the five numbers so that I can calculate the average.
But given that I don't know the the value of 'numbers' ex ante, how 
could I ask for the right amount of numbers?
I don't see how this can be achieved with the tools I have learned so far...
I am currently thinking along the lines of

ans1, ans2 = input("Enter the numbers separated by a comma: ")
average = (ans1 + ans2) / 2.0

But as I say - I don't know how many assignment there have to be, nor do 
I know how Python could then create these assignments.

It would be great if someone could guide me towards the right track!!

Thanks,

David

From rabidpoobear at gmail.com  Thu Oct  2 19:06:55 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 12:06:55 -0500
Subject: [Tutor] Idle and windows XP firewall
In-Reply-To: <500412.53696.qm@web25601.mail.ukl.yahoo.com>
References: <dfeb4470810020933o31956921h72f1c9820ea31e77@mail.gmail.com>
	<500412.53696.qm@web25601.mail.ukl.yahoo.com>
Message-ID: <dfeb4470810021006y7836099peba76e8cd396eaf8@mail.gmail.com>

On Thu, Oct 2, 2008 at 12:00 PM, David Holland <davholla2002 at yahoo.co.uk> wrote:
>
> That works thanks
>
You should send e-mails to the list in plaintext, because it's really
hard to reply to your e-mails in HTML mode.
I mean, it's not hard for me to convert them, but it's just one of
those minor nuisances that may cause some people to decide they don't
want to reply that much, when it's hard to get the formatting right.
Or maybe that's just me.
Anyway, I hope you like PythonWin.  If not, there are countless
threads on here about which IDE is the best, and you can look on the
online mailing list archive at activestate or gmane if you want to
check out some of those threads.  We probably don't need to have that
discussion again right now, though.

From rabidpoobear at gmail.com  Thu Oct  2 19:11:39 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 2 Oct 2008 12:11:39 -0500
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E4FF95.6070803@gmx.net>
References: <48E4FF95.6070803@gmx.net>
Message-ID: <dfeb4470810021011p64aadde1xd984cb68af48123e@mail.gmail.com>

On Thu, Oct 2, 2008 at 12:06 PM, David <ldl08 at gmx.net> wrote:
> Hello,
>
> I am trying to do some exercises in John Zelle's book (chapter 4).
> I got stuck:
>
> "Write a program that finds the average of a series of numbers entered by
> the user. The program should first ask the user how many numbers there are.
> Note: the average should always be a float, even if the user inputs are all
> ints."
>
> Okay, I can ask how many number are to be added:
>
> numbers = input("How many number do you want me to calculate? ")
>
> If I then get a reply, say "5", what I would have to do next is to ask for
> the five numbers so that I can calculate the average.
> But given that I don't know the the value of 'numbers' ex ante, how could I
> ask for the right amount of numbers?
> I don't see how this can be achieved with the tools I have learned so far...
> I am currently thinking along the lines of
>
> ans1, ans2 = input("Enter the numbers separated by a comma: ")
> average = (ans1 + ans2) / 2.0
>
> But as I say - I don't know how many assignment there have to be, nor do I
> know how Python could then create these assignments.

This is a common issue beginners to programming have.
The question you ask yourself here is " do I really need a direct
reference in code to all my values?"
It appears to me that you don't.
For example, how would you do this in real life?
would you say
x = num1
x2 = num2
x3 = num3
 ...
xn = numn

x + x2 + x3 + x4 ... + xn / n

or would you do this:

1 + 2 + 3 + 4 + 5 / count

I would do the latter.
It's the same way in programming.

You can create these generic collections of items in Python.  They are
called "lists."
I'm a little pressed for time (i have a class starting in a few
minutes) but this example should hopefully spark something in 'ya.

a = []
b = [1,2,3,4,5]
for item in b:
   a.append(item)

Does that give you a hint about how you can add items to a collection
without caring how many you have?
Note that you can also do something like this (this is a bigger hint)
a = []
b = [1,2,3,4,5]
for i in range(len(b)):
    a.append(b[i])

Good luck!

>
> It would be great if someone could guide me towards the right track!!
>
> Thanks,
>
> David
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From steve at alchemy.com  Thu Oct  2 19:12:38 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 10:12:38 -0700
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E4FF95.6070803@gmx.net>
References: <48E4FF95.6070803@gmx.net>
Message-ID: <20081002171238.GC98291@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 01:06:29AM +0800, David wrote:
> Hello,
> 
> I am trying to do some exercises in John Zelle's book (chapter 4).
> I got stuck:
> 
> Okay, I can ask how many number are to be added:
> 
> numbers = input("How many number do you want me to calculate? ")
> 
> If I then get a reply, say "5", what I would have to do next is to ask 
> for the five numbers so that I can calculate the average.
> But given that I don't know the the value of 'numbers' ex ante, how 
> could I ask for the right amount of numbers?

You don't need to know in advance what the value of <numbers> 
will be.  You can have Python iterate <number> times, asking
for an additional number each time.

You could add each to a variable (so it accumulates the sum
as you iterate) and then divide by <number>.  You could collect
everything in a list and then do the calculation.

There's a couple of ideas.  See where that leads you and let
us know.


-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From christopher.henk at allisontransmission.com  Thu Oct  2 19:22:50 2008
From: christopher.henk at allisontransmission.com (christopher.henk at allisontransmission.com)
Date: Thu, 2 Oct 2008 13:22:50 -0400
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E4FF95.6070803@gmx.net>
Message-ID: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>

tutor-bounces+christopher.henk=allisontransmission.com at python.org wrote on 
10/02/2008 01:06:29 PM:

> Hello,
> 
> I am trying to do some exercises in John Zelle's book (chapter 4).
> I got stuck:
> 
> "Write a program that finds the average of a series of numbers entered 
> by the user. The program should first ask the user how many numbers 
> there are. Note: the average should always be a float, even if the user 
> inputs are all ints."
> 
> Okay, I can ask how many number are to be added:
> 
> numbers = input("How many number do you want me to calculate? ")

        you should really use raw_input to get the info from the user, and 
then convert it to a number.
        numbers=int(raw_input("How many number do you want me to 
calculate? "))

> 
> If I then get a reply, say "5", what I would have to do next is to ask 
> for the five numbers so that I can calculate the average.

        Write the code like you knew it was going to be a 5 and then 
replace anywhere the 5 appears with the variable 'numbers'.



> But given that I don't know the the value of 'numbers' ex ante, how 
> could I ask for the right amount of numbers?
> I don't see how this can be achieved with the tools I have learned so 
far...

        Looking at the table of contents it looks like you should have 
learned about loops by now.



> I am currently thinking along the lines of
> 
> ans1, ans2 = input("Enter the numbers separated by a comma: ")
> average = (ans1 + ans2) / 2.0

        have each number be its own input and repeat it depending on how 
their input for numbers, and then do the averaging at the end.

> 
> But as I say - I don't know how many assignment there have to be, nor do 

> I know how Python could then create these assignments.
> 
        you don't need to keep the individual numbers only the sum, but if 
you want to, use a list and append each new number to the end of the list.

> It would be great if someone could guide me towards the right track!!
> 
> Thanks,
> 
> David
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/5151b259/attachment-0001.htm>

From ldl08 at gmx.net  Thu Oct  2 19:38:48 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 01:38:48 +0800
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
Message-ID: <48E50728.8020605@gmx.net>

Hello Christopher,

christopher.henk at allisontransmission.com wrote:

>  >
>  > Okay, I can ask how many number are to be added:
>  >
>  > numbers = input("How many number do you want me to calculate? ")
> 
>         you should really use raw_input to get the info from the user, 
> and then convert it to a number.
>         numbers=int(raw_input("How many number do you want me to 
> calculate? "))

Does that mean input() is obsolete (after all, Zelle's book is not the 
freshest on the shelf)? Or do they have different uses?

Thanks,

David

From glenuk at gmail.com  Thu Oct  2 19:40:46 2008
From: glenuk at gmail.com (Glen Clark)
Date: Thu, 2 Oct 2008 18:40:46 +0100
Subject: [Tutor] Multiple windows in Tkinter
Message-ID: <bc0c68550810021040v1a1cd63brd90ea47c556ef457@mail.gmail.com>

Hello,

I am a little confused how multi-windows work in Tkinter. I am currently
using it while learning to program. Using it for single window apps/scripts
is fine. However what I dont understand is:

What is toplevel? Is it the same as Tk()? Do I initialise a root using Tk()
and then use toplevel for any other windows? How do I switch between the
Windows? And while I am on the subject what is a frame and why should I use
it? atm the moment it just seems to be the same as Tk()?

Many thanks for any advice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/6951d8bc/attachment.htm>

From steve at alchemy.com  Thu Oct  2 19:49:11 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 10:49:11 -0700
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E50728.8020605@gmx.net>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
Message-ID: <20081002174911.GF98291@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
> Does that mean input() is obsolete (after all, Zelle's book is not the 
> freshest on the shelf)? Or do they have different uses?

Depends on how you look at it.

input() automatically evaluates whatever the user types as a Python
expression and returns the result.  So if they type 5, the integer
5 is returned.  For your program, that's probably what you want, and
has the advantage of letting you type something like 2+3 so your user
can let Python evaluate math expressions.

On the other hand, you'd think that you could ask a user for a text
response using input():
   name = input("What is your name? ")
   print "Hello, ", name

But if they just type the answer, Python will crash with an error
because it's expecting a legal Python expression there (so a 
string value would have to be typed in quotes).

However, raw_input() will just return the characters the user typed
without doing anything to them.  Great for string values, but this
means to get an integer result you'll have to pass that into the
int() constructor function.

IIRC Python 3.0 will actually make input() do what raw_input() today
does, because this is confusing to people as it stands now.

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From bill at celestial.net  Thu Oct  2 19:54:56 2008
From: bill at celestial.net (Bill Campbell)
Date: Thu, 2 Oct 2008 10:54:56 -0700
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <20081002174911.GF98291@dragon.alchemy.com>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
	<20081002174911.GF98291@dragon.alchemy.com>
Message-ID: <20081002175456.GA26406@ayn.mi.celestial.com>

On Thu, Oct 02, 2008, Steve Willoughby wrote:
>On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
>> Does that mean input() is obsolete (after all, Zelle's book is not the 
>> freshest on the shelf)? Or do they have different uses?
>
>Depends on how you look at it.
>
>input() automatically evaluates whatever the user types as a Python
>expression and returns the result.  So if they type 5, the integer
>5 is returned.  For your program, that's probably what you want, and
>has the advantage of letting you type something like 2+3 so your user
>can let Python evaluate math expressions.
>
>On the other hand, you'd think that you could ask a user for a text
>response using input():
>   name = input("What is your name? ")
>   print "Hello, ", name
>
>But if they just type the answer, Python will crash with an error
>because it's expecting a legal Python expression there (so a 
>string value would have to be typed in quotes).

Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
for validity, and use methods that prevent malicious strings from
allowing the user to get unauthorized access or change things
they shouldn't.

Many of the common exploits of web pages are the result of poor
checking of input resulting in sql injection attacks, and other
breaches.

Bill
-- 
INTERNET:   bill at celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186

There are three kinds of men. The ones that learn by reading. The few who
learn by observation.  The rest of them have to pee on the electric fence
for themselves. -- Will Rogers

From ldl08 at gmx.net  Thu Oct  2 20:06:47 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 02:06:47 +0800
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <20081002175456.GA26406@ayn.mi.celestial.com>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>	<48E50728.8020605@gmx.net>	<20081002174911.GF98291@dragon.alchemy.com>
	<20081002175456.GA26406@ayn.mi.celestial.com>
Message-ID: <48E50DB7.8030704@gmx.net>

Cheers for the insights!

However, I just found out that changing input() to raw_input() breaks my 
code:

This program takes the average of numbers you supply!!
How many numbers do you want me to work with? 2
You want me to take the average of 2 numbers.
Please type the numbers, separated by commas: 1,2
You want to know the average of the numbers: 1,2
Traceback (most recent call last):
  File "avgInput.py", line 13, in <module>
    add = add + i
TypeError: unsupported operand type(s) for +: 'int' and 'str'

**** End of process output ****

The reason being, I take, that

numbers = raw_input("Please type the numbers, separated by commas: ")

also returns the comma (1,2) and thus the for loop can't cope...
So should I therefore retain

numbers = input("Please type the numbers, separated by commas: ") ?

Otherwise I don't know (yet) what to do....

David


Bill Campbell wrote:
> On Thu, Oct 02, 2008, Steve Willoughby wrote:
>   
>> On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
>>     
>>> Does that mean input() is obsolete (after all, Zelle's book is not the 
>>> freshest on the shelf)? Or do they have different uses?
>>>       
>> Depends on how you look at it.
>>
>> input() automatically evaluates whatever the user types as a Python
>> expression and returns the result.  So if they type 5, the integer
>> 5 is returned.  For your program, that's probably what you want, and
>> has the advantage of letting you type something like 2+3 so your user
>> can let Python evaluate math expressions.
>>
>> On the other hand, you'd think that you could ask a user for a text
>> response using input():
>>   name = input("What is your name? ")
>>   print "Hello, ", name
>>
>> But if they just type the answer, Python will crash with an error
>> because it's expecting a legal Python expression there (so a 
>> string value would have to be typed in quotes).
>>     
>
> Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
> for validity, and use methods that prevent malicious strings from
> allowing the user to get unauthorized access or change things
> they shouldn't.
>
> Many of the common exploits of web pages are the result of poor
> checking of input resulting in sql injection attacks, and other
> breaches.
>
> Bill
>   


From steve at alchemy.com  Thu Oct  2 20:13:03 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 11:13:03 -0700
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <20081002175456.GA26406@ayn.mi.celestial.com>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
	<20081002174911.GF98291@dragon.alchemy.com>
	<20081002175456.GA26406@ayn.mi.celestial.com>
Message-ID: <20081002181303.GG98291@dragon.alchemy.com>

On Thu, Oct 02, 2008 at 10:54:56AM -0700, Bill Campbell wrote:
> Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
> for validity, and use methods that prevent malicious strings from
> allowing the user to get unauthorized access or change things
> they shouldn't.

Yes, I probably should have qualified what I said.  This is
VERY important.  Should you ever allow input() or other eval()
of what the user typed (or for that matter, passing what the
user types into file operations, SQL queries, etc)?  Yes, but
*only* if you are *certain* you *must* and that you know exactly
what you're doing.  And probably not even then if you can 
avoid it.

So the point was what the difference was between raw_input()
and input(), but Bill's right, don't just use input() or
eval() (and input() is essentially eval(raw_input())) casually.

Not sure why?

Suppose you put a program up for public use which gets a
string value using input().  Instead of

  How many numbers? 5

the user types:

  How many numbers? os.system('rm -rf /')

Don't ever assume data is safe or valid if it came from 
outside your realm of control.

(And don't fool yourself that a script is "just for me", in 
most environments things get reused in ways you don't expect, 
and even if not, get used to good programming habits).

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From steve at alchemy.com  Thu Oct  2 20:14:49 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 11:14:49 -0700
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E50DB7.8030704@gmx.net>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
	<20081002174911.GF98291@dragon.alchemy.com>
	<20081002175456.GA26406@ayn.mi.celestial.com>
	<48E50DB7.8030704@gmx.net>
Message-ID: <20081002181449.GH98291@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 02:06:47AM +0800, David wrote:
> Cheers for the insights!
> 
> However, I just found out that changing input() to raw_input() breaks my 
> code:

Recall that we told you raw_input() returns a string, while
input() returns an integer if you typed an integer value.

So you need to convert the string of characters the user typed
into an integer value before using it as a number:

numbers = int(raw_input(...))


> 
> This program takes the average of numbers you supply!!
> How many numbers do you want me to work with? 2
> You want me to take the average of 2 numbers.
> Please type the numbers, separated by commas: 1,2
> You want to know the average of the numbers: 1,2
> Traceback (most recent call last):
>  File "avgInput.py", line 13, in <module>
>    add = add + i
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
> 
> **** End of process output ****
> 
> The reason being, I take, that
> 
> numbers = raw_input("Please type the numbers, separated by commas: ")
> 
> also returns the comma (1,2) and thus the for loop can't cope...
> So should I therefore retain
> 
> numbers = input("Please type the numbers, separated by commas: ") ?
> 
> Otherwise I don't know (yet) what to do....
> 
> David
> 
> 
> Bill Campbell wrote:
> >On Thu, Oct 02, 2008, Steve Willoughby wrote:
> >  
> >>On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
> >>    
> >>>Does that mean input() is obsolete (after all, Zelle's book is not the 
> >>>freshest on the shelf)? Or do they have different uses?
> >>>      
> >>Depends on how you look at it.
> >>
> >>input() automatically evaluates whatever the user types as a Python
> >>expression and returns the result.  So if they type 5, the integer
> >>5 is returned.  For your program, that's probably what you want, and
> >>has the advantage of letting you type something like 2+3 so your user
> >>can let Python evaluate math expressions.
> >>
> >>On the other hand, you'd think that you could ask a user for a text
> >>response using input():
> >>  name = input("What is your name? ")
> >>  print "Hello, ", name
> >>
> >>But if they just type the answer, Python will crash with an error
> >>because it's expecting a legal Python expression there (so a 
> >>string value would have to be typed in quotes).
> >>    
> >
> >Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
> >for validity, and use methods that prevent malicious strings from
> >allowing the user to get unauthorized access or change things
> >they shouldn't.
> >
> >Many of the common exploits of web pages are the result of poor
> >checking of input resulting in sql injection attacks, and other
> >breaches.
> >
> >Bill
> >  
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From christopher.henk at allisontransmission.com  Thu Oct  2 20:21:11 2008
From: christopher.henk at allisontransmission.com (christopher.henk at allisontransmission.com)
Date: Thu, 2 Oct 2008 14:21:11 -0400
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E50DB7.8030704@gmx.net>
Message-ID: <OFBB45D2FD.52AA0216-ON852574D6.0063E3B9-852574D6.0064D0FF@gm.com>

I am not sure how you got from the input to your variable i, it is a good 
idea to post your code as well.

That said raw_input will return the user's input as a string which you 
then need to convert to integers.
So the commas are brought in as well.
You can solve this in a couple of ways:
First, you can split the string on the commas and get a list of strings 
each representing one of the numbers.

        numberlist=numbers.splt(",")
will give you: 
        numberslist=["1","2"]
which you can then loop over and convert to integers and add up.

Secondly, you can have the users input the numbers one at a time inside 
the loop.
add = add + int(raw_input("Please type the next number:"))

Chris





David <ldl08 at gmx.net> 
Sent by: tutor-bounces+christopher.henk=allisontransmission.com at python.org
10/02/2008 02:06 PM

To
tutor at python.org, 
tutor-bounces+christopher.henk=allisontransmission.com at python.org
cc

Subject
Re: [Tutor] dealing with user input whose value I don't know






Cheers for the insights!

However, I just found out that changing input() to raw_input() breaks my 
code:

This program takes the average of numbers you supply!!
How many numbers do you want me to work with? 2
You want me to take the average of 2 numbers.
Please type the numbers, separated by commas: 1,2
You want to know the average of the numbers: 1,2
Traceback (most recent call last):
  File "avgInput.py", line 13, in <module>
    add = add + i
TypeError: unsupported operand type(s) for +: 'int' and 'str'

**** End of process output ****

The reason being, I take, that

numbers = raw_input("Please type the numbers, separated by commas: ")

also returns the comma (1,2) and thus the for loop can't cope...
So should I therefore retain

numbers = input("Please type the numbers, separated by commas: ") ?

Otherwise I don't know (yet) what to do....

David


Bill Campbell wrote:
> On Thu, Oct 02, 2008, Steve Willoughby wrote:
> 
>> On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
>> 
>>> Does that mean input() is obsolete (after all, Zelle's book is not the 

>>> freshest on the shelf)? Or do they have different uses?
>>> 
>> Depends on how you look at it.
>>
>> input() automatically evaluates whatever the user types as a Python
>> expression and returns the result.  So if they type 5, the integer
>> 5 is returned.  For your program, that's probably what you want, and
>> has the advantage of letting you type something like 2+3 so your user
>> can let Python evaluate math expressions.
>>
>> On the other hand, you'd think that you could ask a user for a text
>> response using input():
>>   name = input("What is your name? ")
>>   print "Hello, ", name
>>
>> But if they just type the answer, Python will crash with an error
>> because it's expecting a legal Python expression there (so a 
>> string value would have to be typed in quotes).
>> 
>
> Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
> for validity, and use methods that prevent malicious strings from
> allowing the user to get unauthorized access or change things
> they shouldn't.
>
> Many of the common exploits of web pages are the result of poor
> checking of input resulting in sql injection attacks, and other
> breaches.
>
> Bill
> 

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/7e99b2e1/attachment-0001.htm>

From ldl08 at gmx.net  Thu Oct  2 20:23:48 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 02:23:48 +0800
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <20081002181449.GH98291@dragon.alchemy.com>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
	<20081002174911.GF98291@dragon.alchemy.com>
	<20081002175456.GA26406@ayn.mi.celestial.com>
	<48E50DB7.8030704@gmx.net>
	<20081002181449.GH98291@dragon.alchemy.com>
Message-ID: <48E511B4.1000500@gmx.net>

Hello Steve,

thanks for all your help and comments.

What happens, though, is that with

numbers = int(raw_input("Please type the numbers, separated by commas: "))

my code is still defunct (whereas input() works):

Please type the numbers, separated by commas: 1,2
Traceback (most recent call last):
  File "avgInput.py", line 8, in <module>
    numbers = int(raw_input("Please type the numbers, separated by 
commas: "))
ValueError: invalid literal for int() with base 10: '1,2'

**** End of process output ****


Here is the entire code:

print "This program takes the average of numbers you supply!!"
amount = raw_input("How many numbers do you want me to work with? ")
print "You want me to take the average of", amount, "numbers."
numbers = int(raw_input("Please type the numbers, separated by commas: "))
print "You want to know the average of the numbers:", numbers

add = 0
for i in numbers:
    add = add + i
print "The sum of your numbers is:", add
average = add / float(amount)
print "Therefore the average of your numbers is", average


David



Steve Willoughby wrote:
> On Fri, Oct 03, 2008 at 02:06:47AM +0800, David wrote:
>   
>> Cheers for the insights!
>>
>> However, I just found out that changing input() to raw_input() breaks my 
>> code:
>>     
>
> Recall that we told you raw_input() returns a string, while
> input() returns an integer if you typed an integer value.
>
> So you need to convert the string of characters the user typed
> into an integer value before using it as a number:
>
> numbers = int(raw_input(...))
>
>
>   
>> This program takes the average of numbers you supply!!
>> How many numbers do you want me to work with? 2
>> You want me to take the average of 2 numbers.
>> Please type the numbers, separated by commas: 1,2
>> You want to know the average of the numbers: 1,2
>> Traceback (most recent call last):
>>  File "avgInput.py", line 13, in <module>
>>    add = add + i
>> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>
>> **** End of process output ****
>>
>> The reason being, I take, that
>>
>> numbers = raw_input("Please type the numbers, separated by commas: ")
>>
>> also returns the comma (1,2) and thus the for loop can't cope...
>> So should I therefore retain
>>
>> numbers = input("Please type the numbers, separated by commas: ") ?
>>
>> Otherwise I don't know (yet) what to do....
>>
>> David
>>
>>
>> Bill Campbell wrote:
>>     
>>> On Thu, Oct 02, 2008, Steve Willoughby wrote:
>>>  
>>>       
>>>> On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
>>>>    
>>>>         
>>>>> Does that mean input() is obsolete (after all, Zelle's book is not the 
>>>>> freshest on the shelf)? Or do they have different uses?
>>>>>      
>>>>>           
>>>> Depends on how you look at it.
>>>>
>>>> input() automatically evaluates whatever the user types as a Python
>>>> expression and returns the result.  So if they type 5, the integer
>>>> 5 is returned.  For your program, that's probably what you want, and
>>>> has the advantage of letting you type something like 2+3 so your user
>>>> can let Python evaluate math expressions.
>>>>
>>>> On the other hand, you'd think that you could ask a user for a text
>>>> response using input():
>>>>  name = input("What is your name? ")
>>>>  print "Hello, ", name
>>>>
>>>> But if they just type the answer, Python will crash with an error
>>>> because it's expecting a legal Python expression there (so a 
>>>> string value would have to be typed in quotes).
>>>>    
>>>>         
>>> Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
>>> for validity, and use methods that prevent malicious strings from
>>> allowing the user to get unauthorized access or change things
>>> they shouldn't.
>>>
>>> Many of the common exploits of web pages are the result of poor
>>> checking of input resulting in sql injection attacks, and other
>>> breaches.
>>>
>>> Bill
>>>  
>>>       
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>     
>
>   


From ldl08 at gmx.net  Thu Oct  2 20:25:01 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 02:25:01 +0800
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <OFBB45D2FD.52AA0216-ON852574D6.0063E3B9-852574D6.0064D0FF@gm.com>
References: <OFBB45D2FD.52AA0216-ON852574D6.0063E3B9-852574D6.0064D0FF@gm.com>
Message-ID: <48E511FD.1010709@gmx.net>

Oh, great, this answers my question!

Thanks!

David


christopher.henk at allisontransmission.com wrote:
>
> I am not sure how you got from the input to your variable i, it is a 
> good idea to post your code as well.
>
> That said raw_input will return the user's input as a string which you 
> then need to convert to integers.
> So the commas are brought in as well.
> You can solve this in a couple of ways:
> First, you can split the string on the commas and get a list of 
> strings each representing one of the numbers.
>
>         numberlist=numbers.splt(",")
> will give you:
>         numberslist=["1","2"]
> which you can then loop over and convert to integers and add up.
>
> Secondly, you can have the users input the numbers one at a time 
> inside the loop.
> add = add + int(raw_input("Please type the next number:"))
>
> Chris
>
>
>
>
> *David <ldl08 at gmx.net>*
> Sent by: 
> tutor-bounces+christopher.henk=allisontransmission.com at python.org
>
> 10/02/2008 02:06 PM
>
> 	
> To
> 	tutor at python.org, 
> tutor-bounces+christopher.henk=allisontransmission.com at python.org
> cc
> 	
> Subject
> 	Re: [Tutor] dealing with user input whose value I don't know
>
>
>
> 	
>
>
>
>
>
> Cheers for the insights!
>
> However, I just found out that changing input() to raw_input() breaks my
> code:
>
> This program takes the average of numbers you supply!!
> How many numbers do you want me to work with? 2
> You want me to take the average of 2 numbers.
> Please type the numbers, separated by commas: 1,2
> You want to know the average of the numbers: 1,2
> Traceback (most recent call last):
>  File "avgInput.py", line 13, in <module>
>    add = add + i
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> **** End of process output ****
>
> The reason being, I take, that
>
> numbers = raw_input("Please type the numbers, separated by commas: ")
>
> also returns the comma (1,2) and thus the for loop can't cope...
> So should I therefore retain
>
> numbers = input("Please type the numbers, separated by commas: ") ?
>
> Otherwise I don't know (yet) what to do....
>
> David
>
>
> Bill Campbell wrote:
> > On Thu, Oct 02, 2008, Steve Willoughby wrote:
> >  
> >> On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote:
> >>    
> >>> Does that mean input() is obsolete (after all, Zelle's book is not 
> the
> >>> freshest on the shelf)? Or do they have different uses?
> >>>      
> >> Depends on how you look at it.
> >>
> >> input() automatically evaluates whatever the user types as a Python
> >> expression and returns the result.  So if they type 5, the integer
> >> 5 is returned.  For your program, that's probably what you want, and
> >> has the advantage of letting you type something like 2+3 so your user
> >> can let Python evaluate math expressions.
> >>
> >> On the other hand, you'd think that you could ask a user for a text
> >> response using input():
> >>   name = input("What is your name? ")
> >>   print "Hello, ", name
> >>
> >> But if they just type the answer, Python will crash with an error
> >> because it's expecting a legal Python expression there (so a
> >> string value would have to be typed in quotes).
> >>    
> >
> > Remember the cardinal rule NEVER TRUST USER INPUT!  Always check
> > for validity, and use methods that prevent malicious strings from
> > allowing the user to get unauthorized access or change things
> > they shouldn't.
> >
> > Many of the common exploits of web pages are the result of poor
> > checking of input resulting in sql injection attacks, and other
> > breaches.
> >
> > Bill
> >  
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


From tsmundahl at comcast.net  Thu Oct  2 23:41:37 2008
From: tsmundahl at comcast.net (tsmundahl at comcast.net)
Date: Thu, 02 Oct 2008 21:41:37 +0000
Subject: [Tutor] Hello again. and another question.
Message-ID: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>

Hello Trask, 

I have been working on the first program. I got the files to read and print out the grades and averages, but when I write these files to the other txt file, all that I get is:

10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0
10.0

I know it is something simple. I am just not seeing it. Here is my code:



Grades = [ ]

filename = raw_input("Enter the filename with 10 grades to be averaged: ")        

my_file_object = open (filename, "r")

for a in range (10):
    temp_string = my_file_object.readline()
    Grades = Grades + [ float (temp_string)]

my_file_object.close()

for a in range (len(Grades)):
    print "Grade", str (a + 1) + ":", Grades [a]

total = 0
for a in range (len(Grades)):
    total = total + Grades[a]

average = total/float (len(Grades))

print "The average grade was: ", round(average,2)
print ""
print "Okay, we are assuming that you have created a file named 'grade_file_2.txt' that is empty, yes?"
print ""

fname= raw_input("Please enter 'grade_file_2.txt' to write to new file: ")

grades_file_2 = open("grade_file_2.txt", "w")

for count in range (len(Grades)):
    grades_file_2.write(str("%.2f"% (len(Grades))) + "\n")       
grades_file_2.close()

print ""
print "Nice Job. your file is done."


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



I am including the files. Let me know if you see anything goofy. 



Tom Mundahl


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 1810 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20081002/1113a35b/attachment.obj>
-------------- next part --------------
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
10.00
-------------- next part --------------
90.50
88.25
98.95
94.90
95.44
96.84
97.99
98.25
99.55
96.88

From steve at alchemy.com  Thu Oct  2 23:48:59 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 14:48:59 -0700
Subject: [Tutor] Hello again. and another question.
In-Reply-To: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>
References: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>
Message-ID: <20081002214859.GJ98291@dragon.alchemy.com>

On Thu, Oct 02, 2008 at 09:41:37PM +0000, tsmundahl at comcast.net wrote:
> for count in range (len(Grades)):
>     grades_file_2.write(str("%.2f"% (len(Grades))) + "\n")       
                                       ^^^^^^^^^^^^

Look at what you're actually writing for each count.
See anything amiss there?


-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From jeff at drinktomi.com  Thu Oct  2 23:49:57 2008
From: jeff at drinktomi.com (Jeff Younker)
Date: Thu, 2 Oct 2008 14:49:57 -0700
Subject: [Tutor] sample python twill scripts?
In-Reply-To: <48E4E6F0.7010206@gmail.com>
References: <1222882128.6536.7.camel@jeremiah-laptop>
	<48E4E6F0.7010206@gmail.com>
Message-ID: <8C10B8DA-7989-41F2-B21A-37C67206EB9A@drinktomi.com>


On Oct 2, 2008, at 8:21 AM, bob gailer wrote:
> jeremiah wrote:
>> Just wondering if anyone here would be interested in sharing a python
>> twill script?  I'd just like to take a gander at how others are
>> engineering their scripts.
>>
>
twill?

Twill is an http client automation tool.  It's used quite a bit for  
performing
functional testing from Python.

- Jeff Younker - jeff at drinktomi.com -



From steve at alchemy.com  Thu Oct  2 23:58:03 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Thu, 2 Oct 2008 14:58:03 -0700
Subject: [Tutor] Hello again. and another question.
In-Reply-To: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>
References: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>
Message-ID: <20081002215803.GK98291@dragon.alchemy.com>

You're doing a good job getting started with
programming here, keep getting the fundamentals
and then learn to refine those concepts over time.

But for future reference, here are some finer 
points for you to keep in mind to improve your
style and get a more Pythonic approach:

On Thu, Oct 02, 2008 at 09:41:37PM +0000, tsmundahl at comcast.net wrote:
> Grades = [ ]

Usually we capitalize class and module names, but not
variables and functions/methods.  

> for a in range (10):
>     temp_string = my_file_object.readline()
>     Grades = Grades + [ float (temp_string)]

Might be more clear here to say

      Grades.append(float(temp_string))

instead of constructing a new list just to use +

You might also want to just read each line in the file
right in the for loop, which allows you to take ANY 
number of lines, not just 10, and makes the code
more concise at the same time:

    for grade in my_file_object:
        Grades.append(float(grade))

> for a in range (len(Grades)):
>     print "Grade", str (a + 1) + ":", Grades [a]

If all you're going to do is to deal with each element
of a list in turn, instead of using an index over the
range of the number of elements, just directly iterate
over the list:

    for a in Grades:
       print "Grade:", a


And one GREAT habit to get into is to always be checking
if Python's built in functions and standard library already
offer something you're doing manually:

> total = 0
> for a in range (len(Grades)):
>     total = total + Grades[a]
> 
> average = total/float (len(Grades))


     average = sum(Grades) / len(Grades)


> fname= raw_input("Please enter 'grade_file_2.txt' to write to new file: ")
> grades_file_2 = open("grade_file_2.txt", "w")

I'm not sure why you're asking them to type in a file name
which you're ignoring and opening grade_file_2.txt anyway?

> for count in range (len(Grades)):
>     grades_file_2.write(str("%.2f"% (len(Grades))) + "\n")       
> grades_file_2.close()

No need to explicitly call str() here, and I suspect print would
be clearer anyway.  And again, note the direct iteration over
Grades:

    for grade in Grades:
        print >>grades_file_2, "%.2f" % grade
    grades_file_2.close()
    

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From john at fouhy.net  Fri Oct  3 00:53:09 2008
From: john at fouhy.net (John Fouhy)
Date: Fri, 3 Oct 2008 11:53:09 +1300
Subject: [Tutor] Multiple windows in Tkinter
In-Reply-To: <bc0c68550810021040v1a1cd63brd90ea47c556ef457@mail.gmail.com>
References: <bc0c68550810021040v1a1cd63brd90ea47c556ef457@mail.gmail.com>
Message-ID: <5e58f2e40810021553l75c4b695ld716e61b379efa56@mail.gmail.com>

2008/10/3 Glen Clark <glenuk at gmail.com>:
> What is toplevel? Is it the same as Tk()? Do I initialise a root using Tk()
> and then use toplevel for any other windows? How do I switch between the
> Windows? And while I am on the subject what is a frame and why should I use
> it? atm the moment it just seems to be the same as Tk()?

The answer to your third question is: Yes.  Toplevel() will create
another window that is managed by your window manager (this is
Explorer if you are using Microsoft Windows).  So you can switch to it
using alt-tab or command-` or whatever.  You can also programmatically
give it focus, although I forget how.

(to say that a widget has "focus" means "if you type on the keyboard,
this widget gets the keypresses")

Frames are containers. The main use for them is to put other widgets
into them for layout purposes.  For example, you might decide to split
your layout into two halves, with some kind of menu in the left, and
content in the right.  To do that, you would create two frames, pack
them left to right, then put the menu into the left frame and your
content into the right frame.

e.g. here is a short program that puts some buttons in the left and
uses them to change the colour of the right-hand frame.
(normally you would do something more complex :-) )

from Tkinter import *

tk = Tk()

# Left frame to hold buttons
left = Frame(tk)
left.pack(side=LEFT, expand=True, fill=Y)

# Right frame to hold display
right = Frame(tk, height=200, width=200)
right.pack(expand=True, fill=BOTH)

# change the colour of the right-hand frame
def changeColour(c):
    def change():
        right.config(background=c)
    return change

# Buttons
colours = ['red', 'green', 'blue', 'yellow']
for c in colours:
    b = Button(left, text=c, command=changeColour(c))
    b.pack(side=TOP, expand=True)

tk.mainloop()

-- 
John.

From alan.gauld at btinternet.com  Fri Oct  3 01:55:44 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 3 Oct 2008 00:55:44 +0100
Subject: [Tutor] dealing with user input whose value I don't know
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>	<48E50728.8020605@gmx.net>	<20081002174911.GF98291@dragon.alchemy.com><20081002175456.GA26406@ayn.mi.celestial.com>
	<48E50DB7.8030704@gmx.net>
Message-ID: <gc3n1u$lrd$1@ger.gmane.org>


"David" <ldl08 at gmx.net> wrote

> However, I just found out that changing input() to raw_input() 
> breaks my code:
>
> You want to know the average of the numbers: 1,2
> Traceback (most recent call last):
>  File "avgInput.py", line 13, in <module>
>    add = add + i
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> **** End of process output ****
>
> numbers = raw_input("Please type the numbers, separated by commas: 
> ")
> numbers = input("Please type the numbers, separated by commas: ") ?

What is happening is a bit more subtle than you think. I think!...

As others have pointed out input() evaluates whatever the user types
as a python expression. Now a list of numbers separated by commas
is, to python, a tuple. So your input version stores the list of 
numbers
as a list(ie. a tuple!) whereas raw_input() stores a string containing
the list of comma separated values.

The solution you have already seen - use string.split(',') to separate
the string into substrings and then convert each substring to an
integer.

As an aside:
What you have done is actually quite a user friendly solution but
I suspect most programmers would have opted to use a loop.
Have you covered loops yet? Specifically a for loop? That would
allow you to read in really long lists of numbers and calculate
the sum as you go.

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



From alan.gauld at btinternet.com  Fri Oct  3 01:57:59 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 3 Oct 2008 00:57:59 +0100
Subject: [Tutor] dealing with user input whose value I don't know
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net>
Message-ID: <gc3n65$m6m$1@ger.gmane.org>


"David" <ldl08 at gmx.net> wrote

> Does that mean input() is obsolete (after all, Zelle's book is not 
> the freshest on the shelf)? Or do they have different uses?

They have different uses and input is very convenient at the >>> 
prompt
or when experimenting but in most cases is the wrong choice for
'production'; code because of its vulnerability to exploitation by
crackers and other malicious (or unintentionally malign) users.

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




From alan.gauld at btinternet.com  Fri Oct  3 02:05:24 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 3 Oct 2008 01:05:24 +0100
Subject: [Tutor] Multiple windows in Tkinter
References: <bc0c68550810021040v1a1cd63brd90ea47c556ef457@mail.gmail.com>
Message-ID: <gc3nk2$nrj$1@ger.gmane.org>

"Glen Clark" <glenuk at gmail.com> wrote

> I am a little confused how multi-windows work in Tkinter. I am 
> currently
> using it while learning to program. Using it for single window 
> apps/scripts
> is fine. However what I dont understand is:
>
> What is toplevel? Is it the same as Tk()?

In any GUI thee is a containment heirarchy of widgets. tk() is the
highest level widget in any application. Top Level is the highest
level widget in a window which is separate from the main
application window. They differ in that you can kill a top level
window without killing the entire application but if you kill the
Tk based window everything should die!

> Do I initialise a root using Tk()

Yes. Tk is what runs the program. The mainloop() function
that organises the events is in Tk() as are several other application
evel methods.

> and then use toplevel for any other windows?

Exactly so.

> How do I switch between the Windows?

Usuially the user does that themselves although you can
do it programmatically by setting focus.

> And while I am on the subject what is a frame

A frame is just a container for other widgets, it helps you
organise your GUI and helps build reusable GUI components
by collecting all the bits onto a single Frame.

> and why should I use it?
> it just seems to be the same as Tk()?

No, they are completely different. A Frame does
not have a mainloop or quit function. And Tk does not
have the ability to set borders, colours etc. And you
cannot create reusable widget collectons using Tk
because you can only have one Tk in an appliation
but you can have many Frames.

HTH,

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



From alan.gauld at btinternet.com  Fri Oct  3 02:16:43 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 3 Oct 2008 01:16:43 +0100
Subject: [Tutor] Hello again. and another question.
References: <100220082141.29307.48E5401100049AEE0000727B221559341404080E0B029A039C9B@comcast.net>
Message-ID: <gc3o99$p8j$1@ger.gmane.org>

<tsmundahl at comcast.net> wrote

> I got the files to read and print out the grades and averages,
> but when I write these files to the other txt file, all that I get 
> is:
>
> 10.0
> 10.0...
> I know it is something simple. I am just not seeing it.

When the output doesn't vary like this you know you must be
writing the wrong value or the same value multiple times.

I'll add several comments on the code but the solution
is in there too...

Grades = [ ]
filename = raw_input("Enter the filename with 10 grades to be 
averaged: ")

my_file_object = open (filename, "r")
for a in range (10):
    temp_string = my_file_object.readline()
    Grades = Grades + [ float (temp_string)]
my_file_object.close()

for a in range (len(Grades)):
    print "Grade", str (a + 1) + ":", Grades [a]

##########
# It would be better to just iterate over Grades:

for index, grade in enumerate(Grades):
    print "Grade", index,":",grade

total = 0
for a in range (len(Grades)):
    total = total + Grades[a]

######
# same here:

for grade in Grades:
    total += grade

average = total/float (len(Grades))


######
# you don't need the float conversion here
because you converted them all to floats
at the beginning.

print "The average grade was: ", round(average,2)
print ""
print "Okay, we are assuming that you have created a file named 
'grade_file_2.txt' that is empty, yes?"
print ""

fname= raw_input("Please enter 'grade_file_2.txt' to write to new 
file: ")
grades_file_2 = open("grade_file_2.txt", "w")

for count in range (len(Grades)):
    grades_file_2.write(str("%.2f"% (len(Grades))) + "\n")

#####
# Notice you are writing len(Grades) which is always 10 - your error!
But...

#####
# and again the for loop, and simplify the output string:

for grade in Grades:
     grades_file_2.write("%.2f\n" % grade)

grades_file_2.close()

////////////////////////////

Python for loops are much more powerful when used
as foreach loops rather than always using indexing.

HTH,


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



From alecwh at gmail.com  Fri Oct  3 00:23:04 2008
From: alecwh at gmail.com (Alec Henriksen)
Date: Thu, 02 Oct 2008 16:23:04 -0600
Subject: [Tutor] How trustworthy are pseudo-random numbers?
Message-ID: <1222986184.6552.8.camel@alecwh-laptop>

Hello list,

How trustworthy is the "randomness" generated by the random module? I
just wrote a script (with the help of some tutors here!) that finds the
largest streak in a series of coin flips.

My collected data:

100 coin flips = 6-7 streak (usually)
1000 coin flips = 10-12 streak (usually)
10000 coin flips = 15-19 streak (usually)
etc etc.

I'm curious, how much can I trust the randomness? I can't really do
100000 coin flips in real life to compare...
-- 
Alec Henriksen <alecwh at gmail.com> @ http://alecwh.com


From tim.peters at gmail.com  Fri Oct  3 07:44:59 2008
From: tim.peters at gmail.com (Tim Peters)
Date: Fri, 3 Oct 2008 01:44:59 -0400
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <1222986184.6552.8.camel@alecwh-laptop>
References: <1222986184.6552.8.camel@alecwh-laptop>
Message-ID: <1f7befae0810022244o5c57a15do4814885bbe826ad0@mail.gmail.com>

[Alec Henriksen]
> How trustworthy is the "randomness" generated by the random module?

Python uses the Mersenne Twister algorithm for generating
pseudo-random numbers, and that's one of the highest-quality methods
known.  You can read more about it, e.g., here:

    http://en.wikipedia.org/wiki/Mersenne_Twister


> I just wrote a script (with the help of some tutors here!) that finds
> the largest streak in a series of coin flips.
>
> My collected data:
>
> 100 coin flips = 6-7 streak (usually)
> 1000 coin flips = 10-12 streak (usually)
> 10000 coin flips = 15-19 streak (usually)
> etc etc.
>
> I'm curious, how much can I trust the randomness?

For this purpose, you can have high confidence -- provided your
program is correct ;-)


> I can't really do 100000 coin flips in real life to compare...

The theoretical expected maximum run length is given by equation (15)
here, with p=0.5 and n=100000:

    http://mathworld.wolfram.com/Run.html

although I'm not certain that coincides with what you mean by "streak".

From ldl08 at gmx.net  Fri Oct  3 09:45:46 2008
From: ldl08 at gmx.net (David)
Date: Fri, 03 Oct 2008 15:45:46 +0800
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <gc3n1u$lrd$1@ger.gmane.org>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>	<48E50728.8020605@gmx.net>	<20081002174911.GF98291@dragon.alchemy.com><20081002175456.GA26406@ayn.mi.celestial.com>	<48E50DB7.8030704@gmx.net>
	<gc3n1u$lrd$1@ger.gmane.org>
Message-ID: <48E5CDAA.9090900@gmx.net>

Hello Alan, dear list members,

Alan Gauld wrote:
> The solution you have already seen - use string.split(',') to separate
> the string into substrings and then convert each substring to an
> integer.
This I have now done by using eval(). But now I wonder whether that is 
actually clever because it is supposed to be similarly problematic as 
the input() function in terms of security. Alternatively I could use 
int() -- would that be the way forward?

Here is the code:

def main():
    import string

    print "This program takes the average of numbers you supply!!"

    amount = raw_input("How many numbers do you want me to work with? ")
    print "You want me to take the average of", amount, "numbers."

    numbers = raw_input("Please type the numbers, separated by commas: ")
    print "You want to know the average of the numbers:", numbers

    add = 0
    for numStr in string.split(numbers, ","):
        convNum = eval(numStr) # convert digit string to a number
        add = add + convNum # add number to variable 'add'
    print "The sum of your numbers is:", add
    average = add / float(amount)
    print "Therefore the average of your numbers is", average
main() 


Many thanks,

David


From alan.gauld at btinternet.com  Fri Oct  3 10:23:14 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 3 Oct 2008 09:23:14 +0100
Subject: [Tutor] dealing with user input whose value I don't know
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>	<48E50728.8020605@gmx.net>	<20081002174911.GF98291@dragon.alchemy.com><20081002175456.GA26406@ayn.mi.celestial.com>	<48E50DB7.8030704@gmx.net><gc3n1u$lrd$1@ger.gmane.org>
	<48E5CDAA.9090900@gmx.net>
Message-ID: <gc4kpg$jt0$1@ger.gmane.org>


"David" <ldl08 at gmx.net> wrote

>> the string into substrings and then convert each substring to an
>> integer.
> This I have now done by using eval(). But now I wonder whether that 
> is actually clever because it is supposed to be similarly 
> problematic as the input() function in terms of security.

Absolutely. The more open and general you make your code
the more opportunity you provide for attacks. Converting to
int/float is much safer.

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



From srilyk at gmail.com  Fri Oct  3 12:40:46 2008
From: srilyk at gmail.com (W W)
Date: Fri, 3 Oct 2008 05:40:46 -0500
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <1f7befae0810022244o5c57a15do4814885bbe826ad0@mail.gmail.com>
References: <1222986184.6552.8.camel@alecwh-laptop>
	<1f7befae0810022244o5c57a15do4814885bbe826ad0@mail.gmail.com>
Message-ID: <333efb450810030340g3beb865by9b2934c45ed726b@mail.gmail.com>

On Fri, Oct 3, 2008 at 12:44 AM, Tim Peters <tim.peters at gmail.com> wrote:

> [Alec Henriksen]
> > How trustworthy is the "randomness" generated by the random module?
>
> Python uses the Mersenne Twister algorithm for generating
> pseudo-random numbers, and that's one of the highest-quality methods
> known.


I've talked with some people about random number generation, and how you can
tell if it's random. For 10 numbers, is 5 5 5 5 5 5 5 5 5 5 random? You
really don't know, because it's random! It probably is. Even if the set
before and after are all the same, it still could be - that's the beauty of
randomness, is sometimes you can get what looks like patterns.

Of course, if you're working with data encryption, this is simply not a very
reliable way to do things. One of the most "random" ways (of course if you
were able to /exactly/ duplicate the circumstances, you'd still get the same
result. However it's much more difficult to duplicate the circumstances with
this method.) I've seen to generate a number is getting sound input from the
mic jack when there's no mic attached, and treating it like string data,
then using that as your key.

Hooray for Random!
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/43939c51/attachment.htm>

From sdragon1984 at gmail.com  Fri Oct  3 14:46:08 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Fri, 3 Oct 2008 08:46:08 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
Message-ID: <111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>

Hm... Tried changing that, but it didn't help....

On Thu, Oct 2, 2008 at 9:18 AM, Luke Paireepinart <rabidpoobear at gmail.com>wrote:

> room == start is a comparison (check if room is equal to start - doesn't
> make a whole lot of sense to be doing that here).  The "room" variable name
> doesn't exist in the current namespace, so it can't be compared to start.
> It looks like you wanted room = start.
>
> On 10/2/08, nathan virgil <sdragon1984 at gmail.com> wrote:
>
>> Okay, I'm resurrecting this project. I did a little more work on it then
>> what you see here, but that ended up getting accidentally deleted, and I
>> haven't done anything with Python since.
>>
>> I'm running into one problem already, and I haven't really added any extra
>> code. In the content (at this point, the rooms still have Bob's
>> descriptions), the very first line of actual code (third line in the
>> program) is returning an error.
>>
>> Offending code:
>>
>> # Content
>> # retrieve data for current room
>> room == start
>> while true:
>>     if room == start:
>>         desc = "Ahead of you, you see a chasm."
>>         ques = "Do you wish to try jumping over it? Y/N"
>>         destY = 2
>>         destN = 3
>>
>> Error:
>>
>> Traceback (most recent call last):
>>   File "samplegame.py", line 3, in <module>
>>     room == start
>> NameError: name 'room' is not defined
>>
>>
>> What's going on here?
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/b627a5f1/attachment.htm>

From sdragon1984 at gmail.com  Fri Oct  3 14:52:05 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Fri, 3 Oct 2008 08:52:05 -0400
Subject: [Tutor] Finding the "streaks" in heads/tails list
In-Reply-To: <gc14hp$nsm$1@ger.gmane.org>
References: <1222894568.6779.52.camel@alecwh-laptop>
	<1c2a2c590810011427k6c5d9172kea85dee4f957423a@mail.gmail.com>
	<gc14hp$nsm$1@ger.gmane.org>
Message-ID: <111a9ddb0810030552k338c499cnbf3d3c0f94c3351e@mail.gmail.com>

You need to store the count before resetting it since you want

> to know the largest value of count over the list. Or at least keep a
> separate max variable that you update if count > max.
>


Fairly easy:

if Cur_Count > Max_Count:
     Max_Count = Cur_Count

See? Just two extra lines of code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/8cbc4723/attachment.htm>

From david at abbottdavid.com  Fri Oct  3 15:19:08 2008
From: david at abbottdavid.com (David)
Date: Fri, 03 Oct 2008 09:19:08 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
Message-ID: <48E61BCC.2030003@abbottdavid.com>

> Okay, I'm resurrecting this project.
Where is this project code?




-- 
Have Fun,
David A.

Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com


From sdragon1984 at gmail.com  Fri Oct  3 15:50:55 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Fri, 3 Oct 2008 09:50:55 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <48E61BCC.2030003@abbottdavid.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
Message-ID: <111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>

On Fri, Oct 3, 2008 at 9:19 AM, David <david at abbottdavid.com> wrote:

> > Okay, I'm resurrecting this project.
> Where is this project code? <http://www.linuxcrazy.com>
>

Right here. The content is going to eventually go through some drastic
changes, but what's here should be good enough for testing.

# Content
# retrieve data for current room
room = 1
if room == 1:
    desc = "Ahead of you, you see a chasm."
    ques = "Do you wish to try jumping over it? Y/N"
    destYes = 2
    destNo = 3
elif room == 2:
    desc = "Ahead of you, you see a warty green ogre."
    ques = "Do you wish to eat it? Y/N"
    destYes = 4
    destNo = 5
# etc for the rest of the rooms

# Engine
# ask current question and move to next room
print desc
ans = raw_input(ques).upper() # allow for lower case input
if ans == "Y":
    room = destYes
elif ans == "N":
    room = destNo
elif ans == "north":
    room = destN
elif ans == "south":
    room = destS
elif ans == "east":
    room = destE
elif ans == "west":
    room = destW
elif ans == "Q": # give us a way out.
    Break
else:
    print "I don't understand. Can you give a clearer answer?"


It seems like good code, but for some reason, it's not letting me go into
Room 2 (the ogre). I remember last time I tried this, the problem had
something to do with redirecting back into the same room, but I don't
remember exactly what that issue was.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/189c1416/attachment.htm>

From rabidpoobear at gmail.com  Fri Oct  3 16:02:08 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Fri, 3 Oct 2008 09:02:08 -0500
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
	<111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
Message-ID: <dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>

On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil <sdragon1984 at gmail.com> wrote:
>
>
> On Fri, Oct 3, 2008 at 9:19 AM, David <david at abbottdavid.com> wrote:
>>
>> > Okay, I'm resurrecting this project.
>> Where is this project code?
> It seems like good code,
It's not.


> # Content
> # retrieve data for current room
> room = 1
> if room == 1:
this is always true because you just set room to 1 right before you
checked the variable.
>     desc = "Ahead of you, you see a chasm."
>     ques = "Do you wish to try jumping over it? Y/N"
>     destYes = 2
>     destNo = 3
> elif room == 2:
this will never be true, which is why you can't get into the second room.
This whole thing needs to be in a loop.
But this is definitely not the best way to implement this either.

>     desc = "Ahead of you, you see a warty green ogre."
>     ques = "Do you wish to eat it? Y/N"
>     destYes = 4
>     destNo = 5
> # etc for the rest of the rooms
He's wiring these rooms together with numbers.  The way I'd do it is
to create a Room object with a bunch of different methods, such as
room.print(), room.printDescription(), room.makeChoice(), and such,
and then the rooms would be connected together using data members.
It would be a lot more elegant and less confusing that way.

>
> # Engine
> # ask current question and move to next room
> print desc
> ans = raw_input(ques).upper() # allow for lower case input
> if ans == "Y":
>     room = destYes
> elif ans == "N":
>     room = destNo
> elif ans == "north":
>     room = destN
> elif ans == "south":
>     room = destS
> elif ans == "east":
>     room = destE
> elif ans == "west":
>     room = destW
> elif ans == "Q": # give us a way out.
>     Break
> else:
>     print "I don't understand. Can you give a clearer answer?"

You prompted the user, then retrieved the next room value.
Now we're here, and there's no code left.  So it stops here.

>
but for some reason, it's not letting me go into
> Room 2 (the ogre).
Is it clearer why this isn't working now?

From d.conca at gmail.com  Fri Oct  3 16:11:42 2008
From: d.conca at gmail.com (Daniele)
Date: Fri, 3 Oct 2008 16:11:42 +0200
Subject: [Tutor] How trustworthy are pseudo-random numbers?
Message-ID: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>

>> [Alec Henriksen]
>> > How trustworthy is the "randomness" generated by the random module?
>>
>> Python uses the Mersenne Twister algorithm for generating
>> pseudo-random numbers, and that's one of the highest-quality methods
>> known.

>From here
http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
and here
http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

I think it can be argued that the randomness is pretty trustworthy :o)

From sdragon1984 at gmail.com  Fri Oct  3 16:24:19 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Fri, 3 Oct 2008 10:24:19 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
	<111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
	<dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>
Message-ID: <111a9ddb0810030724r1da90c15v5ca71a60f1eb8c86@mail.gmail.com>

On Fri, Oct 3, 2008 at 10:02 AM, Luke Paireepinart
<rabidpoobear at gmail.com>wrote:

> On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil <sdragon1984 at gmail.com>
> wrote:
> >
> >
> > On Fri, Oct 3, 2008 at 9:19 AM, David <david at abbottdavid.com> wrote:
> >>
> >> > Okay, I'm resurrecting this project.
> >> Where is this project code?
> > It seems like good code,
> It's not.
>
>
> > # Content
> > # retrieve data for current room
> > room = 1
> > if room == 1:
> this is always true because you just set room to 1 right before you
> checked the variable.
> >     desc = "Ahead of you, you see a chasm."
> >     ques = "Do you wish to try jumping over it? Y/N"
> >     destYes = 2
> >     destNo = 3
> > elif room == 2:
> this will never be true, which is why you can't get into the second room.
> This whole thing needs to be in a loop.
> But this is definitely not the best way to implement this either.
>
> >     desc = "Ahead of you, you see a warty green ogre."
> >     ques = "Do you wish to eat it? Y/N"
> >     destYes = 4
> >     destNo = 5
> > # etc for the rest of the rooms
> He's wiring these rooms together with numbers.  The way I'd do it is
> to create a Room object with a bunch of different methods, such as
> room.print(), room.printDescription(), room.makeChoice(), and such,
> and then the rooms would be connected together using data members.
> It would be a lot more elegant and less confusing that way.
>
> >
> > # Engine
> > # ask current question and move to next room
> > print desc
> > ans = raw_input(ques).upper() # allow for lower case input
> > if ans == "Y":
> >     room = destYes
> > elif ans == "N":
> >     room = destNo
> > elif ans == "north":
> >     room = destN
> > elif ans == "south":
> >     room = destS
> > elif ans == "east":
> >     room = destE
> > elif ans == "west":
> >     room = destW
> > elif ans == "Q": # give us a way out.
> >     Break
> > else:
> >     print "I don't understand. Can you give a clearer answer?"
>
> You prompted the user, then retrieved the next room value.
> Now we're here, and there's no code left.  So it stops here.
>
> >
> but for some reason, it's not letting me go into
> > Room 2 (the ogre).
> Is it clearer why this isn't working now?
>


Erm, no, not really. Are you saying I need to take out those last two lines?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/ba7a7459/attachment.htm>

From sdragon1984 at gmail.com  Fri Oct  3 16:59:44 2008
From: sdragon1984 at gmail.com (nathan virgil)
Date: Fri, 3 Oct 2008 10:59:44 -0400
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <111a9ddb0810030724r1da90c15v5ca71a60f1eb8c86@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
	<111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
	<dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>
	<111a9ddb0810030724r1da90c15v5ca71a60f1eb8c86@mail.gmail.com>
Message-ID: <111a9ddb0810030759g6907cda2t1037c2afc5246053@mail.gmail.com>

On Fri, Oct 3, 2008 at 10:24 AM, nathan virgil <sdragon1984 at gmail.com>wrote:

>
>
> On Fri, Oct 3, 2008 at 10:02 AM, Luke Paireepinart <rabidpoobear at gmail.com
> > wrote:
>
>> On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil <sdragon1984 at gmail.com>
>> wrote:
>> >
>> >
>> > On Fri, Oct 3, 2008 at 9:19 AM, David <david at abbottdavid.com> wrote:
>> >>
>> >> > Okay, I'm resurrecting this project.
>> >> Where is this project code?
>> > It seems like good code,
>> It's not.
>>
>>
>> > # Content
>> > # retrieve data for current room
>> > room = 1
>> > if room == 1:
>> this is always true because you just set room to 1 right before you
>> checked the variable.
>> >     desc = "Ahead of you, you see a chasm."
>> >     ques = "Do you wish to try jumping over it? Y/N"
>> >     destYes = 2
>> >     destNo = 3
>> > elif room == 2:
>> this will never be true, which is why you can't get into the second room.
>> This whole thing needs to be in a loop.
>> But this is definitely not the best way to implement this either.
>>
>> >     desc = "Ahead of you, you see a warty green ogre."
>> >     ques = "Do you wish to eat it? Y/N"
>> >     destYes = 4
>> >     destNo = 5
>> > # etc for the rest of the rooms
>> He's wiring these rooms together with numbers.  The way I'd do it is
>> to create a Room object with a bunch of different methods, such as
>> room.print(), room.printDescription(), room.makeChoice(), and such,
>> and then the rooms would be connected together using data members.
>> It would be a lot more elegant and less confusing that way.
>>
>> >
>> > # Engine
>> > # ask current question and move to next room
>> > print desc
>> > ans = raw_input(ques).upper() # allow for lower case input
>> > if ans == "Y":
>> >     room = destYes
>> > elif ans == "N":
>> >     room = destNo
>> > elif ans == "north":
>> >     room = destN
>> > elif ans == "south":
>> >     room = destS
>> > elif ans == "east":
>> >     room = destE
>> > elif ans == "west":
>> >     room = destW
>> > elif ans == "Q": # give us a way out.
>> >     Break
>> > else:
>> >     print "I don't understand. Can you give a clearer answer?"
>>
>> You prompted the user, then retrieved the next room value.
>> Now we're here, and there's no code left.  So it stops here.
>>
>> >
>> but for some reason, it's not letting me go into
>> > Room 2 (the ogre).
>> Is it clearer why this isn't working now?
>>
>
>
> Erm, no, not really. Are you saying I need to take out those last two
> lines?
>

Loops, then? The  code this is based off of  had the second line of  actual
code (between "room = 1" and "if room ==1") as "while true:", but when I
include this, it gives an error at that line. Is there another way to do
that? Maybe "while room != 4.2"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/55b63f8c/attachment.htm>

From andreengels at gmail.com  Fri Oct  3 17:03:14 2008
From: andreengels at gmail.com (Andre Engels)
Date: Fri, 3 Oct 2008 17:03:14 +0200
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
Message-ID: <6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>

On Fri, Oct 3, 2008 at 4:11 PM, Daniele <d.conca at gmail.com> wrote:
> >From here
> http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
> and here
> http://en.wikipedia.org/wiki/Mersenne_twister#Advantages
>
> I think it can be argued that the randomness is pretty trustworthy :o)

Nice understatement on that last page - "most applications do not
require 2^19937 unique combinations (2^19937 is approximately 4.315425
? 10^6001)."

If you used every atom in the known universe as a computer, then let
them turn out a billion combinations a second for the entire time
since the big bang, and call the number of combination you get then
N...
then take N computers turning out N combinations a second for the
entire time since the big bang, and call the number of combinations
they turn out N2...
then take N2 computers turning out N2 combinations a second and call
the number of combination they turn out in the time since the big bang
and call that N3...
then the number of combinations turned out by N3 computers turning out
N3 combinations per second in the time since the big bang STILL
dwarves in comparison to that number.


-- 
Andr? Engels, andreengels at gmail.com

From kent37 at tds.net  Fri Oct  3 17:08:29 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 3 Oct 2008 11:08:29 -0400
Subject: [Tutor] Apress on sale at Bookpool
Message-ID: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>

Bookpool.com is selling Apress titles at 50% off for December. Apress
has many good Python titles:

For learning Python:
- Beginning Python: From Novice to Professional, Second Edition
- Dive Into Python

Django:
- The Definitive Guide to Django: Web Development Done Right
- Practical Django Projects

Networking:
- Foundations of Python Network Programming

http://apress.com/book/catalog?category=144
http://www.bookpool.com/ct/272

Kent

From kent37 at tds.net  Fri Oct  3 17:10:24 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 3 Oct 2008 11:10:24 -0400
Subject: [Tutor] Apress on sale at Bookpool
In-Reply-To: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
Message-ID: <1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>

Oops, that's October, not December!

On Fri, Oct 3, 2008 at 11:08 AM, Kent Johnson <kent37 at tds.net> wrote:
> Bookpool.com is selling Apress titles at 50% off for December. Apress
> has many good Python titles:
>
> For learning Python:
> - Beginning Python: From Novice to Professional, Second Edition
> - Dive Into Python
>
> Django:
> - The Definitive Guide to Django: Web Development Done Right
> - Practical Django Projects
>
> Networking:
> - Foundations of Python Network Programming
>
> http://apress.com/book/catalog?category=144
> http://www.bookpool.com/ct/272
>
> Kent
>

From rabidpoobear at gmail.com  Fri Oct  3 17:25:17 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Fri, 3 Oct 2008 10:25:17 -0500
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
	<6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
Message-ID: <dfeb4470810030825k1b93dc2lef14382112a62b2e@mail.gmail.com>

Is your math correct?  That's ridiculously large.

On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels <andreengels at gmail.com> wrote:
> On Fri, Oct 3, 2008 at 4:11 PM, Daniele <d.conca at gmail.com> wrote:
>> >From here
>> http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
>> and here
>> http://en.wikipedia.org/wiki/Mersenne_twister#Advantages
>>
>> I think it can be argued that the randomness is pretty trustworthy :o)
>
> Nice understatement on that last page - "most applications do not
> require 2^19937 unique combinations (2^19937 is approximately 4.315425
> ? 10^6001)."
>
> If you used every atom in the known universe as a computer, then let
> them turn out a billion combinations a second for the entire time
> since the big bang, and call the number of combination you get then
> N...
> then take N computers turning out N combinations a second for the
> entire time since the big bang, and call the number of combinations
> they turn out N2...
> then take N2 computers turning out N2 combinations a second and call
> the number of combination they turn out in the time since the big bang
> and call that N3...
> then the number of combinations turned out by N3 computers turning out
> N3 combinations per second in the time since the big bang STILL
> dwarves in comparison to that number.
>
>
> --
> Andr? Engels, andreengels at gmail.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From andreengels at gmail.com  Fri Oct  3 17:32:46 2008
From: andreengels at gmail.com (Andre Engels)
Date: Fri, 3 Oct 2008 17:32:46 +0200
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <dfeb4470810030825k1b93dc2lef14382112a62b2e@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
	<6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
	<dfeb4470810030825k1b93dc2lef14382112a62b2e@mail.gmail.com>
Message-ID: <6faf39c90810030832q16139684xda587d26a49772f5@mail.gmail.com>

On Fri, Oct 3, 2008 at 5:25 PM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
> Is your math correct?  That's ridiculously large.

1 year equals 3600 * 24 * 365 makes about 3*10^8 seconds.
The universe is about 15.000.000.000 years old, that's about 5*10^17 seconds.
With 1 billion combinations per second, each computer does 5*10^26
combinations in that time.
There are something like 10^70 or 10^72 particles in the universe,
thus N is about 10^100, give or take a factor of thousand or so.
N2 is equal to 5*10^17 * N * N, which we will round up to 10^220.
N3 by that same calculation will be about 10^460.
The unnamed last number that way becomes something like 10^940 (in
reality, because of all the rounding up, more like 10^930). That's
less than 1/10^600 of 10^1600 - I'd say that's dwarved by any
definition of the word.

> On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels <andreengels at gmail.com> wrote:
>> On Fri, Oct 3, 2008 at 4:11 PM, Daniele <d.conca at gmail.com> wrote:
>>> >From here
>>> http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
>>> and here
>>> http://en.wikipedia.org/wiki/Mersenne_twister#Advantages
>>>
>>> I think it can be argued that the randomness is pretty trustworthy :o)
>>
>> Nice understatement on that last page - "most applications do not
>> require 2^19937 unique combinations (2^19937 is approximately 4.315425
>> ? 10^6001)."
>>
>> If you used every atom in the known universe as a computer, then let
>> them turn out a billion combinations a second for the entire time
>> since the big bang, and call the number of combination you get then
>> N...
>> then take N computers turning out N combinations a second for the
>> entire time since the big bang, and call the number of combinations
>> they turn out N2...
>> then take N2 computers turning out N2 combinations a second and call
>> the number of combination they turn out in the time since the big bang
>> and call that N3...
>> then the number of combinations turned out by N3 computers turning out
>> N3 combinations per second in the time since the big bang STILL
>> dwarves in comparison to that number.
>>
>>
>> --
>> Andr? Engels, andreengels at gmail.com
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>



-- 
Andr? Engels, andreengels at gmail.com

From andreengels at gmail.com  Fri Oct  3 17:44:53 2008
From: andreengels at gmail.com (Andre Engels)
Date: Fri, 3 Oct 2008 17:44:53 +0200
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <6faf39c90810030832q16139684xda587d26a49772f5@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
	<6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
	<dfeb4470810030825k1b93dc2lef14382112a62b2e@mail.gmail.com>
	<6faf39c90810030832q16139684xda587d26a49772f5@mail.gmail.com>
Message-ID: <6faf39c90810030844y36faa1c2r6658a6e8ef9892d6@mail.gmail.com>

On Fri, Oct 3, 2008 at 5:32 PM, Andre Engels <andreengels at gmail.com> wrote:
> On Fri, Oct 3, 2008 at 5:25 PM, Luke Paireepinart
> <rabidpoobear at gmail.com> wrote:
>> Is your math correct?  That's ridiculously large.
>
> 1 year equals 3600 * 24 * 365 makes about 3*10^8 seconds.
> The universe is about 15.000.000.000 years old, that's about 5*10^17 seconds.
> With 1 billion combinations per second, each computer does 5*10^26
> combinations in that time.
> There are something like 10^70 or 10^72 particles in the universe,
> thus N is about 10^100, give or take a factor of thousand or so.
> N2 is equal to 5*10^17 * N * N, which we will round up to 10^220.
> N3 by that same calculation will be about 10^460.
> The unnamed last number that way becomes something like 10^940 (in
> reality, because of all the rounding up, more like 10^930). That's
> less than 1/10^600 of 10^1600 - I'd say that's dwarved by any
> definition of the word.

Oh, wait, I had to compare to 10^6001 instead of 10^1600... Which
means I could have gone on to N6 instead of N4.

>> On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels <andreengels at gmail.com> wrote:
>>> On Fri, Oct 3, 2008 at 4:11 PM, Daniele <d.conca at gmail.com> wrote:
>>>> >From here
>>>> http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
>>>> and here
>>>> http://en.wikipedia.org/wiki/Mersenne_twister#Advantages
>>>>
>>>> I think it can be argued that the randomness is pretty trustworthy :o)
>>>
>>> Nice understatement on that last page - "most applications do not
>>> require 2^19937 unique combinations (2^19937 is approximately 4.315425
>>> ? 10^6001)."
>>>
>>> If you used every atom in the known universe as a computer, then let
>>> them turn out a billion combinations a second for the entire time
>>> since the big bang, and call the number of combination you get then
>>> N...
>>> then take N computers turning out N combinations a second for the
>>> entire time since the big bang, and call the number of combinations
>>> they turn out N2...
>>> then take N2 computers turning out N2 combinations a second and call
>>> the number of combination they turn out in the time since the big bang
>>> and call that N3...
>>> then the number of combinations turned out by N3 computers turning out
>>> N3 combinations per second in the time since the big bang STILL
>>> dwarves in comparison to that number.
>>>
>>>
>>> --
>>> Andr? Engels, andreengels at gmail.com
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>
>
>
> --
> Andr? Engels, andreengels at gmail.com
>



-- 
Andr? Engels, andreengels at gmail.com

From d.conca at gmail.com  Fri Oct  3 17:45:06 2008
From: d.conca at gmail.com (Daniele)
Date: Fri, 3 Oct 2008 17:45:06 +0200
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>
	<6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>
Message-ID: <537341c70810030845t65edd688we0dd0e626371c9f0@mail.gmail.com>

2008/10/3 Andre Engels <andreengels at gmail.com>:
> On Fri, Oct 3, 2008 at 4:11 PM, Daniele <d.conca at gmail.com> wrote:
> If you used every atom in the known universe as a computer, then let
> them turn out a billion combinations a second for the entire time
> since the big bang, and call the number of combination you get then
> N [...].. then the number of combinations turned out by N3 computers turning out
> N3 combinations per second in the time since the big bang STILL
> dwarves in comparison to that number.

Excellent Proof of concept! ,-)

From bermanrl at embarqmail.com  Fri Oct  3 17:52:51 2008
From: bermanrl at embarqmail.com (Robert Berman)
Date: Fri, 03 Oct 2008 11:52:51 -0400
Subject: [Tutor] How trustworthy are pseudo-random numbers?
In-Reply-To: <6faf39c90810030832q16139684xda587d26a49772f5@mail.gmail.com>
References: <537341c70810030711l54459b15laeabfea4a7e07691@mail.gmail.com>	<6faf39c90810030803r2b6713cod99079253d5d4131@mail.gmail.com>	<dfeb4470810030825k1b93dc2lef14382112a62b2e@mail.gmail.com>
	<6faf39c90810030832q16139684xda587d26a49772f5@mail.gmail.com>
Message-ID: <48E63FD3.7060408@embarqmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/bb65520b/attachment.htm>

From cbabcock at asciiking.com  Fri Oct  3 18:38:56 2008
From: cbabcock at asciiking.com (Chris Babcock)
Date: Fri, 3 Oct 2008 09:38:56 -0700
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <111a9ddb0810030759g6907cda2t1037c2afc5246053@mail.gmail.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
	<111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
	<dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>
	<111a9ddb0810030724r1da90c15v5ca71a60f1eb8c86@mail.gmail.com>
	<111a9ddb0810030759g6907cda2t1037c2afc5246053@mail.gmail.com>
Message-ID: <20081003093856.61f3e0ce@mail.asciiking.com>


> Loops, then? The  code this is based off of  had the second line of
> actual code (between "room = 1" and "if room ==1") as "while true:",
> but when I include this, it gives an error at that line. Is there
> another way to do that? Maybe "while room != 4.2"?

What you had before was...

room = 1
if room == 1
  # Room 1 stuff
elif... #Stuff that never got executed
# End of program.


Try...

room = 1
while 1:
  if room == 1:
    # Room 1 stuff
  elif room == 2:
    # Room 2 stuff

Your switching variable can't be the loop control and you do need to be
in a loop for the conditional expression to be evaluated again after
you've changed the value of room.

Chris


-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.

From jeremiah.jester at panasonic.aero  Fri Oct  3 19:29:13 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Fri, 03 Oct 2008 10:29:13 -0700
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
Message-ID: <1223054953.22213.9.camel@jeremiah-laptop>

I have a list of dictionary values that i am looping through that upon
each iteration I would like to assign these values to a new dictionary
name. 

For example...

item=0
for line in some_dict:
	## some how assign dict values to new name
	"new_dict_name_"+item = line

I have not tested the example code above and is displayed simply for
demonstration purposes. 

Any thoughts on how to do this? 

Thanks,
JJ



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From steve at alchemy.com  Fri Oct  3 19:35:13 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Fri, 3 Oct 2008 10:35:13 -0700
Subject: [Tutor] Hands-on beginner's project?
In-Reply-To: <20081003093856.61f3e0ce@mail.asciiking.com>
References: <109363.20638.qm@web52007.mail.re2.yahoo.com>
	<111a9ddb0810020610m4ae7a418wd05ea7fe52828509@mail.gmail.com>
	<dfeb4470810020618k704801fbwf6ce81286eba82f4@mail.gmail.com>
	<111a9ddb0810030546j79f3c439r700a8957b3486d0c@mail.gmail.com>
	<48E61BCC.2030003@abbottdavid.com>
	<111a9ddb0810030650qc5bdae6kbbf8698c0b761835@mail.gmail.com>
	<dfeb4470810030702q7488dc7cqf0858f17d0fddbaa@mail.gmail.com>
	<111a9ddb0810030724r1da90c15v5ca71a60f1eb8c86@mail.gmail.com>
	<111a9ddb0810030759g6907cda2t1037c2afc5246053@mail.gmail.com>
	<20081003093856.61f3e0ce@mail.asciiking.com>
Message-ID: <20081003173513.GB83430@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 09:38:56AM -0700, Chris Babcock wrote:
> room = 1
> while 1:

Also, it may be more clear to say "while True:" in preference
to "while 1:".  Note that in your earlier version you didn't
capitalize "True" which meant Python had no idea what that
value was (could be a variable or something).  True and False
(and None, for that matter) are all capitalized.

>   if room == 1:
>     # Room 1 stuff
>   elif room == 2:
>     # Room 2 stuff

This is a good start while you're learning to program initially.
You'll later want to see how to generalize this so the collection
of rooms and connections between them exists in _data_ instead
of _code_.  Something to simmer on the back burner until you're
ready for that step.


-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From steve at alchemy.com  Fri Oct  3 19:39:37 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Fri, 3 Oct 2008 10:39:37 -0700
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <1223054953.22213.9.camel@jeremiah-laptop>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
	<1223054953.22213.9.camel@jeremiah-laptop>
Message-ID: <20081003173937.GC83430@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
> I have a list of dictionary values that i am looping through that upon
> each iteration I would like to assign these values to a new dictionary
> name. 
> 
> For example...
> 
> item=0
> for line in some_dict:
> 	## some how assign dict values to new name
> 	"new_dict_name_"+item = line

You could use eval, I suppose, but are you sure that 
making up new dictionary names on the fly like that is
the solution that best fits the problem as opposed to
having, say, a set of objects or an overall dictionary
of dictionaries you add to?  What's the bigger context
this fits into?  Although you *can* do this sort of thing,
it quite often ends up not being the most elegant thing
to do.

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From luckdancing at gmail.com  Fri Oct  3 19:50:27 2008
From: luckdancing at gmail.com (Rob Sutherland)
Date: Fri, 3 Oct 2008 11:50:27 -0600
Subject: [Tutor] UnicodeEncodeError
Message-ID: <92559a100810031050s4cb2d4c5k1ee7e2508838788b@mail.gmail.com>

I'm working on a python application that stores email in a postgresql
database and
I'm encountering the UnicodeEncodeError - while storing a particular
email I receive
this error

UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
in position 144: character maps to <undefined>

I'm a little confused about a workaround for this, from what I've
googled the approach seems to be to use the codecs.register_error and
codecs.ignore_errors to skip processing of the offending character. I
haven't been able to find an understandable example though, so if
anyone has one that would be great.

Rob

From jeremiah.jester at panasonic.aero  Fri Oct  3 20:02:34 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Fri, 03 Oct 2008 11:02:34 -0700
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <20081003173937.GC83430@dragon.alchemy.com>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
	<1223054953.22213.9.camel@jeremiah-laptop>
	<20081003173937.GC83430@dragon.alchemy.com>
Message-ID: <1223056954.22213.14.camel@jeremiah-laptop>

i think i figured it out. The result is that I have a dictionary within
a dictionary..i think.

for example:

{'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}

How would I go about itterating through this?

Thanks,
JJ


On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
> On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
> > I have a list of dictionary values that i am looping through that
> upon
> > each iteration I would like to assign these values to a new
> dictionary
> > name.
> >
> > For example...
> >
> > item=0
> > for line in some_dict:
> >       ## some how assign dict values to new name
> >       "new_dict_name_"+item = line
> 
> You could use eval, I suppose, but are you sure that
> making up new dictionary names on the fly like that is
> the solution that best fits the problem as opposed to
> having, say, a set of objects or an overall dictionary
> of dictionaries you add to?  What's the bigger context
> this fits into?  Although you *can* do this sort of thing,
> it quite often ends up not being the most elegant thing
> to do.
> 
> --
> Steve Willoughby    |  Using billion-dollar satellites
> steve at alchemy.com   |  to hunt for Tupperware.
> 
> 
> 


Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From srilyk at gmail.com  Fri Oct  3 20:05:31 2008
From: srilyk at gmail.com (W W)
Date: Fri, 3 Oct 2008 13:05:31 -0500
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <1223056954.22213.14.camel@jeremiah-laptop>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
	<1223054953.22213.9.camel@jeremiah-laptop>
	<20081003173937.GC83430@dragon.alchemy.com>
	<1223056954.22213.14.camel@jeremiah-laptop>
Message-ID: <333efb450810031105ka54b2efx62bedac9001b9ee0@mail.gmail.com>

On Fri, Oct 3, 2008 at 1:02 PM, jeremiah <jeremiah.jester at panasonic.aero>wrote:

> i think i figured it out. The result is that I have a dictionary within
> a dictionary..i think.
>
> for example:
>
> {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}
>
> How would I go about itterating through this?
>

for k, v in items(mydict):
    for k, v in items(v):
       print k, v

I think that should work
hth,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/4820b5c0/attachment.htm>

From steve at alchemy.com  Fri Oct  3 20:07:06 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Fri, 3 Oct 2008 11:07:06 -0700
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <1223056954.22213.14.camel@jeremiah-laptop>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
	<1223054953.22213.9.camel@jeremiah-laptop>
	<20081003173937.GC83430@dragon.alchemy.com>
	<1223056954.22213.14.camel@jeremiah-laptop>
Message-ID: <20081003180706.GE83430@dragon.alchemy.com>

On Fri, Oct 03, 2008 at 11:02:34AM -0700, jeremiah wrote:
> i think i figured it out. The result is that I have a dictionary within
> a dictionary..i think.
> 
> for example:
> 
> {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}
> 
> How would I go about itterating through this?

Depends on how you want to iterate through it (what
in the end you're trying to accomplish).  One example:

for major_key in my_dict:
  print "The stuff stored under", major_key, "is:"
  for minor_key in my_dict[major_key]:
    print "(%s) %s=%s" % (major_key, minor_key, my_dict[major_key][minor_key])

Another possibility might be:

for major_key, subdict in my_dict.iteritems():
  print "The stuff stored under", major_key, "is:"
  for minor_key, value in subdict.iteritems():
    print "(%s) %s=%s" % (major_key, minor_key, value)


> 
> Thanks,
> JJ
> 
> 
> On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
> > On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
> > > I have a list of dictionary values that i am looping through that
> > upon
> > > each iteration I would like to assign these values to a new
> > dictionary
> > > name.
> > >
> > > For example...
> > >
> > > item=0
> > > for line in some_dict:
> > >       ## some how assign dict values to new name
> > >       "new_dict_name_"+item = line
> > 
> > You could use eval, I suppose, but are you sure that
> > making up new dictionary names on the fly like that is
> > the solution that best fits the problem as opposed to
> > having, say, a set of objects or an overall dictionary
> > of dictionaries you add to?  What's the bigger context
> > this fits into?  Although you *can* do this sort of thing,
> > it quite often ends up not being the most elegant thing
> > to do.
> > 
> > --
> > Steve Willoughby    |  Using billion-dollar satellites
> > steve at alchemy.com   |  to hunt for Tupperware.
> > 
> > 
> > 
> 
> 
> Disclaimer: The information contained in this transmission, including any 
> attachments, may contain confidential information of Panasonic Avionics
> Corporation.  This transmission is intended only for the use of the 
> addressee(s) listed above.  Unauthorized review, dissemination or other use 
> of the information contained in this transmission is strictly prohibited. 
> If you have received this transmission in error or have reason to believe 
> you are not authorized to receive it, please notify the sender by return 
> email and promptly delete the transmission.
> 
> 

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From jeremiah.jester at panasonic.aero  Fri Oct  3 20:14:44 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Fri, 03 Oct 2008 11:14:44 -0700
Subject: [Tutor] assigning values to dictionary
In-Reply-To: <20081003180706.GE83430@dragon.alchemy.com>
References: <1c2a2c590810030808x18eaba2bga288cee9b7793686@mail.gmail.com>
	<1c2a2c590810030810p649baa89vff9dbcd6f9936c1@mail.gmail.com>
	<1223054953.22213.9.camel@jeremiah-laptop>
	<20081003173937.GC83430@dragon.alchemy.com>
	<1223056954.22213.14.camel@jeremiah-laptop>
	<20081003180706.GE83430@dragon.alchemy.com>
Message-ID: <1223057684.22213.20.camel@jeremiah-laptop>

Awesome. Thanks!

On Fri, 2008-10-03 at 11:07 -0700, Steve Willoughby wrote:
> On Fri, Oct 03, 2008 at 11:02:34AM -0700, jeremiah wrote:
> > i think i figured it out. The result is that I have a dictionary
> within
> > a dictionary..i think.
> >
> > for example:
> >
> > {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}
> >
> > How would I go about itterating through this?
> 
> Depends on how you want to iterate through it (what
> in the end you're trying to accomplish).  One example:
> 
> for major_key in my_dict:
>   print "The stuff stored under", major_key, "is:"
>   for minor_key in my_dict[major_key]:
>     print "(%s) %s=%s" % (major_key, minor_key,
> my_dict[major_key][minor_key])
> 
> Another possibility might be:
> 
> for major_key, subdict in my_dict.iteritems():
>   print "The stuff stored under", major_key, "is:"
>   for minor_key, value in subdict.iteritems():
>     print "(%s) %s=%s" % (major_key, minor_key, value)
> 
> 
> >
> > Thanks,
> > JJ
> >
> >
> > On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
> > > On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
> > > > I have a list of dictionary values that i am looping through
> that
> > > upon
> > > > each iteration I would like to assign these values to a new
> > > dictionary
> > > > name.
> > > >
> > > > For example...
> > > >
> > > > item=0
> > > > for line in some_dict:
> > > >       ## some how assign dict values to new name
> > > >       "new_dict_name_"+item = line
> > >
> > > You could use eval, I suppose, but are you sure that
> > > making up new dictionary names on the fly like that is
> > > the solution that best fits the problem as opposed to
> > > having, say, a set of objects or an overall dictionary
> > > of dictionaries you add to?  What's the bigger context
> > > this fits into?  Although you *can* do this sort of thing,
> > > it quite often ends up not being the most elegant thing
> > > to do.
> > >
> > > --
> > > Steve Willoughby    |  Using billion-dollar satellites
> > > steve at alchemy.com   |  to hunt for Tupperware.
> > >
> > >
> > >
> >
> >
> > Disclaimer: The information contained in this transmission,
> including any
> > attachments, may contain confidential information of Panasonic
> Avionics
> > Corporation.  This transmission is intended only for the use of the
> > addressee(s) listed above.  Unauthorized review, dissemination or
> other use
> > of the information contained in this transmission is strictly
> prohibited.
> > If you have received this transmission in error or have reason to
> believe
> > you are not authorized to receive it, please notify the sender by
> return
> > email and promptly delete the transmission.
> >
> >
> 
> --
> Steve Willoughby    |  Using billion-dollar satellites
> steve at alchemy.com   |  to hunt for Tupperware.
> 
> 
> 

From dilisamom at yahoo.com  Fri Oct  3 20:04:22 2008
From: dilisamom at yahoo.com (realNewbie)
Date: Fri, 3 Oct 2008 11:04:22 -0700 (PDT)
Subject: [Tutor]  Coin Flip
Message-ID: <19802888.post@talk.nabble.com>


This is a class assignment, I am to create a program that flips a coin 100
times and tells me the number of heads and tails.
I've been working on it for 2 days now and I am stuck. I a trying to run the
program but it is not running. 
Can someone please point out my error? 

Here is what I have come up with:
import random
heads=0
tails=0
count=1
while count <101:
   randomFlip = random.randrange(0,1)
if randomFlip == 0:
    heads = heads + 1
else:
    tails = tails + 1
count = count + 1
print heads," heads"
print tails," tails"
-- 
View this message in context: http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
Sent from the Python - tutor mailing list archive at Nabble.com.


From kent37 at tds.net  Fri Oct  3 20:23:44 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 3 Oct 2008 14:23:44 -0400
Subject: [Tutor] UnicodeEncodeError
In-Reply-To: <92559a100810031050s4cb2d4c5k1ee7e2508838788b@mail.gmail.com>
References: <92559a100810031050s4cb2d4c5k1ee7e2508838788b@mail.gmail.com>
Message-ID: <1c2a2c590810031123u310ec56btb61329fbbf3b2334@mail.gmail.com>

On Fri, Oct 3, 2008 at 1:50 PM, Rob Sutherland <luckdancing at gmail.com> wrote:
> I'm working on a python application that stores email in a postgresql
> database and
> I'm encountering the UnicodeEncodeError - while storing a particular
> email I receive
> this error
>
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
> in position 144: character maps to <undefined>
>
> I'm a little confused about a workaround for this, from what I've
> googled the approach seems to be to use the codecs.register_error and
> codecs.ignore_errors to skip processing of the offending character. I
> haven't been able to find an understandable example though, so if
> anyone has one that would be great.

It helps if you show the code that is causing the error and the full
traceback. Presumably you are calling someString.encode("some
encoding") where "some encoding"  is an encoding that doesn't include
the character "U+2019 right single quotation mark"
http://www.eki.ee/letter/chardata.cgi?ucode=2019

The string encode() method takes a second argument which indicates how
errors should be handled. See the docs for the options:
http://docs.python.org/library/stdtypes.html#str.encode

Kent

From taserian at gmail.com  Fri Oct  3 20:26:47 2008
From: taserian at gmail.com (taserian)
Date: Fri, 3 Oct 2008 14:26:47 -0400
Subject: [Tutor] Coin Flip
In-Reply-To: <19802888.post@talk.nabble.com>
References: <19802888.post@talk.nabble.com>
Message-ID: <70dbc4d40810031126w2eb1537co6b4dc785d30faa4c@mail.gmail.com>

Since the variable *count* never increases inside of the loop body, it gets
stuck in the *while* loop.

I recommend taking a hard look at the program, consider what it should be
doing, and then seeing which statements should be in the *while* loop, and
which ones should be outside it.

Tony R.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie <dilisamom at yahoo.com> wrote:

>
> This is a class assignment, I am to create a program that flips a coin 100
> times and tells me the number of heads and tails.
> I've been working on it for 2 days now and I am stuck. I a trying to run
> the
> program but it is not running.
> Can someone please point out my error?
>
> Here is what I have come up with:
> import random
> heads=0
> tails=0
> count=1
> while count <101:
>   randomFlip = random.randrange(0,1)
> if randomFlip == 0:
>    heads = heads + 1
> else:
>    tails = tails + 1
> count = count + 1
> print heads," heads"
> print tails," tails"
> --
> View this message in context:
> http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/08c50df2/attachment.htm>

From bhaaluu at gmail.com  Fri Oct  3 21:50:48 2008
From: bhaaluu at gmail.com (bhaaluu)
Date: Fri, 3 Oct 2008 15:50:48 -0400
Subject: [Tutor] Coin Flip
In-Reply-To: <19802888.post@talk.nabble.com>
References: <19802888.post@talk.nabble.com>
Message-ID: <ea979d70810031250i4ceb2cb4k9f3f8dd8e5b83862@mail.gmail.com>

First off, check your program's indentation.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie <dilisamom at yahoo.com> wrote:
>
> This is a class assignment, I am to create a program that flips a coin 100
> times and tells me the number of heads and tails.
> I've been working on it for 2 days now and I am stuck. I a trying to run the
> program but it is not running.
> Can someone please point out my error?
>
> Here is what I have come up with:
> import random
> heads=0
> tails=0
> count=1
> while count <101:
>   randomFlip = random.randrange(0,1)
> if randomFlip == 0:
>    heads = heads + 1
> else:
>    tails = tails + 1
> count = count + 1
> print heads," heads"
> print tails," tails"
> --
> View this message in context: http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!

From kent37 at tds.net  Fri Oct  3 22:04:38 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 3 Oct 2008 16:04:38 -0400
Subject: [Tutor] UnicodeEncodeError
In-Reply-To: <92559a100810031139j74fde327u20323b5e7fb84a22@mail.gmail.com>
References: <92559a100810031050s4cb2d4c5k1ee7e2508838788b@mail.gmail.com>
	<1c2a2c590810031123u310ec56btb61329fbbf3b2334@mail.gmail.com>
	<92559a100810031139j74fde327u20323b5e7fb84a22@mail.gmail.com>
Message-ID: <1c2a2c590810031304o144a97eew6de9777ddcb1591e@mail.gmail.com>

On Fri, Oct 3, 2008 at 2:39 PM, Rob Sutherland <luckdancing at gmail.com> wrote:
> On Fri, Oct 3, 2008 at 12:23 PM, Kent Johnson <kent37 at tds.net> wrote:
>
>> It helps if you show the code that is causing the error and the full
>> traceback. Presumably you are calling someString.encode("some
>> encoding") where "some encoding"  is an encoding that doesn't i
>
> I'm encountering this error while attempting to store the string in
> a database, the code I execute is
>
> cur.execute(statement ,attachDict)
>
> which falls through to the code that actually does the encoding  in
> /usr/lib/python2.4/encodings/iso8859_1.py
>
> Traceback (most recent call last):
>  File "./mail2db.py", line 219, in ?
>    storemail(cur, conn,emailDict,attachment_hold)
>  File "./mail2db.py", line 118, in storemail
>    attachments_ok = storeattachment(cur,conn,search_message_id,attachment_hold)
>  File "./mail2db.py", line 61, in storeattachment
>    cur.execute(statement ,attachDict)
>  File "/usr/lib/python2.4/site-packages/psycopg2/extras.py", line 88,
> in execute
>    return _cursor.execute(self, query, vars, async)
>  File "/usr/lib/python2.4/encodings/iso8859_1.py", line 18, in encode
>    return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
> in position 144: character maps to <undefined>

My guess is, your database is set up to hold ISO-8859-1 data
(Latin-1). You are giving it Unicode data, so it tries to encode as
Latin-1. The data includes a character that is not in Latin-1 so it
fails.

I would try explicitly converting the data to latin-1 before you send
it to the database, giving it one of the forgiving error handling
methods I referred to earlier. Or, change your database to UTF-8...

Kent

PS Please use Reply All to reply to the list.

From dwbarne at earthlink.net  Sat Oct  4 02:31:21 2008
From: dwbarne at earthlink.net (dwbarne at earthlink.net)
Date: Fri, 3 Oct 2008 20:31:21 -0400 (EDT)
Subject: [Tutor] keep from opening multiple Toplevel windows
Message-ID: <29227985.1223080282014.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net>

I have a Tkinter button widget that when pressed invokes a Toplevel window call each time. The Toplevel window thus generated has a close button on it. As you might guess, when multiple Toplevel windows are open, I can press on a 'close' button to '.destroy' the window, but all other Toplevel windows remain and do not respond to their 'close' buttons. I understand why THIS happens, but...

The behavior I seek is that one and only one Toplevel window gets generated no matter how many times the original Tkinter button is pressed. A new Toplevel is generated only after the previous one is closed.

My question is: how does one check that a particular Toplevel window is open? I've tried just checking on the Toplevel widget name with try-except, but the value of the Toplevel name stays persistent even when the .destroy method is used to kill the Toplevel window, which makes try-except think the Toplevel is still open. 

From ldl08 at gmx.net  Sat Oct  4 10:03:50 2008
From: ldl08 at gmx.net (David)
Date: Sat, 04 Oct 2008 16:03:50 +0800
Subject: [Tutor] some string operations
Message-ID: <48E72366.5040402@gmx.net>

Dear list,

one of the exercises in Zelle's book is:

given

import string
s1 = "spam"
s2 = "ni!"

show a Python expression that could construct the following result by 
performing string operations on s1 and s2:

"Spam Ni! Spam Ni! Spam Ni!".

I have two solutions:

a)
(string.capitalize(s1) + " " + string.capitalize( s2) + "  " ) * 3

b)
"%s %s " % (string.capitalize(s1), string.capitalize(s2)) * 3

Both seem to work, but they seem overly complex. Where could I improve?

Also, Python returns:

'Spam Ni! Spam Ni! Spam Ni! '

Which is not exactly "Spam Ni! Spam Ni! Spam Ni!" (note the final free 
space in my outcome). I am at a loss as to how to perfect my answer with 
regard to this issue.

Many thanks for helping me in my pythonic adventures!

David

From reed at reedobrien.com  Sat Oct  4 10:27:08 2008
From: reed at reedobrien.com (Reed O'Brien)
Date: Sat, 4 Oct 2008 04:27:08 -0400
Subject: [Tutor] some string operations
In-Reply-To: <48E72366.5040402@gmx.net>
References: <48E72366.5040402@gmx.net>
Message-ID: <C6640DCB-AEAC-4A74-B0DF-2637D3E1214D@reedobrien.com>

On Oct 4, 2008, at 4:03 AM, David wrote:

> Dear list,
>
> one of the exercises in Zelle's book is:
>
> given
>
> import string
> s1 = "spam"
> s2 = "ni!"
>
> show a Python expression that could construct the following result  
> by performing string operations on s1 and s2:
>
> "Spam Ni! Spam Ni! Spam Ni!".
>
> I have two solutions:
>
> a)
> (string.capitalize(s1) + " " + string.capitalize( s2) + "  " ) * 3
>
> b)
> "%s %s " % (string.capitalize(s1), string.capitalize(s2)) * 3
>
> Both seem to work, but they seem overly complex. Where could I  
> improve?
>
> Also, Python returns:
>
> 'Spam Ni! Spam Ni! Spam Ni! '
>
> Which is not exactly "Spam Ni! Spam Ni! Spam Ni!" (note the final  
> free space in my outcome). I am at a loss as to how to perfect my  
> answer with regard to this issue.

 >>>  s1, s2 = 'spam', 'ni!'
 >>> ' '.join([s.capitalize() for s in (s1, s2)] * 3)
'Spam Ni! Spam Ni! Spam Ni!'

HTH,
~ro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2421 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/dadc1b6b/attachment-0001.bin>

From alan.gauld at btinternet.com  Sat Oct  4 10:31:55 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 4 Oct 2008 09:31:55 +0100
Subject: [Tutor] some string operations
References: <48E72366.5040402@gmx.net>
Message-ID: <gc79ls$2m1$1@ger.gmane.org>


"David" <ldl08 at gmx.net> wrote

> I have two solutions:
>
> a)
> (string.capitalize(s1) + " " + string.capitalize( s2) + "  " ) * 3
> b)
> "%s %s " % (string.capitalize(s1), string.capitalize(s2)) * 3
>
> Both seem to work, but they seem overly complex. Where could I 
> improve?

Personally I'd go with b but avoid the string module and add an 
rstrip():

("%s %s " % (s1.capitalize(),s2.capitalize()) * 3).rstrip()

Or another approach:

"%s %s %s %s %s %s" % ((s1.capitalize(),s2.capitalize())*3)
'Foo Bar Foo Bar Foo Bar'

But the first is more flexible IMHO.

HTH,

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



From ldl08 at gmx.net  Sat Oct  4 12:11:35 2008
From: ldl08 at gmx.net (David)
Date: Sat, 04 Oct 2008 18:11:35 +0800
Subject: [Tutor] bug in exam score conversion program
Message-ID: <48E74157.3030507@gmx.net>

Hello!!

I just completed exercise 7 (chapter 4) in Zelle's book:
"A certain CS professor gives 100-point exams that are graded on the 
scale 90?100:A, 80?89:B, 70?79:C, 60?69:D, 60:F. Write a program that 
accepts an exam score as input and prints out the corresponding grade."

I am quite happy with my code, but there is a bug: if the score is 100, 
then the program calculates 100/10 = 10. However, the tuple runs to 9, 
leaving me with an error message: IndexError: tuple index out of range

I can't figure out how to solve that problem...
I also suspect that my code clearly exposes me as a beginner :-) What 
would be the pythonic way of solving that exercise?

# exam score to grade conversion
# Zelle, ch. 4, exercise 7
x = ("F", "F", "F", "F", "F", "E", "D", "C", "B", "A")
score = raw_input("What's your exam score (0-100)? ")
grade = x[int(score)/10]
print "Your grade is:", grade

I greatly appreciate your comments!

David

From sander.sweers at gmail.com  Sat Oct  4 13:17:05 2008
From: sander.sweers at gmail.com (Sander Sweers)
Date: Sat, 4 Oct 2008 13:17:05 +0200
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E74157.3030507@gmx.net>
References: <48E74157.3030507@gmx.net>
Message-ID: <b65fbb130810040417g46cb37c5x2fd863f9388e73f1@mail.gmail.com>

On Sat, Oct 4, 2008 at 12:11, David <ldl08 at gmx.net> wrote:
> I am quite happy with my code, but there is a bug: if the score is 100, then
> the program calculates 100/10 = 10. However, the tuple runs to 9, leaving me
> with an error message: IndexError: tuple index out of range
>
> I can't figure out how to solve that problem...
> I also suspect that my code clearly exposes me as a beginner :-) What would
> be the pythonic way of solving that exercise?
>
> # exam score to grade conversion
> # Zelle, ch. 4, exercise 7
> x = ("F", "F", "F", "F", "F", "E", "D", "C", "B", "A")
> score = raw_input("What's your exam score (0-100)? ")
> grade = x[int(score)/10]
> print "Your grade is:", grade

Python starts counting from zero so to access the first item in x it
would be x[0]. When you do x[10] you actually are requestting the 11th
value in x instead of the 10th and this does not exist.

You should be able to fix this yourself now.

Greets
Sander

From kent37 at tds.net  Sat Oct  4 13:28:10 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 07:28:10 -0400
Subject: [Tutor] some string operations
In-Reply-To: <48E72366.5040402@gmx.net>
References: <48E72366.5040402@gmx.net>
Message-ID: <1c2a2c590810040428o1b6e92f4r66d7a695f9ee637a@mail.gmail.com>

On Sat, Oct 4, 2008 at 4:03 AM, David <ldl08 at gmx.net> wrote:
> Dear list,
>
> one of the exercises in Zelle's book is:
>
> given
>
> import string
> s1 = "spam"
> s2 = "ni!"
>
> show a Python expression that could construct the following result by
> performing string operations on s1 and s2:

Note that most of the functions in the string module are also
available as string methods. The string methods are preferred, so
  string.capitalize(s1)
is more idiomatically written as
  s1.capitalize()

Kent

From srilyk at gmail.com  Sat Oct  4 13:28:59 2008
From: srilyk at gmail.com (W W)
Date: Sat, 4 Oct 2008 06:28:59 -0500
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E74157.3030507@gmx.net>
References: <48E74157.3030507@gmx.net>
Message-ID: <333efb450810040428m115ba4bdte96b7bd0b885439c@mail.gmail.com>

On Sat, Oct 4, 2008 at 5:11 AM, David <ldl08 at gmx.net> wrote:

> Hello!!

<snip>

I can't figure out how to solve that problem...
> I also suspect that my code clearly exposes me as a beginner :-) What would
> be the pythonic way of solving that exercise?
>
> # exam score to grade conversion
> # Zelle, ch. 4, exercise 7
> x = ("F", "F", "F", "F", "F", "E", "D", "C", "B", "A")
> score = raw_input("What's your exam score (0-100)? ")
> grade = x[int(score)/10]
> print "Your grade is:", grade


Wow! That's actually a really surprising way of solving this, and not
entirely bad. The easiest way of modifying this program is to do exactly
what you did with the "F"s, only with an "A".

I suspect most people would have created an if else chain:

if score >=  90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
elif score >= 60:
    grade = "D"
else:
    grade = "F"

print "Your grade is %s" % (grade, )

But in reality, there's nothing wrong with your method - as a matter of
fact, it's probably slightly more optimized (although we're talking in time
frames of < .00001 seconds) because rather than making comparisons it makes
one computation and then directly accesses the values stored in the tuple.

So, I'll compliment you for solving a problem in a way that I never would
have thought of, helping me to think outside the box! In addition a tuple is
an ideal variable here because it's constant - you cannot change the values
or size of a tuple, unlike a list or dictionary. Not that (at this point)
you're worried about malicious type users, but  it's always a good idea to
"fool proof" your code.

Well, I hope this helps both look at your problem a different way, as well
as solves your "bug" (in this case, a syntax error: the code behaves exactly
how it should, you just made an error in how you implemented your code.
Those will be your most common "bugs", from here until forever ;) )
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/c05dbe5a/attachment.htm>

From kent37 at tds.net  Sat Oct  4 13:45:02 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 07:45:02 -0400
Subject: [Tutor] UnicodeEncodeError
In-Reply-To: <1c2a2c590810031304o144a97eew6de9777ddcb1591e@mail.gmail.com>
References: <92559a100810031050s4cb2d4c5k1ee7e2508838788b@mail.gmail.com>
	<1c2a2c590810031123u310ec56btb61329fbbf3b2334@mail.gmail.com>
	<92559a100810031139j74fde327u20323b5e7fb84a22@mail.gmail.com>
	<1c2a2c590810031304o144a97eew6de9777ddcb1591e@mail.gmail.com>
Message-ID: <1c2a2c590810040445i1a427931l5895ecee06710c14@mail.gmail.com>

On Fri, Oct 3, 2008 at 4:04 PM, Kent Johnson <kent37 at tds.net> wrote:

> I would try explicitly converting the data to latin-1 before you send
> it to the database, giving it one of the forgiving error handling
> methods I referred to earlier. Or, change your database to UTF-8...

BTW to create a UTF-8 database in Postgres, use
  createdb -E utf-8 ...

Kent

From kent37 at tds.net  Sat Oct  4 14:23:29 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 08:23:29 -0400
Subject: [Tutor] keep from opening multiple Toplevel windows
In-Reply-To: <29227985.1223080282014.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net>
References: <29227985.1223080282014.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net>
Message-ID: <1c2a2c590810040523o364a885cm3170922ff5228674@mail.gmail.com>

On Fri, Oct 3, 2008 at 8:31 PM,  <dwbarne at earthlink.net> wrote:
> I have a Tkinter button widget that when pressed invokes a Toplevel window call each time. The Toplevel window thus generated has a close button on it. As you might guess, when multiple Toplevel windows are open, I can press on a 'close' button to '.destroy' the window, but all other Toplevel windows remain and do not respond to their 'close' buttons. I understand why THIS happens, but...
>
> The behavior I seek is that one and only one Toplevel window gets generated no matter how many times the original Tkinter button is pressed. A new Toplevel is generated only after the previous one is closed.

The way I would do this is to have the class containing the button
handler save a reference to the window. When the window is closed then
set the reference to None. Then the button handler can check to see if
it already has a window.

Alternately you could just create a single, hidden window at startup,
then the button shows the window and the close box just hides it
instead of destroying it.

From alan.gauld at btinternet.com  Sat Oct  4 15:34:46 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 4 Oct 2008 14:34:46 +0100
Subject: [Tutor] keep from opening multiple Toplevel windows
References: <29227985.1223080282014.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net>
Message-ID: <gc7rdn$i8l$1@ger.gmane.org>


<dwbarne at earthlink.net> wrote

> The behavior I seek is that one and only one Toplevel window
> gets generated no matter how many times the original Tkinter
> button is pressed.

Here is a minimal example of what I think you want?

Does that help?

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

--------------------------------------------------
# TestTopLevel.py

from Tkinter import *


class MainWin(Frame):
    def __init__(self, parent, sub=None):
        Frame.__init__(self, parent)
        self.parent = parent
        Label(self, text="This is the main window").pack()
        self.bShow = Button(self, text="Show Sub", command = 
self.doShow)
        self.bShow.pack()
        self.bQuit = Button(self, text="Quit", command = self.quit)
        self.bQuit.pack()
        self.sub = sub
        self.pack()

    def doShow(self):
       try: self.sub.deiconify()
       except:
           self.sub = SubWindow(self.parent)
           self.sub.withdraw()
           self.sub.deiconify()

class SubWindow(Toplevel):
    def __init__(self, parent):
        Toplevel.__init__(self, parent)
        Label(self, text="Child Window").pack()
        self.bClose = Button(self, text="Close", command=self.doClose)
        self.bClose.pack()
        self.withdraw()

    def doClose(self):
        self.withdraw()


def main():
   app = Tk()
   m = MainWin(app, SubWindow(app))
   app.mainloop()

if __name__ == "__main__": main()




From alan.gauld at btinternet.com  Sat Oct  4 15:45:46 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 4 Oct 2008 14:45:46 +0100
Subject: [Tutor] bug in exam score conversion program
References: <48E74157.3030507@gmx.net>
Message-ID: <gc7s2b$k4r$1@ger.gmane.org>

"David" <ldl08 at gmx.net> wrote

> I am quite happy with my code, but there is a bug: if the score is 
> 100, then the program calculates 100/10 = 10. However, the tuple 
> runs to 9, leaving me with an error message: IndexError: tuple index 
> out of range
>
> I can't figure out how to solve that problem...

> I also suspect that my code clearly exposes me as a beginner :-) 
> What would be the pythonic way of solving that exercise?
>
> # exam score to grade conversion
> # Zelle, ch. 4, exercise 7
> x = ("F", "F", "F", "F", "F", "E", "D", "C", "B", "A")
> score = raw_input("What's your exam score (0-100)? ")
> grade = x[int(score)/10]
> print "Your grade is:", grade

It's not too bad but I would probably use a dictionary rather
than the list - which avoids the index problem - and I'd do
the int conversion with raw_input::

Grades = {0:'F', 1:'F',2:'F',....8:'B', 9:'A',10:'A'}
score = int(raw_input("What's your exam score (0-100)? "))
print "Your grade is:", Grades[score/10]

HTH,

Alan G






From bcl at brianlane.com  Sat Oct  4 16:31:45 2008
From: bcl at brianlane.com (Brian C. Lane)
Date: Sat, 04 Oct 2008 07:31:45 -0700
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E74157.3030507@gmx.net>
References: <48E74157.3030507@gmx.net>
Message-ID: <48E77E51.2070200@brianlane.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David wrote:
> Hello!!
> 
> I just completed exercise 7 (chapter 4) in Zelle's book:
> "A certain CS professor gives 100-point exams that are graded on the
> scale 90?100:A, 80?89:B, 70?79:C, 60?69:D, 60:F. Write a program that
> accepts an exam score as input and prints out the corresponding grade."
> 

Just to throw in another method, I tend to use tables of for problems
like this. The requirements usually change so its easier to modify later:

# min, max, grade
grades = [  (90,100,'A'),
            (80, 89,'B'),
            (70, 79,'C'),
            (60, 69,'D'),
            ( 0, 59,'F'),
        ]

def getGrade(score):
    """
    Return a letter grade based on a score
    """
    for g in grades:
        if (score <= g[1]) and (score >= g[0]):
            return g[2]



- --
- ---[Office 71.6F]--[Outside 55.4F]--[Server 107.9F]--[Coaster 71.7F]---
- ---[       WSF KITSAP (366772980) @ 47 34.7811 -122 27.7554       ]---
Software, Linux, Microcontrollers             http://www.brianlane.com
AIS Parser SDK                                http://www.aisparser.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFI535RIftj/pcSws0RAldqAJ9yKYSyDArc/LZ6G47SwxUq4z8yAACgioyx
b9WnwDEQe8hSOuYbKuKo9sY=
=7lCV
-----END PGP SIGNATURE-----

From alan.gauld at btinternet.com  Sat Oct  4 17:52:26 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 4 Oct 2008 16:52:26 +0100
Subject: [Tutor] bug in exam score conversion program
References: <48E74157.3030507@gmx.net> <48E77E51.2070200@brianlane.com>
Message-ID: <gc83fr$894$1@ger.gmane.org>


"Brian C. Lane" <bcl at brianlane.com> wrote

> # min, max, grade
> grades = [  (90,100,'A'),
>            (80, 89,'B'),
>            (70, 79,'C'),
>            (60, 69,'D'),
>            ( 0, 59,'F'),
>        ]
>
> def getGrade(score):
>    """
>    Return a letter grade based on a score
>    """
>    for g in grades:
>        if (score <= g[1]) and (score >= g[0]):
>            return g[2]

Could be written more concisely as

for g in grades:
    if g[0] <= score <= g[1]:
        return g[2]




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






>
>
>
> - --
> - ---[Office 71.6F]--[Outside 55.4F]--[Server 107.9F]--[Coaster 
> 71.7F]---
> - ---[       WSF KITSAP (366772980) @ 47 34.7811 -122 
> 4       ]---
> Software, Linux, Microcontrollers 
> http://www.brianlane.com
> AIS Parser SDK 
> http://www.aisparser.com
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (Darwin)
> Comment: Remember Lexington Green!
>
> iD8DBQFI535RIftj/pcSws0RAldqAJ9yKYSyDArc/LZ6G47SwxUq4z8yAACgioyx
> b9WnwDEQe8hSOuYbKuKo9sY=
> =7lCV
> -----END PGP SIGNATURE-----
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From kent37 at tds.net  Sat Oct  4 18:58:08 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 12:58:08 -0400
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E77E51.2070200@brianlane.com>
References: <48E74157.3030507@gmx.net> <48E77E51.2070200@brianlane.com>
Message-ID: <1c2a2c590810040958n47d3db25m31d138a9985dccda@mail.gmail.com>

On Sat, Oct 4, 2008 at 10:31 AM, Brian C. Lane <bcl at brianlane.com> wrote:

>    for g in grades:
>        if (score <= g[1]) and (score >= g[0]):
>            return g[2]

I think tuple unpacking makes code like this more readable:

for lower, upper, grade in grades:
  if lower <= score <= upper:
    return grade

Kent

From kent37 at tds.net  Sat Oct  4 18:59:07 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 12:59:07 -0400
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <gc7s2b$k4r$1@ger.gmane.org>
References: <48E74157.3030507@gmx.net> <gc7s2b$k4r$1@ger.gmane.org>
Message-ID: <1c2a2c590810040959lb61f36bga7f6e06e667ea186@mail.gmail.com>

On Sat, Oct 4, 2008 at 9:45 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:

> It's not too bad but I would probably use a dictionary rather
> than the list - which avoids the index problem

Not sure how the dict is better - in either case, leaving off the
grade corresponding to a score of 100 will raise an exception.

Kent

From david at abbottdavid.com  Sat Oct  4 18:55:57 2008
From: david at abbottdavid.com (David)
Date: Sat, 04 Oct 2008 12:55:57 -0400
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E77E51.2070200@brianlane.com>
References: <48E74157.3030507@gmx.net> <48E77E51.2070200@brianlane.com>
Message-ID: <48E7A01D.4050101@abbottdavid.com>

When I run it from the idle it works perfect, but when I run it from a
file I get none, why is that?

>>> grades = [  (90,100,'A'),
            (80, 89,'B'),
            (70, 79,'C'),
            (60, 69,'D'),
            ( 0, 59,'F'),
        ]

>>> score = 66
>>> def getGrade(score):
    """
    Return a letter grade based on a score
    """
    for g in grades:
        if (score <= g[1]) and (score >= g[0]):
            return g[2]

>>> getGrade
<function getGrade at 0x84ec80>
>>> getGrade(score)
'D'
>>>

#!/usr/bin/python

grades = [  (90,100,'A'),
            (80, 89,'B'),
            (70, 79,'C'),
            (60, 69,'D'),
            ( 0, 59,'F'),
        ]

def getGrade(score):
    """
    Return a letter grade based on a score
    """
    for g in grades:
        if (score <= g[1]) and (score >= g[0]):
            return g[2]

score = raw_input("What is your exam score: (0-100)? ")
print getGrade
print getGrade(score)

What is your exam score: (0-100)? 66
<function getGrade at 0x2b4b2a310d70>
None

-- 
Have Fun,
David A.

Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com


From kent37 at tds.net  Sat Oct  4 19:23:33 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 4 Oct 2008 13:23:33 -0400
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E7A01D.4050101@abbottdavid.com>
References: <48E74157.3030507@gmx.net> <48E77E51.2070200@brianlane.com>
	<48E7A01D.4050101@abbottdavid.com>
Message-ID: <1c2a2c590810041023x24ba3c0exc3d1385249ab30aa@mail.gmail.com>

On Sat, Oct 4, 2008 at 12:55 PM, David <david at abbottdavid.com> wrote:
> When I run it from the idle it works perfect, but when I run it from a
> file I get none, why is that?
> score = raw_input("What is your exam score: (0-100)? ")

The value returned from raw_input() is a string; you have to convert
it to an int:
score = int(raw_input("What is your exam score: (0-100)? "))

Kent

From idragos at ymail.com  Sat Oct  4 19:18:01 2008
From: idragos at ymail.com (Dragos Ionescu)
Date: Sat, 4 Oct 2008 10:18:01 -0700 (PDT)
Subject: [Tutor] bug in exam score conversion program
Message-ID: <40291.97420.qm@web59904.mail.ac4.yahoo.com>

David try this:
?
score = input("What is your exam score: (0-100)? ")
print getGrade
print getGrade(score)


Regards,
Dragoshttp://scripts.mit.edu/~dionescu/pyworld/ 



----- Original Message ----
From: David <david at abbottdavid.com>
To: Brian C. Lane <bcl at brianlane.com>
Cc: tutor at python.org
Sent: Saturday, October 4, 2008 7:55:57 PM
Subject: Re: [Tutor] bug in exam score conversion program

When I run it from the idle it works perfect, but when I run it from a
file I get none, why is that?

>>> grades = [? (90,100,'A'),
? ? ? ? ? ? (80, 89,'B'),
? ? ? ? ? ? (70, 79,'C'),
? ? ? ? ? ? (60, 69,'D'),
? ? ? ? ? ? ( 0, 59,'F'),
? ? ? ? ]

>>> score = 66
>>> def getGrade(score):
? ? """
? ? Return a letter grade based on a score
? ? """
? ? for g in grades:
? ? ? ? if (score <= g[1]) and (score >= g[0]):
? ? ? ? ? ? return g[2]

>>> getGrade
<function getGrade at 0x84ec80>
>>> getGrade(score)
'D'
>>>

#!/usr/bin/python

grades = [? (90,100,'A'),
? ? ? ? ? ? (80, 89,'B'),
? ? ? ? ? ? (70, 79,'C'),
? ? ? ? ? ? (60, 69,'D'),
? ? ? ? ? ? ( 0, 59,'F'),
? ? ? ? ]

def getGrade(score):
? ? """
? ? Return a letter grade based on a score
? ? """
? ? for g in grades:
? ? ? ? if (score <= g[1]) and (score >= g[0]):
? ? ? ? ? ? return g[2]

score = raw_input("What is your exam score: (0-100)? ")
print getGrade
print getGrade(score)

What is your exam score: (0-100)? 66
<function getGrade at 0x2b4b2a310d70>
None

-- 
Have Fun,
David A.

Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com

_______________________________________________
Tutor maillist? -? Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/15fe5ac0/attachment.htm>

From bgailer at gmail.com  Sat Oct  4 21:15:10 2008
From: bgailer at gmail.com (bob gailer)
Date: Sat, 04 Oct 2008 15:15:10 -0400
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <48E74157.3030507@gmx.net>
References: <48E74157.3030507@gmx.net>
Message-ID: <48E7C0BE.4040803@gmail.com>

Lots of good responses. And now for something completely different:

import string
x = string.maketrans('567891', 'FDCBAA')
score = raw_input('score>')
print "Your grade is:", score[0].translate(x)

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From idragos at ymail.com  Sat Oct  4 21:42:30 2008
From: idragos at ymail.com (Dragos Ionescu)
Date: Sat, 4 Oct 2008 12:42:30 -0700 (PDT)
Subject: [Tutor] bug in exam score conversion program
Message-ID: <129771.61819.qm@web59915.mail.ac4.yahoo.com>

----- Original Message ----
From: bob gailer <bgailer at gmail.com>
To: David <ldl08 at gmx.net>
Cc: tutor at python.org
Sent: Saturday, October 4, 2008 10:15:10 PM
Subject: Re: [Tutor] bug in exam score conversion program

Lots of good responses. And now for something completely different:

import string
x = string.maketrans('567891', 'FDCBAA')
score = raw_input('score>')
print "Your grade is:", score[0].translate(x)

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

_______________________________________________
Tutor maillist? -? Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



Wow! Bob Gailer's solution is so elegant. Can someone plese explain what is the algorithm behind? string.maketrans.?More exactly,?how is this function doing the coding? 
?http://scripts.mit.edu/~dionescu/pyworld/



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/c39764f5/attachment.htm>

From steve at alchemy.com  Sat Oct  4 22:04:30 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Sat, 04 Oct 2008 13:04:30 -0700
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <129771.61819.qm@web59915.mail.ac4.yahoo.com>
References: <129771.61819.qm@web59915.mail.ac4.yahoo.com>
Message-ID: <48E7CC4E.1030908@alchemy.com>

Dragos Ionescu wrote:
> ----- Original Message ----
> From: bob gailer <bgailer at gmail.com>
> To: David <ldl08 at gmx.net>
> Cc: tutor at python.org
> Sent: Saturday, October 4, 2008 10:15:10 PM
> Subject: Re: [Tutor] bug in exam score conversion program
> 
> Lots of good responses. And now for something completely different:
> 
> import string
> x = string.maketrans('567891', 'FDCBAA')
> score = raw_input('score>')
> print "Your grade is:", score[0].translate(x)
> -- 
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
> 
> When we take the time to be aware of our feelings and
> needs we have more satisfying interatctions with others.
> 
> Nonviolent Communication provides tools for this awareness.
> 
> As a coach and trainer I can assist you in learning this process.
> 
> What is YOUR biggest relationship challenge?
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org <mailto:Tutor at python.org>
> http://mail.python.org/mailman/listinfo/tutor
>  
>  
> Wow! Bob Gailer's solution is so elegant. Can someone plese explain what 
> is the algorithm behind  string.maketrans. More exactly, how is this 
> function doing the coding?

Actually, I don't think the point was to be elegant as much
as to get you thinking about something you might not have
explored--never hurts to keep learning new features so you
don't inefficiently apply the same old small set of things
to new problems.

You wouldn't *really* want to implement a production grade
system like that, cute though it is.  This is setting up a
translation table mapping the first character in the score
to a letter grade.  So a 9 is changed to an A.  The obvious
problem though is how it handles a score of, say, "1".  Or,
for that matter, "37".


>  http://scripts.mit.edu/~dionescu/pyworld/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From idragos at ymail.com  Sat Oct  4 22:21:54 2008
From: idragos at ymail.com (Dragos Ionescu)
Date: Sat, 4 Oct 2008 13:21:54 -0700 (PDT)
Subject: [Tutor] bug in exam score conversion program
Message-ID: <467295.17049.qm@web59907.mail.ac4.yahoo.com>

---- Original Message ----
From: Steve Willoughby <steve at alchemy.com>
To: Dragos Ionescu <idragos at ymail.com>
Cc: bob gailer <bgailer at gmail.com>; David <ldl08 at gmx.net>; tutor at python.org
Sent: Saturday, October 4, 2008 11:04:30 PM
Subject: Re: [Tutor] bug in exam score conversion program

Dragos Ionescu wrote:
> ----- Original Message ----
> From: bob gailer <bgailer at gmail.com>
> To: David <ldl08 at gmx.net>
> Cc: tutor at python.org
> Sent: Saturday, October 4, 2008 10:15:10 PM
> Subject: Re: [Tutor] bug in exam score conversion program
> 
> Lots of good responses. And now for something completely different:
> 
> import string
> x = string.maketrans('567891', 'FDCBAA')
> score = raw_input('score>')
> print "Your grade is:", score[0].translate(x)
> -- 
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
> 
> When we take the time to be aware of our feelings and
> needs we have more satisfying interatctions with others..
> 
> Nonviolent Communication provides tools for this awareness.
> 
> As a coach and trainer I can assist you in learning this process.
> 
> What is YOUR biggest relationship challenge?
> 
> _______________________________________________
> Tutor maillist? -? Tutor at python.org <mailto:Tutor at python.org>
> http://mail.python.org/mailman/listinfo/tutor
>? 
>? 
> Wow! Bob Gailer's solution is so elegant. Can someone plese explain what 
> is the algorithm behind? string.maketrans. More exactly, how is this 
> function doing the coding?

Actually, I don't think the point was to be elegant as much
as to get you thinking about something you might not have
explored--never hurts to keep learning new features so you
don't inefficiently apply the same old small set of things
to new problems.

You wouldn't *really* want to implement a production grade
system like that, cute though it is.? This is setting up a
translation table mapping the first character in the score
to a letter grade.? So a 9 is changed to an A.? The obvious
problem though is how it handles a score of, say, "1".? Or,
for that matter, "37".


I know how string.maketrans works. I was wondering how to implement such a function. Would that be very hard? I must admit that I was 'surprised' when I printed x...

Thanks,
Dragos
http://scripts.mit.edu/~dionescu/pyworld


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/b4798cb4/attachment.htm>

From steve at alchemy.com  Sat Oct  4 22:27:17 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Sat, 04 Oct 2008 13:27:17 -0700
Subject: [Tutor] bug in exam score conversion program
In-Reply-To: <467295.17049.qm@web59907.mail.ac4.yahoo.com>
References: <467295.17049.qm@web59907.mail.ac4.yahoo.com>
Message-ID: <48E7D1A5.1020005@alchemy.com>

Dragos Ionescu wrote:
> ---- Original Message ----
> From: Steve Willoughby <steve at alchemy.com>
> To: Dragos Ionescu <idragos at ymail.com>
> Cc: bob gailer <bgailer at gmail.com>; David <ldl08 at gmx.net>; tutor at python.org
> Sent: Saturday, October 4, 2008 11:04:30 PM
> Subject: Re: [Tutor] bug in exam score conversion program
> 
> Dragos Ionescu wrote:
>  > ----- Original Message ----
>  > From: bob gailer <bgailer at gmail.com <mailto:bgailer at gmail.com>>
>  > To: David <ldl08 at gmx.net <mailto:ldl08 at gmx.net>>
>  > Cc: tutor at python.org <mailto:tutor at python.org>
>  > Sent: Saturday, October 4, 2008 10:15:10 PM
>  > Subject: Re: [Tutor] bug in exam score conversion program
>  >
>  > Lots of good responses. And now for something completely different:
>  >
>  > import string
>  > x = string.maketrans('567891', 'FDCBAA')
>  > score = raw_input('score>')
>  > print "Your grade is:", score[0].translate(x)
>  > --
>  > Bob Gailer
>  > Chapel Hill NC
>  > 919-636-4239
>  >
>  > When we take the time to be aware of our feelings and
>  > needs we have more satisfying interatctions with others.
>  >
>  > Nonviolent Communication provides tools for this awareness.
>  >
>  > As a coach and trainer I can assist you in learning this process.
>  >
>  > What is YOUR biggest relationship challenge?
>  >
>  > _______________________________________________
>  > Tutor maillist  -  Tutor at python.org <mailto:Tutor at python.org> 
> <mailto:Tutor at python.org <mailto:Tutor at python.org>>
>  > http://mail.python.org/mailman/listinfo/tutor
>  > 
>  > 
>  > Wow! Bob Gailer's solution is so elegant. Can someone plese explain what
>  > is the algorithm behind  string.maketrans. More exactly, how is this
>  > function doing the coding?
> 
> Actually, I don't think the point was to be elegant as much
> as to get you thinking about something you might not have
> explored--never hurts to keep learning new features so you
> don't inefficiently apply the same old small set of things
> to new problems.
> 
> You wouldn't *really* want to implement a production grade
> system like that, cute though it is.  This is setting up a
> translation table mapping the first character in the score
> to a letter grade.  So a 9 is changed to an A.  The obvious
> problem though is how it handles a score of, say, "1".  Or,
> for that matter, "37".
> 
> 
> I know how string.maketrans works. I was wondering how to implement such 
> a function. Would that be very hard? I must admit that I was 'surprised' 
> when I printed x...

How to implement... the equivalent of maketrans/translate?  Pretty
easy really.  maketrans just builds a 256-byte table showing a mapping
from one character set to another (compare perl's y/// or tr///).  Once 
you have that translation table, all you really need to do is take each 
character of a string and make a new string by looking up each source 
character and returning what the table says (effectively table[ord(i)] 
for each character i in the source string).  Which is pretty much
what string.translate() is doing.

or did I misunderstand which function you wanted to implement?

From Jaggojaggo+Py at gmail.com  Sat Oct  4 23:08:58 2008
From: Jaggojaggo+Py at gmail.com (Omer)
Date: Sun, 5 Oct 2008 00:08:58 +0300
Subject: [Tutor] Tutor Archives and PC Crash
In-Reply-To: <gbu5ho$fbk$1@ger.gmane.org>
References: <48E26FAB.5010206@sbcglobal.net>
	<d06401780809301138y26b88a67kb96454dd6b92a651@mail.gmail.com>
	<gbu5ho$fbk$1@ger.gmane.org>
Message-ID: <515008f10810041408q6002c04ble8342f81b083215d@mail.gmail.com>

(Or you could start using Gmail, which conveniantly archives Qs with their
As, based on subject line,)

On Wed, Oct 1, 2008 at 12:26 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "Danny Yoo" <dyoo at cs.wpi.edu> wrote in message
> news:d06401780809301138y26b88a67kb96454dd6b92a651 at mail.gmail.com...
>
>> Yup.  See:
>>
>>   http://mail.python.org/pipermail/tutor/
>>
>> for the archive.  There's also a searchable interface from GMANE:
>>
>>   http://dir.gmane.org/gmane.comp.python.tutor
>>
>
>
> And another at ActiveState.com
>
> http://lists.activestate.com/tutor at python.org
>
> Alan G
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081005/86a1f211/attachment.htm>

From Jaggojaggo+Py at gmail.com  Sat Oct  4 23:13:43 2008
From: Jaggojaggo+Py at gmail.com (Omer)
Date: Sun, 5 Oct 2008 00:13:43 +0300
Subject: [Tutor] Text Scatter Plots?
In-Reply-To: <117875730794.20081001094923@columbus.rr.com>
References: <48E0BD38.9000904@sbcglobal.net>
	<117875730794.20081001094923@columbus.rr.com>
Message-ID: <515008f10810041413i6f7c6396xccfac23c695800f9@mail.gmail.com>

You could check out Google Visualization API. supposed to be fairly nifty;
haven't had time to check it out myself though.

On Wed, Oct 1, 2008 at 4:49 PM, R. Alan Monroe <amonroe at columbus.rr.com>wrote:

> > Is there a text graphics module that does say scatter plots or
> > histograms? I'm thinking of stuff prior to the graphics era of
> > computing. I'm looking for something really simple.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081005/2eaa78a3/attachment-0001.htm>

From alan.gauld at btinternet.com  Sun Oct  5 01:55:50 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 5 Oct 2008 00:55:50 +0100
Subject: [Tutor] bug in exam score conversion program
References: <48E74157.3030507@gmx.net> <gc7s2b$k4r$1@ger.gmane.org>
	<1c2a2c590810040959lb61f36bga7f6e06e667ea186@mail.gmail.com>
Message-ID: <gc8vq7$lh5$1@ger.gmane.org>


"Kent Johnson" <kent37 at tds.net> wrote

>> It's not too bad but I would probably use a dictionary rather
>> than the list - which avoids the index problem
> 
> Not sure how the dict is better - in either case, leaving off the
> grade corresponding to a score of 100 will raise an exception.

Sure, you could just extend the list to have 11 elements 
but its less obvious than with the dictionary which for this purpose 
provides a self documenting mapping between the score and 
the grade. IMHO of course :-)

Alan G.




From alan.gauld at btinternet.com  Sun Oct  5 02:01:31 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 5 Oct 2008 01:01:31 +0100
Subject: [Tutor] bug in exam score conversion program
References: <48E74157.3030507@gmx.net> <48E77E51.2070200@brianlane.com>
	<48E7A01D.4050101@abbottdavid.com>
Message-ID: <gc904s$m9p$1@ger.gmane.org>


"David" <david at abbottdavid.com> wrote

> When I run it from the idle it works perfect, but when I run it from 
> a
> file I get none, why is that?
>
>
>>>> score = 66

Here you directly assign a number to score

> #!/usr/bin/python
>
> score = raw_input("What is your exam score: (0-100)? ")

Here you assign a string - the result of raw_input

> print getGrade(score)

But getGrade expects to get an integer so yo need to
convert score to an int either when you pass it to getGrade
or, more usually, the return value from raw_input.

Passing a string to getGrade means it never finds a match
so never returns a grade and instead falls off the bottom with
no specified return value. When this happens Python inserts
a default return value of None

HTH,

Alan G 



From alan.gauld at btinternet.com  Sun Oct  5 02:03:48 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 5 Oct 2008 01:03:48 +0100
Subject: [Tutor] bug in exam score conversion program
References: <40291.97420.qm@web59904.mail.ac4.yahoo.com>
Message-ID: <gc9096$mgo$1@ger.gmane.org>


"Dragos Ionescu" <idragos at ymail.com> wrote 

> David try this:
>
> score = input("What is your exam score: (0-100)? ")

No, please don't! input has several security issues, it is 
much better to use raw_input but convert the result to 
the type you need:

score = int(raw_input("What is your exam score: (0-100)? "))


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


From bgailer at gmail.com  Sun Oct  5 03:38:36 2008
From: bgailer at gmail.com (bob gailer)
Date: Sat, 04 Oct 2008 21:38:36 -0400
Subject: [Tutor] Reading Files and Such
In-Reply-To: <515008f10810041404j356a46ffle8eabc0c6a5789d1@mail.gmail.com>
References: <48E0BBB5.2050206@sbcglobal.net> <48E1566C.1090107@gmail.com>
	<515008f10810041404j356a46ffle8eabc0c6a5789d1@mail.gmail.com>
Message-ID: <48E81A9C.2010101@gmail.com>

Jaggo wrote:
> So, am I to understand from this lack of response there be *no 
> particular reason* to use Temp file?

AFAIC there is no particular reason to use Temp file. It is a 
convenience for those of us who need temp files and don't want to bother 
creating unique names.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From Jaggojaggo+Py at gmail.com  Sun Oct  5 18:38:23 2008
From: Jaggojaggo+Py at gmail.com (Omer)
Date: Sun, 5 Oct 2008 18:38:23 +0200
Subject: [Tutor] dealing with user input whose value I don't know
In-Reply-To: <48E5CDAA.9090900@gmx.net>
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com>
	<48E50728.8020605@gmx.net> <20081002174911.GF98291@dragon.alchemy.com>
	<20081002175456.GA26406@ayn.mi.celestial.com>
	<48E50DB7.8030704@gmx.net> <gc3n1u$lrd$1@ger.gmane.org>
	<48E5CDAA.9090900@gmx.net>
Message-ID: <515008f10810050938h1929198bl3b9d58a1f4e6b762@mail.gmail.com>

On Fri, Oct 3, 2008 at 9:45 AM, David <ldl08 at gmx.net> wrote:

> Here is the code:
>
> def main():
>   import string
>

Hey,
lagging a bit behind the list,

"import string" is unnecessary, mate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081005/9d8090d9/attachment.htm>

From bermanrl at embarqmail.com  Sun Oct  5 19:52:07 2008
From: bermanrl at embarqmail.com (Robert Berman)
Date: Sun, 05 Oct 2008 13:52:07 -0400
Subject: [Tutor] More Pythonesque or a more efficient method
Message-ID: <48E8FEC7.5090000@embarqmail.com>

Hi,

The below script which prints anagrams available for any word available 
within a given database. It does work, but  it is not very fast. I am 
relatively certain there are more Python friendly coding techniques but 
I am more concerned with a faster algorithm.

The database item consists of the key; the actual word, and the value, 
the size as a string. For example, the word 'myth' is represented as 
key= 'myth', value = '4'.  I think the slow part of the algorithm is the 
script retrieves a list of all database words of length (myth)=4. That's 
a lot of words. Each word is sorted  and then compared to the alpha 
sorted word. When there is a match, that word becomes a part of the 
anagram list. Even a very basic look at the word 'myth' shows there are 
no anagrams. So, to return an empty list, we have scanned all words in 
the database of size 4.

I will be happy to send the first program and the original word file to 
anyone who would like to implement  the database. I could not  attach 
the database since  that made this post  way too large.

Any and all suggestions are most welcome.

#!/usr/bin/env python

##The second program is in a perpetual loop waiting on input. A 'Q ' 
will terminate the program.
##All input is by string; for example the word 'zygote' without the 
quotes is a request for all possible anagrams
##created from all the letters in 'zygote'.

def get_key(d1, value):
   return [item[0] for item in d1.items() if item[1] == value]

def Get_Anagrams(db,word):
   Alist=list()
   tulip1=tuple(word)
   list1=list(tulip1)
   list1.sort()
   wordlist=get_key(db,str(len(word)))
   for items in wordlist:
       if items != word:
           tulip2=tuple(items)
           list2=list(tulip2)
           list2.sort()
           if list2==list1:
               Alist.append(items)
   if len(Alist)>0:
       return Alist
   else:
       return None


def main():
   import anydbm
   db=anydbm.open('anagram.db','r')
   Repeat=True
   while Repeat != False:
       word_in=str(raw_input('Input a word to build anagrams\nA Q will 
quit the program: '))
       if word_in=='Q':
           Repeat = False
       else:
           if db.has_key(word_in) < 1:
               print word_in,'  is not in the dictionary\n'
           else:
               Anagrams=Get_Anagrams(db,word_in)
               if Anagrams != None:
                   print  'Anagrams for ',word_in,' are ',Anagrams
               else:
                   print word_in,' has no anagrams.'
   db.close
   return 0

if __name__ == '__main__': main()


Thanks,

Robert

From kent37 at tds.net  Sun Oct  5 20:45:58 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 5 Oct 2008 14:45:58 -0400
Subject: [Tutor] PYTHON 26 DOESN'T MATCH TUTORIAL
In-Reply-To: <48E87076.3020705@SOCAL.RR.COM>
References: <48E87076.3020705@SOCAL.RR.COM>
Message-ID: <1c2a2c590810051145jb717795rc19dbeaad2daea05@mail.gmail.com>

On Sun, Oct 5, 2008 at 3:44 AM, WM <WFERGUSON1 at socal.rr.com> wrote:
> I am trying to learn PYTHON from scratch using two screens; the tutor and
> IDLE.  The first two lessons went OK but the third (IF and ELSE IF) just do
> not work.  When I try ELSE I get >>> without any further indent.  When I did
> COPY and PASTE I got showered with incomprehensible error messages.  I did
> this because I wondered if I were screwing up with my keyboarding.

Can you copy / paste the IDLE session to an email?

My guess is that you entered an extra line before the else. You should
just backspace to remove the indent.
>
> Is this what you do?  Answer about beginners' problems?  I just subscribed
> to the list; this is my first query.

Yes, pretty much. You should send your question to tutor at python.org,
though. tutor-owner just goes to  the list maintainers, not to the
entire list. When you reply, use Reply All so your reply also goes to
the list.

Kent

From kent37 at tds.net  Sun Oct  5 20:54:04 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 5 Oct 2008 14:54:04 -0400
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <48E8FEC7.5090000@embarqmail.com>
References: <48E8FEC7.5090000@embarqmail.com>
Message-ID: <1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>

On Sun, Oct 5, 2008 at 1:52 PM, Robert Berman <bermanrl at embarqmail.com> wrote:

> The database item consists of the key; the actual word, and the value, the
> size as a string. For example, the word 'myth' is represented as key=
> 'myth', value = '4'.  I think the slow part of the algorithm is the script
> retrieves a list of all database words of length (myth)=4. That's a lot of
> words. Each word is sorted  and then compared to the alpha sorted word. When
> there is a match, that word becomes a part of the anagram list. Even a very
> basic look at the word 'myth' shows there are no anagrams. So, to return an
> empty list, we have scanned all words in the database of size 4.

This is pretty inefficient, yes. You actually scan every word in the
database because you have to find the ones of length 4. You are really
using the database as just a list of words. A better data structure
would be to index by word length with the value being a list of words
of that length. Even better would be to index by the sorted letters in
the word, with the value being a list of all words with that sorting.

Kent

From bermanrl at embarqmail.com  Sun Oct  5 21:01:19 2008
From: bermanrl at embarqmail.com (Robert Berman)
Date: Sun, 05 Oct 2008 15:01:19 -0400
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>
References: <48E8FEC7.5090000@embarqmail.com>
	<1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>
Message-ID: <48E90EFF.9070101@embarqmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081005/f1f63fe9/attachment.htm>

From alan.gauld at btinternet.com  Mon Oct  6 01:30:37 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 6 Oct 2008 00:30:37 +0100
Subject: [Tutor] dealing with user input whose value I don't know
References: <OF14CD0942.26E1CC97-ON852574D6.005E95AF-852574D6.005F79AD@gm.com><48E50728.8020605@gmx.net>
	<20081002174911.GF98291@dragon.alchemy.com><20081002175456.GA26406@ayn.mi.celestial.com><48E50DB7.8030704@gmx.net>
	<gc3n1u$lrd$1@ger.gmane.org><48E5CDAA.9090900@gmx.net>
	<515008f10810050938h1929198bl3b9d58a1f4e6b762@mail.gmail.com>
Message-ID: <gcbimv$fi$1@ger.gmane.org>


"Omer" <Jaggojaggo+Py at gmail.com> wrote 

>> Here is the code:
>>
>> def main():
>>   import string
>>
> "import string" is unnecessary, mate.

Not entirely true since the code uses string.split()
However since the split method of the string could 
be used instead then that would indeed render the 
import unnecessary. But you need both changes.

Alan G


From WFERGUSON1 at SOCAL.RR.COM  Mon Oct  6 04:51:53 2008
From: WFERGUSON1 at SOCAL.RR.COM (WM)
Date: Sun, 05 Oct 2008 19:51:53 -0700
Subject: [Tutor] IF statements
Message-ID: <48E97D49.9060903@SOCAL.RR.COM>

I used to do Basic and enjoyed it.  Someone said Python was a vastly 
better language than Visual Basic, which I considered playing with.  So 
I sought to give it a go but struck a sticking point very early.
I am now going through the Python tutorial.  All went well until I came 
to IF.  The code below was not written by me.  It is a copy/paste job 
from the tutor.  I do not have any idea what is going wrong.

IDLE 2.6     
 >>>
 >>>
 >>> x = int(raw_input("Please enter an integer: "))
Please enter an integer: 42
 >>> if x < 0:
...      x = 0
...      print 'Negative changed to zero'
... elif x == 0:
...      print 'Zero'
... elif x == 1:
...      print 'Single'
... else:
...      print 'More'
...
More
12
SyntaxError: invalid syntax
 >>>


From gods_bud666 at hotmail.com  Mon Oct  6 05:27:39 2008
From: gods_bud666 at hotmail.com (Anthony Smith)
Date: Sun, 5 Oct 2008 20:27:39 -0700
Subject: [Tutor] first call - newcomer
Message-ID: <BLU146-W21D0F815F794C49517F301CA390@phx.gbl>


This is my first post - I will be brief...
 
One:  I have programmed before - but it has been DECADES...so just a few simple queries:
 
1.  A brief (but complete) description regarding the use of script editor (I will be using
     command prompt in Windows), as:
 
         a.  details about loading and saving programs (not in that order) and little
              specs about pathnames or other requirements (I will probably store all
              my little goodies in one folder or space).
 
      That should get me going ... a book and manual by my side should suffice for
       the rest - - - except for one thing:
 
2.  I have been unable to locate the gizmo in the literature to get ascii codes
    in python.  In the old days, it was a list of 256 (or so) characters that 
    represented all keyboard symbols (A equalled 36; B equalled 37; et cetera).
   To assign a value, you used "Let A$ = ASC (36)" where A$ was a variable
    and 36 was the ASCII value for 'A'.  I believe the reverse of this process
    was PRINT VAL(A$) or something.  I want to play with a program that will
   assign a number to a word (using a simple algorhythm that will give a
    specific number to every word).  Other stuff is pretty easy to find with
    the book and on-line literature.  I will need to get an ascii code out of
     a string (whose content is not known to the programmer, as raw_input).
    Then to assign, I will need the actual list with assigned numbers.
 
You will be giving me probably the only boost I will need!  I will be available later on,
if I want to take part in the ask/answer system here.
 
 
Thanks a lot,
 
Anthony
 
8:27 pm PST October 4th, 2008
 
 
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081005/d178c2a2/attachment-0001.htm>

From lie.1296 at gmail.com  Mon Oct  6 07:46:49 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Mon, 06 Oct 2008 12:46:49 +0700
Subject: [Tutor] Tutor Digest, Vol 56, Issue 22
In-Reply-To: <mailman.16704.1223263963.3486.tutor@python.org>
References: <mailman.16704.1223263963.3486.tutor@python.org>
Message-ID: <1223272009.6409.8.camel@lieryan-laptop>

On Mon, 2008-10-06 at 05:32 +0200, tutor-request at python.org wrote:
> 
> Message: 8
> Date: Sun, 5 Oct 2008 20:27:39 -0700
> From: Anthony Smith <gods_bud666 at hotmail.com>
> Subject: [Tutor] first call - newcomer
> To: <tutor at python.org>
> Message-ID: <BLU146-W21D0F815F794C49517F301CA390 at phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> 
> This is my first post - I will be brief...
>  
> One:  I have programmed before - but it has been DECADES...so just a
> few simple queries:
>  
> 1.  A brief (but complete) description regarding the use of script
> editor (I will be using

Your script editor can be any plain text-editing tools, Notepad could
do.

>      command prompt in Windows), as:
>  
>          a.  details about loading and saving programs (not in that
> order) and little
>               specs about pathnames or other requirements (I will
> probably store all
>               my little goodies in one folder or space).

Pathnames is free, you can name your program anything your OS allows for
a file. A convention is to name the script ending with .py/.pyw
extension (command-line script/GUI script), although python doesn't
complain if it is not in those extension (in Windows, the extension is
associated with the interpreter). Calling a program from command line is
done like this:

python filename.py

>       That should get me going ... a book and manual by my side should
> suffice for
>        the rest - - - except for one thing:

> 2.  I have been unable to locate the gizmo in the literature to get
> ascii codes
>     in python.  In the old days, it was a list of 256 (or so)
> characters that 
>     represented all keyboard symbols (A equalled 36; B equalled 37; et
> cetera).
>    To assign a value, you used "Let A$ = ASC (36)" where A$ was a
> variable
>     and 36 was the ASCII value for 'A'.  I believe the reverse of this
> process
>     was PRINT VAL(A$) or something.  I want to play with a program
> that will
>    assign a number to a word (using a simple algorhythm that will give
> a
>     specific number to every word).  Other stuff is pretty easy to
> find with
>     the book and on-line literature.  I will need to get an ascii code
> out of
>      a string (whose content is not known to the programmer, as
> raw_input).
>     Then to assign, I will need the actual list with assigned numbers.

a = ord('A')
b = chr(36)

-- read on the help file: Built-in Functions
 
> You will be giving me probably the only boost I will need!  I will be
> available later on,
> if I want to take part in the ask/answer system here.


From lie.1296 at gmail.com  Mon Oct  6 07:46:49 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Mon, 06 Oct 2008 12:46:49 +0700
Subject: [Tutor] Tutor Digest, Vol 56, Issue 22
In-Reply-To: <mailman.16704.1223263963.3486.tutor@python.org>
References: <mailman.16704.1223263963.3486.tutor@python.org>
Message-ID: <1223272009.6409.8.camel@lieryan-laptop>

On Mon, 2008-10-06 at 05:32 +0200, tutor-request at python.org wrote:
> 
> Message: 8
> Date: Sun, 5 Oct 2008 20:27:39 -0700
> From: Anthony Smith <gods_bud666 at hotmail.com>
> Subject: [Tutor] first call - newcomer
> To: <tutor at python.org>
> Message-ID: <BLU146-W21D0F815F794C49517F301CA390 at phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> 
> This is my first post - I will be brief...
>  
> One:  I have programmed before - but it has been DECADES...so just a
> few simple queries:
>  
> 1.  A brief (but complete) description regarding the use of script
> editor (I will be using

Your script editor can be any plain text-editing tools, Notepad could
do.

>      command prompt in Windows), as:
>  
>          a.  details about loading and saving programs (not in that
> order) and little
>               specs about pathnames or other requirements (I will
> probably store all
>               my little goodies in one folder or space).

Pathnames is free, you can name your program anything your OS allows for
a file. A convention is to name the script ending with .py/.pyw
extension (command-line script/GUI script), although python doesn't
complain if it is not in those extension (in Windows, the extension is
associated with the interpreter). Calling a program from command line is
done like this:

python filename.py

>       That should get me going ... a book and manual by my side should
> suffice for
>        the rest - - - except for one thing:

> 2.  I have been unable to locate the gizmo in the literature to get
> ascii codes
>     in python.  In the old days, it was a list of 256 (or so)
> characters that 
>     represented all keyboard symbols (A equalled 36; B equalled 37; et
> cetera).
>    To assign a value, you used "Let A$ = ASC (36)" where A$ was a
> variable
>     and 36 was the ASCII value for 'A'.  I believe the reverse of this
> process
>     was PRINT VAL(A$) or something.  I want to play with a program
> that will
>    assign a number to a word (using a simple algorhythm that will give
> a
>     specific number to every word).  Other stuff is pretty easy to
> find with
>     the book and on-line literature.  I will need to get an ascii code
> out of
>      a string (whose content is not known to the programmer, as
> raw_input).
>     Then to assign, I will need the actual list with assigned numbers.

a = ord('A')
b = chr(36)

-- read on the help file: Built-in Functions
 
> You will be giving me probably the only boost I will need!  I will be
> available later on,
> if I want to take part in the ask/answer system here.


From alan.gauld at btinternet.com  Mon Oct  6 10:31:04 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 6 Oct 2008 09:31:04 +0100
Subject: [Tutor] IF statements
References: <48E97D49.9060903@SOCAL.RR.COM>
Message-ID: <gccicb$436$1@ger.gmane.org>

"WM" <WFERGUSON1 at SOCAL.RR.COM> wrote

> to IF.  The code below was not written by me.  It is a copy/paste 
> job from the tutor.  I do not have any idea what is going wrong.

> >>> x = int(raw_input("Please enter an integer: "))
> Please enter an integer: 42
> >>> if x < 0:
> ...      x = 0
> ...      print 'Negative changed to zero'
> ... elif x == 0:
> ...      print 'Zero'
> ... elif x == 1:
> ...      print 'Single'
> ... else:
> ...      print 'More'
> ...
> More
> 12
> SyntaxError: invalid syntax

It looks as if you maybe cut more than you intended?
Also I'm not sure about the ... prompts. I don't have 2.6 yet
so maybe its an enhancement to IDLE but notmally IDLE
doesn't print ... prompts. Did you cut n paste them too?
If so that would confuse IDLE.

HTH,

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



From alan.gauld at btinternet.com  Mon Oct  6 10:38:14 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 6 Oct 2008 09:38:14 +0100
Subject: [Tutor] first call - newcomer
References: <BLU146-W21D0F815F794C49517F301CA390@phx.gbl>
Message-ID: <gccipp$5bk$1@ger.gmane.org>


"Anthony Smith" <gods_bud666 at hotmail.com> wrote

> This is my first post - I will be brief...

Hi, welcome to tutor :-)

> 1.  A brief (but complete) description regarding the use of script
> editor (I will be using command prompt in Windows), as:

Brief and Complete don;t normally go together!
If you are using IDLE then Danny yoo's intro is a good place to start.
The IDLE section of the Python web site has a more detailed run
through oof the faciilities.

         a.  details about loading and saving programs (not in that 
order) and little
              specs about pathnames or other requirements (I will 
probably store all
              my little goodies in one folder or space).

As to paths:

PATH should be set to the folder where the Python interpreters live
PYTHONPATH should be set to include the folder where your code lives

> 2.  I have been unable to locate the gizmo in the literature to get 
> ascii codes
>     in python.

chr(n) is the function you need
ord(c) is the one in the opposite direction

but...

>    was PRINT VAL(A$) or something.

Python will generally figure out what you want to print without
explicit conversions, certainly fewer than you will be used to
from the early BASIC versions.

>     assign a number to a word (using a simple algorhythm that will 
> give a
>     specific number to every word).  Other stuff is pretty easy to 
> find with
>     the book and on-line literature.  I will need to get an ascii 
> code out of
>     a string (whose content is not known to the programmer, as 
> raw_input).
>     Then to assign, I will need the actual list with assigned 
> numbers.

OK, You lost me here.
Can you give an example of what the data would look like?

HTH,

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



From kent37 at tds.net  Mon Oct  6 12:46:19 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 06:46:19 -0400
Subject: [Tutor] IF statements
In-Reply-To: <48E97D49.9060903@SOCAL.RR.COM>
References: <48E97D49.9060903@SOCAL.RR.COM>
Message-ID: <1c2a2c590810060346i1e6f8a8jc0fdba5e954c56b@mail.gmail.com>

On Sun, Oct 5, 2008 at 10:51 PM, WM <WFERGUSON1 at socal.rr.com> wrote:
> I used to do Basic and enjoyed it.  Someone said Python was a vastly better
> language than Visual Basic, which I considered playing with.  So I sought to
> give it a go but struck a sticking point very early.
> I am now going through the Python tutorial.  All went well until I came to
> IF.  The code below was not written by me.  It is a copy/paste job from the
> tutor.  I do not have any idea what is going wrong.
>
> IDLE 2.6     >>>
>>>>
>>>> x = int(raw_input("Please enter an integer: "))
> Please enter an integer: 42
>>>> if x < 0:
> ...      x = 0
> ...      print 'Negative changed to zero'
> ... elif x == 0:
> ...      print 'Zero'
> ... elif x == 1:
> ...      print 'Single'
> ... else:
> ...      print 'More'
> ...
> More
> 12
> SyntaxError: invalid syntax
>>>>

Did you paste the >>> and ... or were they printed by the interpreter?
Examples often show the entire contents of a session in the
interpreter, including the >>> and ... prompts. When you enter the
example yourself you should not include them. Also "Please enter an
integer: " is output from the program and "42" is user input to the
program, you should not paste either of them.

Where did the 12 come from? It looks like interpreter output but there
is nothing preceding it that would print a 12.

Kent

From rajeev1204 at gmail.com  Mon Oct  6 13:24:57 2008
From: rajeev1204 at gmail.com (Rajeev Nair)
Date: Mon, 6 Oct 2008 16:54:57 +0530
Subject: [Tutor] IF Statements
Message-ID: <eec116310810060424m6a3701d7pbf3cbdd387c743b9@mail.gmail.com>

also i believe the first line can also be written as 'x = input('enter
.......') instead of using x=int(raw_input('......') . use raw_input for
string and just input for integer.



regards

rajeev

On Mon, Oct 6, 2008 at 3:30 PM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>        tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>        tutor-request at python.org
>
> You can reach the person managing the list at
>        tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: Tutor Digest, Vol 56, Issue 22 (Lie Ryan)
>   2. Re: Tutor Digest, Vol 56, Issue 22 (Lie Ryan)
>   3. Re: IF statements (Alan Gauld)
>   4. Re: first call - newcomer (Alan Gauld)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 06 Oct 2008 12:46:49 +0700
> From: Lie Ryan <lie.1296 at gmail.com>
> Subject: Re: [Tutor] Tutor Digest, Vol 56, Issue 22
> To: tutor at python.org
> Message-ID: <1223272009.6409.8.camel at lieryan-laptop>
> Content-Type: text/plain
>
> On Mon, 2008-10-06 at 05:32 +0200, tutor-request at python.org wrote:
> >
> > Message: 8
> > Date: Sun, 5 Oct 2008 20:27:39 -0700
> > From: Anthony Smith <gods_bud666 at hotmail.com>
> > Subject: [Tutor] first call - newcomer
> > To: <tutor at python.org>
> > Message-ID: <BLU146-W21D0F815F794C49517F301CA390 at phx.gbl>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> >
> > This is my first post - I will be brief...
> >
> > One:  I have programmed before - but it has been DECADES...so just a
> > few simple queries:
> >
> > 1.  A brief (but complete) description regarding the use of script
> > editor (I will be using
>
> Your script editor can be any plain text-editing tools, Notepad could
> do.
>
> >      command prompt in Windows), as:
> >
> >          a.  details about loading and saving programs (not in that
> > order) and little
> >               specs about pathnames or other requirements (I will
> > probably store all
> >               my little goodies in one folder or space).
>
> Pathnames is free, you can name your program anything your OS allows for
> a file. A convention is to name the script ending with .py/.pyw
> extension (command-line script/GUI script), although python doesn't
> complain if it is not in those extension (in Windows, the extension is
> associated with the interpreter). Calling a program from command line is
> done like this:
>
> python filename.py
>
> >       That should get me going ... a book and manual by my side should
> > suffice for
> >        the rest - - - except for one thing:
>
> > 2.  I have been unable to locate the gizmo in the literature to get
> > ascii codes
> >     in python.  In the old days, it was a list of 256 (or so)
> > characters that
> >     represented all keyboard symbols (A equalled 36; B equalled 37; et
> > cetera).
> >    To assign a value, you used "Let A$ = ASC (36)" where A$ was a
> > variable
> >     and 36 was the ASCII value for 'A'.  I believe the reverse of this
> > process
> >     was PRINT VAL(A$) or something.  I want to play with a program
> > that will
> >    assign a number to a word (using a simple algorhythm that will give
> > a
> >     specific number to every word).  Other stuff is pretty easy to
> > find with
> >     the book and on-line literature.  I will need to get an ascii code
> > out of
> >      a string (whose content is not known to the programmer, as
> > raw_input).
> >     Then to assign, I will need the actual list with assigned numbers.
>
> a = ord('A')
> b = chr(36)
>
> -- read on the help file: Built-in Functions
>
> > You will be giving me probably the only boost I will need!  I will be
> > available later on,
> > if I want to take part in the ask/answer system here.
>
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 06 Oct 2008 12:46:49 +0700
> From: Lie Ryan <lie.1296 at gmail.com>
> Subject: Re: [Tutor] Tutor Digest, Vol 56, Issue 22
> To: tutor at python.org
> Message-ID: <1223272009.6409.8.camel at lieryan-laptop>
> Content-Type: text/plain
>
> On Mon, 2008-10-06 at 05:32 +0200, tutor-request at python.org wrote:
> >
> > Message: 8
> > Date: Sun, 5 Oct 2008 20:27:39 -0700
> > From: Anthony Smith <gods_bud666 at hotmail.com>
> > Subject: [Tutor] first call - newcomer
> > To: <tutor at python.org>
> > Message-ID: <BLU146-W21D0F815F794C49517F301CA390 at phx.gbl>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> >
> > This is my first post - I will be brief...
> >
> > One:  I have programmed before - but it has been DECADES...so just a
> > few simple queries:
> >
> > 1.  A brief (but complete) description regarding the use of script
> > editor (I will be using
>
> Your script editor can be any plain text-editing tools, Notepad could
> do.
>
> >      command prompt in Windows), as:
> >
> >          a.  details about loading and saving programs (not in that
> > order) and little
> >               specs about pathnames or other requirements (I will
> > probably store all
> >               my little goodies in one folder or space).
>
> Pathnames is free, you can name your program anything your OS allows for
> a file. A convention is to name the script ending with .py/.pyw
> extension (command-line script/GUI script), although python doesn't
> complain if it is not in those extension (in Windows, the extension is
> associated with the interpreter). Calling a program from command line is
> done like this:
>
> python filename.py
>
> >       That should get me going ... a book and manual by my side should
> > suffice for
> >        the rest - - - except for one thing:
>
> > 2.  I have been unable to locate the gizmo in the literature to get
> > ascii codes
> >     in python.  In the old days, it was a list of 256 (or so)
> > characters that
> >     represented all keyboard symbols (A equalled 36; B equalled 37; et
> > cetera).
> >    To assign a value, you used "Let A$ = ASC (36)" where A$ was a
> > variable
> >     and 36 was the ASCII value for 'A'.  I believe the reverse of this
> > process
> >     was PRINT VAL(A$) or something.  I want to play with a program
> > that will
> >    assign a number to a word (using a simple algorhythm that will give
> > a
> >     specific number to every word).  Other stuff is pretty easy to
> > find with
> >     the book and on-line literature.  I will need to get an ascii code
> > out of
> >      a string (whose content is not known to the programmer, as
> > raw_input).
> >     Then to assign, I will need the actual list with assigned numbers.
>
> a = ord('A')
> b = chr(36)
>
> -- read on the help file: Built-in Functions
>
> > You will be giving me probably the only boost I will need!  I will be
> > available later on,
> > if I want to take part in the ask/answer system here.
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 6 Oct 2008 09:31:04 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] IF statements
> To: tutor at python.org
> Message-ID: <gccicb$436$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>        reply-type=response
>
> "WM" <WFERGUSON1 at SOCAL.RR.COM> wrote
>
> > to IF.  The code below was not written by me.  It is a copy/paste
> > job from the tutor.  I do not have any idea what is going wrong.
>
> > >>> x = int(raw_input("Please enter an integer: "))
> > Please enter an integer: 42
> > >>> if x < 0:
> > ...      x = 0
> > ...      print 'Negative changed to zero'
> > ... elif x == 0:
> > ...      print 'Zero'
> > ... elif x == 1:
> > ...      print 'Single'
> > ... else:
> > ...      print 'More'
> > ...
> > More
> > 12
> > SyntaxError: invalid syntax
>
> It looks as if you maybe cut more than you intended?
> Also I'm not sure about the ... prompts. I don't have 2.6 yet
> so maybe its an enhancement to IDLE but notmally IDLE
> doesn't print ... prompts. Did you cut n paste them too?
> If so that would confuse IDLE.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 6 Oct 2008 09:38:14 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] first call - newcomer
> To: tutor at python.org
> Message-ID: <gccipp$5bk$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>        reply-type=original
>
>
> "Anthony Smith" <gods_bud666 at hotmail.com> wrote
>
> > This is my first post - I will be brief...
>
> Hi, welcome to tutor :-)
>
> > 1.  A brief (but complete) description regarding the use of script
> > editor (I will be using command prompt in Windows), as:
>
> Brief and Complete don;t normally go together!
> If you are using IDLE then Danny yoo's intro is a good place to start.
> The IDLE section of the Python web site has a more detailed run
> through oof the faciilities.
>
>         a.  details about loading and saving programs (not in that
> order) and little
>              specs about pathnames or other requirements (I will
> probably store all
>              my little goodies in one folder or space).
>
> As to paths:
>
> PATH should be set to the folder where the Python interpreters live
> PYTHONPATH should be set to include the folder where your code lives
>
> > 2.  I have been unable to locate the gizmo in the literature to get
> > ascii codes
> >     in python.
>
> chr(n) is the function you need
> ord(c) is the one in the opposite direction
>
> but...
>
> >    was PRINT VAL(A$) or something.
>
> Python will generally figure out what you want to print without
> explicit conversions, certainly fewer than you will be used to
> from the early BASIC versions.
>
> >     assign a number to a word (using a simple algorhythm that will
> > give a
> >     specific number to every word).  Other stuff is pretty easy to
> > find with
> >     the book and on-line literature.  I will need to get an ascii
> > code out of
> >     a string (whose content is not known to the programmer, as
> > raw_input).
> >     Then to assign, I will need the actual list with assigned
> > numbers.
>
> OK, You lost me here.
> Can you give an example of what the data would look like?
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 56, Issue 23
> *************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/1a90450b/attachment-0001.htm>

From adrian.greyling at gmail.com  Mon Oct  6 17:31:41 2008
From: adrian.greyling at gmail.com (Adrian Greyling)
Date: Mon, 6 Oct 2008 11:31:41 -0400
Subject: [Tutor] Delete file before function ends
Message-ID: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>

Greetings all,

Not sure if this is possible, but I'll ask anyway.  Below is a code snippet
that creates my "problem"...  What I'd like to do, is create a plain text
file, use the associated program to open said textfile, (using os.startfile)
and after the associated program has what it needs to open the file and then
of course, has the current focus, I'd like to delete the text file in the
background, so to speak.  (Please assume that the program doesn't lock
'mytextfile.xyz' when it opens it.)

What happens with the code snippet below, is that it doesn't really start
the second program until the function is finished.  I tried using
time.sleep() in between the os.startfile() and os.remove(), but it just
delays opening 'mytextfile.xyz' and actually deletes the file before my
second program can open it up.  Any way around this??

path = "c:\MyFolder\mytextfile.xyz"
#bunch of stuff here to create 'mytextfile.xyz"
os.startfile(path)
os.remove(path)


Thanks everyone,
Adrian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/3d4ee09d/attachment.htm>

From mail at timgolden.me.uk  Mon Oct  6 18:15:28 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Mon, 06 Oct 2008 17:15:28 +0100
Subject: [Tutor] Delete file before function ends
In-Reply-To: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
Message-ID: <48EA39A0.5080406@timgolden.me.uk>

Adrian Greyling wrote:
> Not sure if this is possible, but I'll ask anyway.  Below is a code snippet
> that creates my "problem"...  What I'd like to do, is create a plain text
> file, use the associated program to open said textfile, (using os.startfile)
> and after the associated program has what it needs to open the file and then
> of course, has the current focus, I'd like to delete the text file in the
> background, so to speak.  (Please assume that the program doesn't lock
> 'mytextfile.xyz' when it opens it.)
> 
> What happens with the code snippet below, is that it doesn't really start
> the second program until the function is finished.  I tried using
> time.sleep() in between the os.startfile() and os.remove(), but it just
> delays opening 'mytextfile.xyz' and actually deletes the file before my
> second program can open it up.  Any way around this??
> 
> path = "c:\MyFolder\mytextfile.xyz"
> #bunch of stuff here to create 'mytextfile.xyz"
> os.startfile(path)
> os.remove(path)


Strange. I would have expected the opposite effect: the
os.startfile runs (notepad, or whatever) but doesn't
return control until it's complete.

In any case, try the following snippet. The sleep is
needed because the app probably won't launch in time
to get there before the remove does.

<code>
import os
import subprocess
import time

FILENAME = os.path.abspath ("temp.txt")
f = open (FILENAME, "w")
f.write ("blah blah")
f.close ()

subprocess.Popen ([FILENAME], shell=True)
time.sleep (1.0)
os.remove (FILENAME)

</code>

TJG

From mail at timgolden.me.uk  Mon Oct  6 18:27:11 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Mon, 06 Oct 2008 17:27:11 +0100
Subject: [Tutor] Delete file before function ends
In-Reply-To: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
Message-ID: <48EA3C5F.6080001@timgolden.me.uk>

Adrian Greyling wrote:

> path = "c:\MyFolder\mytextfile.xyz"


BTW, I hope you're using raw strings in your
real code, or else you're going to come a
cropper one day when a filename begins with "t".

TJG

From alan.gauld at btinternet.com  Mon Oct  6 19:09:16 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 6 Oct 2008 18:09:16 +0100
Subject: [Tutor] IF Statements
References: <eec116310810060424m6a3701d7pbf3cbdd387c743b9@mail.gmail.com>
Message-ID: <gcdgnv$fuu$1@ger.gmane.org>


"Rajeev Nair" <rajeev1204 at gmail.com> wrote
> also i believe the first line can also be written as 'x = 
> input('enter
> .......') instead of using x=int(raw_input('......') . use raw_input 
> for
> string and just input for integer.

No, use input() only in very special circumstances or when
experimenting for personal use only.

Use int(raw_input()) for all production code. It is much safer.

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



From kent37 at tds.net  Mon Oct  6 19:17:05 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 13:17:05 -0400
Subject: [Tutor] Fwd:  IF statements
In-Reply-To: <48EA221D.1020100@swipp.de>
References: <48E97D49.9060903@SOCAL.RR.COM>
	<1c2a2c590810060346i1e6f8a8jc0fdba5e954c56b@mail.gmail.com>
	<48EA221D.1020100@swipp.de>
Message-ID: <1c2a2c590810061017x2888d6dekc6b63941c7561c3c@mail.gmail.com>

Forwarding to the list...

---------- Forwarded message ----------
From: Thomas Walch <walch at swipp.de>
Date: Mon, Oct 6, 2008 at 10:35 AM
Subject: Re: [Tutor] IF statements
To: Kent Johnson <kent37 at tds.net>


Entering the code in the interpreter I could not find an issue. No
error at all. Might be that you launched some things in the
interpreter by mistake?

Anyhow, I put the code in an editor and saved it as xxx.py. Again no
error while running the program.

Just try again. Might be different then. I suggest to download SPE:

http://developer.berlios.de/project/showfiles.php?group_id=4161

and try to run it as file too.

Have a nice time....

Thomas

Kent Johnson schrieb:
>
> On Sun, Oct 5, 2008 at 10:51 PM, WM <WFERGUSON1 at socal.rr.com> wrote:
>
>>
>> I used to do Basic and enjoyed it.  Someone said Python was a vastly better
>> language than Visual Basic, which I considered playing with.  So I sought to
>> give it a go but struck a sticking point very early.
>> I am now going through the Python tutorial.  All went well until I came to
>> IF.  The code below was not written by me.  It is a copy/paste job from the
>> tutor.  I do not have any idea what is going wrong.
>>
>> IDLE 2.6     >>>
>>
>>>>>
>>>>> x = int(raw_input("Please enter an integer: "))
>>>>>
>>
>> Please enter an integer: 42
>>
>>>>>
>>>>> if x < 0:
>>>>>
>>
>> ...      x = 0
>> ...      print 'Negative changed to zero'
>> ... elif x == 0:
>> ...      print 'Zero'
>> ... elif x == 1:
>> ...      print 'Single'
>> ... else:
>> ...      print 'More'
>> ...
>> More
>> 12
>> SyntaxError: invalid syntax
>>
>
> Did you paste the >>> and ... or were they printed by the interpreter?
> Examples often show the entire contents of a session in the
> interpreter, including the >>> and ... prompts. When you enter the
> example yourself you should not include them. Also "Please enter an
> integer: " is output from the program and "42" is user input to the
> program, you should not paste either of them.
>
> Where did the 12 come from? It looks like interpreter output but there
> is nothing preceding it that would print a 12.
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From kent37 at tds.net  Mon Oct  6 19:18:41 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 13:18:41 -0400
Subject: [Tutor] IF Statements
In-Reply-To: <eec116310810060424m6a3701d7pbf3cbdd387c743b9@mail.gmail.com>
References: <eec116310810060424m6a3701d7pbf3cbdd387c743b9@mail.gmail.com>
Message-ID: <1c2a2c590810061018v69bb4129k8075c23f8b2735c4@mail.gmail.com>

On Mon, Oct 6, 2008 at 7:24 AM, Rajeev Nair <rajeev1204 at gmail.com> wrote:
> also i believe the first line can also be written as 'x = input('enter
> .......') instead of using x=int(raw_input('......') . use raw_input for
> string and just input for integer.

Yes, although that is not really recommended, this has been discussed
very recently.

Also, please don't include the entire digest in your reply!

Kent

From alan.gauld at btinternet.com  Mon Oct  6 19:31:54 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 6 Oct 2008 18:31:54 +0100
Subject: [Tutor] Delete file before function ends
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
Message-ID: <gcdi2d$l85$1@ger.gmane.org>


"Adrian Greyling" <adrian.greyling at gmail.com> wrote

> that creates my "problem"...  What I'd like to do, is create a plain 
> text
> file, use the associated program to open said textfile, (using 
> os.startfile)
> and after the associated program has what it needs to open the file 
> and then
> of course, has the current focus, I'd like to delete the text file

Thats potentially going to cause the associated program to crash
but assuming you know what you are doing there...

> What happens with the code snippet below, is that it doesn't start
> the second program until the function is finished.

Correct, that's what you asked it to do :-)

> time.sleep() in between the os.startfile() and os.remove(), but it 
> just
> delays opening 'mytextfile.xyz' and actually deletes the file before 
> my
> second program can open it up.

Really? That shouldn't happen!

> path = "c:\MyFolder\mytextfile.xyz"

You probably want to either use forward slashes or put
an r in front of the quotes, otherwise Python will treat
the \ as an escape character...

> #bunch of stuff here to create 'mytextfile.xyz"
> os.startfile(path)
> os.remove(path)

If you want the remove to run in parallel with the startfile
you probably need to use threads to start the application
in one thread and then pause and then delete the file in
the other thread.

Alan 



From adrian.greyling at gmail.com  Mon Oct  6 20:15:06 2008
From: adrian.greyling at gmail.com (Adrian Greyling)
Date: Mon, 6 Oct 2008 14:15:06 -0400
Subject: [Tutor] Delete file before function ends
In-Reply-To: <gcdi2d$l85$1@ger.gmane.org>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
	<gcdi2d$l85$1@ger.gmane.org>
Message-ID: <866c750d0810061115p196ec83cr2961ce6d42c0a2a9@mail.gmail.com>

Thanks for the input folks. Sadly, Tim's suggestion yields the same results
as I was getting previously.  My second program very graciously tells me
that the file I'm trying to open doesn't exist.  Like the code snippet I
posted, the timer.sleep(x) line just waits the 'x' seconds until opening
'mytextfile.xyz", instead of opening it, and then waiting 'x' seconds to
delete the file.
Sorry about naming the path to my file so "poorly"!!  I'm a little more
careful in my programs!  I'm a newbie and I was more concerned about an
understandable question!

As a newbie, Alan, I was kinda scared you'd say that "threads" were the
answer here!  (It sounds like someone is going to get sucked into a worm
hole or something...)  Looks like the next class in my Python education is
going to be "Threads 101"...

Thanks for all the input, I might even be learning something!

Warmest regards,
Adrian




On Mon, Oct 6, 2008 at 1:31 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "Adrian Greyling" <adrian.greyling at gmail.com> wrote
>
>  that creates my "problem"...  What I'd like to do, is create a plain text
>> file, use the associated program to open said textfile, (using
>> os.startfile)
>> and after the associated program has what it needs to open the file and
>> then
>> of course, has the current focus, I'd like to delete the text file
>>
>
> Thats potentially going to cause the associated program to crash
> but assuming you know what you are doing there...
>
>  What happens with the code snippet below, is that it doesn't start
>> the second program until the function is finished.
>>
>
> Correct, that's what you asked it to do :-)
>
>  time.sleep() in between the os.startfile() and os.remove(), but it just
>> delays opening 'mytextfile.xyz' and actually deletes the file before my
>> second program can open it up.
>>
>
> Really? That shouldn't happen!
>
>  path = "c:\MyFolder\mytextfile.xyz"
>>
>
> You probably want to either use forward slashes or put
> an r in front of the quotes, otherwise Python will treat
> the \ as an escape character...
>
>  #bunch of stuff here to create 'mytextfile.xyz"
>> os.startfile(path)
>> os.remove(path)
>>
>
> If you want the remove to run in parallel with the startfile
> you probably need to use threads to start the application
> in one thread and then pause and then delete the file in
> the other thread.
>
> Alan
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/900eb83d/attachment-0001.htm>

From steve at alchemy.com  Mon Oct  6 20:20:29 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Mon, 6 Oct 2008 11:20:29 -0700
Subject: [Tutor] Delete file before function ends
In-Reply-To: <866c750d0810061115p196ec83cr2961ce6d42c0a2a9@mail.gmail.com>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
	<gcdi2d$l85$1@ger.gmane.org>
	<866c750d0810061115p196ec83cr2961ce6d42c0a2a9@mail.gmail.com>
Message-ID: <20081006182029.GA28374@dragon.alchemy.com>

On Mon, Oct 06, 2008 at 02:15:06PM -0400, Adrian Greyling wrote:
> As a newbie, Alan, I was kinda scared you'd say that "threads" were the
> answer here!  (It sounds like someone is going to get sucked into a worm
> hole or something...)  Looks like the next class in my Python education is
> going to be "Threads 101"...

Threads are one approach, but if you aren't ready to jump into them,
that's not the only way to solve your problem.  However, please understand
that your application is trying to do something that's a bit more advanced
than the "newbie" level.  Any time you need to synchronize the operation
of multiple programs, there are complications and platform dependencies
involved that may not be as simple as you first think.

One natural, but naive, approach is to simply drop in a delay loop 
or call to time.sleep() to have the "parent" program wait "long enough"
for the "child" program to have done what it needs to do.  The problem
is you are only guessing how long is long enough, and will probably
be wrong enough of the time to be a problem.  

You need to work out some way to have the parent program wait for
a definite signal that the child is finished before moving forward.
That could be to use a subprocess invocation method which guarantees
the child will complete before it returns.  Or it could be that you
watch for an artifact created by the child, or wait for the child
process (or thread) to exit, or any of several other things.

Browse through the subprocess module for some hints of things you 
can try.

From srilyk at gmail.com  Mon Oct  6 20:30:40 2008
From: srilyk at gmail.com (W W)
Date: Mon, 6 Oct 2008 13:30:40 -0500
Subject: [Tutor] Delete file before function ends
In-Reply-To: <20081006182029.GA28374@dragon.alchemy.com>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
	<gcdi2d$l85$1@ger.gmane.org>
	<866c750d0810061115p196ec83cr2961ce6d42c0a2a9@mail.gmail.com>
	<20081006182029.GA28374@dragon.alchemy.com>
Message-ID: <333efb450810061130l2a182ed2w2300bb9b1b2eca3f@mail.gmail.com>

What OS are you using, Adrian? On WinXP, this worked fine:

import os

def files():
    os.startfile('myfile.txt')
    os.remove('myfile.txt')

-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/621c6624/attachment.htm>

From adrian.greyling at gmail.com  Mon Oct  6 20:37:56 2008
From: adrian.greyling at gmail.com (Adrian Greyling)
Date: Mon, 6 Oct 2008 14:37:56 -0400
Subject: [Tutor] Delete file before function ends
In-Reply-To: <333efb450810061130l2a182ed2w2300bb9b1b2eca3f@mail.gmail.com>
References: <866c750d0810060831n4d262a62sfa861c3ff34aa0df@mail.gmail.com>
	<gcdi2d$l85$1@ger.gmane.org>
	<866c750d0810061115p196ec83cr2961ce6d42c0a2a9@mail.gmail.com>
	<20081006182029.GA28374@dragon.alchemy.com>
	<333efb450810061130l2a182ed2w2300bb9b1b2eca3f@mail.gmail.com>
Message-ID: <866c750d0810061137t5991f9d0i41a2f81404b050e1@mail.gmail.com>

I'll take a peek at the subprocess docs Steve, and see if I can learn
something there...  Thanks for the suggestion!

I'm using WinXP as well Wayne..  Not too sure why yours works, and mine
doesn't..  I'll revisit what I'm doing and also check into Steve's
suggestion.
Adrian





On Mon, Oct 6, 2008 at 2:30 PM, W W <srilyk at gmail.com> wrote:

> What OS are you using, Adrian? On WinXP, this worked fine:
>
> import os
>
> def files():
>     os.startfile('myfile.txt')
>     os.remove('myfile.txt')
>
> -Wayne
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/6eb13f23/attachment.htm>

From xboxmuncher at gmail.com  Mon Oct  6 21:32:36 2008
From: xboxmuncher at gmail.com (xbmuncher)
Date: Mon, 6 Oct 2008 15:32:36 -0400
Subject: [Tutor] Read a random record in dictionary object from csv module
	reader?
Message-ID: <df531c470810061232h13170937me64ff17d3a652493@mail.gmail.com>

import csv
reader = csv.DictReader(open("test_csv.csv", "r"))

reader is not an actual dictionary from my understanding.. so I don't know
how to access properties like the 'total items' in the dictionary
I want to be able to extract a random dictionary entry from the csv file,
how can I do this by using the csv reader module? If I can't, then show me a
better way to do it then..


-thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/8505ba04/attachment.htm>

From kent37 at tds.net  Mon Oct  6 21:55:32 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 15:55:32 -0400
Subject: [Tutor] Read a random record in dictionary object from csv
	module reader?
In-Reply-To: <df531c470810061232h13170937me64ff17d3a652493@mail.gmail.com>
References: <df531c470810061232h13170937me64ff17d3a652493@mail.gmail.com>
Message-ID: <1c2a2c590810061255v1309b455tf82db8143fa72e98@mail.gmail.com>

On Mon, Oct 6, 2008 at 3:32 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> import csv
> reader = csv.DictReader(open("test_csv.csv", "r"))

You should open the file with mode 'rb'

> reader is not an actual dictionary from my understanding.. so I don't know
> how to access properties like the 'total items' in the dictionary
> I want to be able to extract a random dictionary entry from the csv file,
> how can I do this by using the csv reader module? If I can't, then show me a
> better way to do it then..
>

reader is not a dictionary at all; it is a factory for dictionaries.
It produces a new dict for each line in the input file. Given your
code above, and assuming that the first line of the CSV file contains
field names, you can say
for d in reader:
  # d is a dict mapping field names to value for one line in the input file.

If you want all the items in a list, you could say
all_items = list(reader)

Then len(all_items) is the number of items in the dictionary and
random.choice(all_items) would give a randomly selected item dict.

Kent

From Adam.R.Deitemeyer at boeing.com  Mon Oct  6 23:37:11 2008
From: Adam.R.Deitemeyer at boeing.com (Deitemeyer, Adam R)
Date: Mon, 6 Oct 2008 14:37:11 -0700
Subject: [Tutor] Help Python String Search
Message-ID: <4A8E5237A9C4D74DB6E67CA21C6D47AF03234713@XCH-NW-9V1.nw.nos.boeing.com>

Hello,
 
I'm a beginner Python user and I have simple python issue I can't seem
to solve.  I want to do a truth test on a string to see if a another
string is contained within it.  I found that typically the re module has
the methods to accomplish this.  However, every string I'm searching
begins with a metacharacter.  For example: if the string '*I need *help'
contains the word 'help' then true, else false..  Any advice you can
provide would be great. 
 
Thanks,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/f771768b/attachment.htm>

From john at fouhy.net  Tue Oct  7 00:36:54 2008
From: john at fouhy.net (John Fouhy)
Date: Tue, 7 Oct 2008 11:36:54 +1300
Subject: [Tutor] Help Python String Search
In-Reply-To: <4A8E5237A9C4D74DB6E67CA21C6D47AF03234713@XCH-NW-9V1.nw.nos.boeing.com>
References: <4A8E5237A9C4D74DB6E67CA21C6D47AF03234713@XCH-NW-9V1.nw.nos.boeing.com>
Message-ID: <5e58f2e40810061536qd0fe011t22f32222844658e1@mail.gmail.com>

2008/10/7 Deitemeyer, Adam R <Adam.R.Deitemeyer at boeing.com>:
> I'm a beginner Python user and I have simple python issue I can't seem to
> solve.  I want to do a truth test on a string to see if a another string is
> contained within it.  I found that typically the re module has the methods
> to accomplish this.  However, every string I'm searching begins with a
> metacharacter.  For example: if the string '*I need *help' contains the word
> 'help' then true, else false..  Any advice you can provide would be great.

The presence of metacharacters shouldn't be a problem with regular
expressions; you can just "escape" them by putting a backslash (\)
before the character.

However ... your problem is sufficiently simple that you don't need
regular expressions.  The 'in' operator will do it for you:

>>> strings = ['I need help', 'This string does not contain the word', 'I no longer need help']
>>> for s in strings:
...   if 'help' in s:
...     print s
...
I need help
I no longer need help
>>>

If you are worried about case sensitivity, you can use the string
method .lower():

>>> 'help' in 'One HeLP twO'
False
>>> 'help' in 'One HeLP twO'.lower()
True
>>>

HTH!

-- 
John.

From cappy2112 at gmail.com  Tue Oct  7 00:58:15 2008
From: cappy2112 at gmail.com (Tony Cappellini)
Date: Mon, 6 Oct 2008 15:58:15 -0700
Subject: [Tutor] Using the curses module (or a better solution)
In-Reply-To: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
References: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
Message-ID: <8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>

I'm maintaining a framework of tests which are run on a diskless Linux
client, in character mode (no graphical desktop).

The tests often print out a lot of info, which scrolls off the screen.

I'd like to add a 1-2 line no-scroll-area at the top of the screen, so as to
print a message which indicates the progress of the current test.

I am thinking about using the Python curses module for this, unless someone
would suggest an alternative solution, although I'm not sure if the curses
module
has this non-scroll area capability.

http://www.amk.ca/python/howto/curses/

Ideally I'd like something which works on Windows & Linux, but since the
test environment on Linux is non-graphical, packages like WxPython can't be
used.


Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/0e5c305a/attachment-0001.htm>

From WFERGUSON1 at SOCAL.RR.COM  Tue Oct  7 03:48:05 2008
From: WFERGUSON1 at SOCAL.RR.COM (WM)
Date: Mon, 06 Oct 2008 18:48:05 -0700
Subject: [Tutor] IF statements-1
Message-ID: <48EABFD5.7090508@SOCAL.RR.COM>

TO THIS ORIGINAL POST I GOT SIX REPLIES.

WM wrote:
 > > I used to do Basic and enjoyed it.  Someone said Python was a vastly
 > > better language than Visual Basic, which I considered playing with.  So
 > > I sought to give it a go but struck a sticking point very early.
 > > I am now going through the Python tutorial.  All went well until I came
 > > to IF.  The code below was not written by me.  It is a copy/paste job
 > > from the tutor.  I do not have any idea what is going wrong.
 > >
 > > IDLE 2.6     >>>
 >>>> >>>>
 >>>> >>>> x = int(raw_input("Please enter an integer: "))
 > > Please enter an integer: 42
 >>>> >>>> if x < 0:
 > > ...      x = 0
 > > ...      print 'Negative changed to zero'
 > > ... elif x == 0:
 > > ...      print 'Zero'
 > > ... elif x == 1:
 > > ...      print 'Single'
 > > ... else:
 > > ...      print 'More'
 > > ...
 > > More
 > > 12
 > > SyntaxError: invalid syntax
 >>>> >>>>

IS THIS THE WAY TO ANSWER?  OR SHOULD I DO INDIVIDUAL REPLIES?

JOHNSON 1
The copy above is exactly from the book, via COPY & PASTE, from IDLE26 
thru More.
I keyed in the 12 to generate the error message.

JOHNSON 2
All that was running was IDLE from the desktop and the tutor from the 
Python.Org site.
I will not do the down-load right now as I want the tutor to work with 
the program with no tinkering.

JOHNSON 3
I did not understand Nair's reply, so I didn't follow thru there.
What is "the entire digest" and how do I not include it?

LANE
I keyed in "12" & "Enter".  The rest is copy/paste.
I will key the text into Notepad then run it, as you suggest.

GAULD
Not so.  You can check on the tutor, the code stops at 'More'.
It's funny about the dots, they were in the tutor but not in IDLE, 
although the indents were the same.  Then, in the e-mil, there they 
were.  IDLE hides dots?  What do I know?

NAIR
Your post to me starts, "also I believe..."  It looks like the front end 
got truncated.

From kent37 at tds.net  Tue Oct  7 03:59:19 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 21:59:19 -0400
Subject: [Tutor] Help Python String Search
In-Reply-To: <4A8E5237A9C4D74DB6E67CA21C6D47AF03234713@XCH-NW-9V1.nw.nos.boeing.com>
References: <4A8E5237A9C4D74DB6E67CA21C6D47AF03234713@XCH-NW-9V1.nw.nos.boeing.com>
Message-ID: <1c2a2c590810061859y23dde034uc64c8d158d3ffe13@mail.gmail.com>

On Mon, Oct 6, 2008 at 5:37 PM, Deitemeyer, Adam R
<Adam.R.Deitemeyer at boeing.com> wrote:
> Hello,
>
> I'm a beginner Python user and I have simple python issue I can't seem to
> solve.  I want to do a truth test on a string to see if a another string is
> contained within it.  I found that typically the re module has the methods
> to accomplish this.  However, every string I'm searching begins with a
> metacharacter.  For example: if the string '*I need *help' contains the word
> 'help' then true, else false..

This would only be an issue with regexes if the pattern you are
searching for contained metacharacters. Then you would escape them.
But John's approach is simpler in this case.

Kent

From kent37 at tds.net  Tue Oct  7 04:02:55 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 22:02:55 -0400
Subject: [Tutor] Using the curses module (or a better solution)
In-Reply-To: <8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>
References: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
	<8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>
Message-ID: <1c2a2c590810061902o6e9a1862ta48e1862e11c500@mail.gmail.com>

On Mon, Oct 6, 2008 at 6:58 PM, Tony Cappellini <cappy2112 at gmail.com> wrote:
>
>
> I'm maintaining a framework of tests which are run on a diskless Linux
> client, in character mode (no graphical desktop).
>
> The tests often print out a lot of info, which scrolls off the screen.
>
> I'd like to add a 1-2 line no-scroll-area at the top of the screen, so as to
> print a message which indicates the progress of the current test.
>
> I am thinking about using the Python curses module for this, unless someone
> would suggest an alternative solution,

See the recent discussion of urwid for discussion of a similar problem.
http://thread.gmane.org/gmane.comp.python.tutor/50500/

If the tests are based on unittest or assert, you might be interested
in nose; it suppresses output for tests that pass.
http://code.google.com/p/python-nose/wiki/NoseFeatures

Kent

From WFERGUSON1 at SOCAL.RR.COM  Tue Oct  7 04:06:23 2008
From: WFERGUSON1 at SOCAL.RR.COM (WM)
Date: Mon, 06 Oct 2008 19:06:23 -0700
Subject: [Tutor] IF statment 2
Message-ID: <48EAC41F.6010503@SOCAL.RR.COM>

Hey, guys, forgive me; I can't help being a fool.  Just now I READ the 
program and it worked perfectly!  42 is more than 1 so it printed 
"More".  My error was that I imagined there was a loop where no loop 
could be.  Oh, me; oh, my.

From kent37 at tds.net  Tue Oct  7 04:11:27 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 6 Oct 2008 22:11:27 -0400
Subject: [Tutor] IF statements-1
In-Reply-To: <48EABFD5.7090508@SOCAL.RR.COM>
References: <48EABFD5.7090508@SOCAL.RR.COM>
Message-ID: <1c2a2c590810061911o51660931hb0a84a084f88582c@mail.gmail.com>

On Mon, Oct 6, 2008 at 9:48 PM, WM <WFERGUSON1 at socal.rr.com> wrote:
> TO THIS ORIGINAL POST I GOT SIX REPLIES.

> IS THIS THE WAY TO ANSWER?  OR SHOULD I DO INDIVIDUAL REPLIES?

Either way is OK. It helps to quote a bit of the post to which you are
replying, for context. And please don't use all caps, it is
interpreted as shouting. And you seem to be a bit off in your
attributions...

> JOHNSON 1
> The copy above is exactly from the book, via COPY & PASTE, from IDLE26 thru
> More.
> I keyed in the 12 to generate the error message.

You can't just paste the examples verbatim from the tutorial. The
examples are showing you both the text that you type and the output of
the interpreter. In particular the >>> and ... are output and should
not be typed or pasted in.


> JOHNSON 3
> I did not understand Nair's reply, so I didn't follow thru there.
> What is "the entire digest" and how do I not include it?

That was a note to Rajeev, who included a lot of extraneous text in his reply.

Did you start at the beginning of the tutorial or are you starting
with section 4?

Kent

From cappy2112 at gmail.com  Tue Oct  7 04:20:56 2008
From: cappy2112 at gmail.com (Tony Cappellini)
Date: Mon, 6 Oct 2008 19:20:56 -0700
Subject: [Tutor] Using the curses module (or a better solution)
In-Reply-To: <1c2a2c590810061902o6e9a1862ta48e1862e11c500@mail.gmail.com>
References: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
	<8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>
	<1c2a2c590810061902o6e9a1862ta48e1862e11c500@mail.gmail.com>
Message-ID: <8249c4ac0810061920p5ae57149k938d7c08bc3bae5e@mail.gmail.com>

> See the recent discussion of urwid for discussion of a similar problem.
> http://thread.gmane.org/gmane.comp.python.tutor/50500/
This looks interesting.

Thanks!

From pierre.dagenais at ncf.ca  Tue Oct  7 10:23:50 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Tue, 07 Oct 2008 04:23:50 -0400
Subject: [Tutor]  first call - newcomer
Message-ID: <48EB1C96.9020805@ncf.ca>

Anthony Smith wrote:
> This is my first post - I will be brief...
>  
> One:  I have programmed before - but it has been DECADES...so just a 
> few simple queries:
>  
> 1.  A brief (but complete) description regarding the use of script 
> editor (I will be using
>      command prompt in Windows), as:
>  
>          a.  details about loading and saving programs (not in that 
> order) and little
>               specs about pathnames or other requirements (I will 
> probably store all
>               my little goodies in one folder or space).
>  
>   
Hi,
You save programs by writing them in a file with a .py extension. Ex.: 
myProgram.py
Then there are different ways of loading a program, from the dos command 
line you can do: C:\myProgram.py, that one I couldn't find in the 
litterature, I had to ask, thank you Alan.
>       That should get me going ... a book and manual by my side should 
> suffice for
>        the rest - - - except for one thing:
>  
> 2.  I have been unable to locate the gizmo in the literature to get 
> ascii codes
>     in python.  In the old days, it was a list of 256 (or so) 
> characters that     represented all keyboard symbols (A equalled 36; B 
> equalled 37; et cetera).
>    To assign a value, you used "Let A$ = ASC (36)" where A$ was a 
> variable
>     and 36 was the ASCII value for 'A'.  I believe the reverse of this 
> process
>     was PRINT VAL(A$) or something.  I want to play with a program 
> that will
>    assign a number to a word (using a simple algorhythm that will give a
>     specific number to every word).  Other stuff is pretty easy to 
> find with
>     the book and on-line literature.  I will need to get an ascii code 
> out of
>      a string (whose content is not known to the programmer, as 
> raw_input).
>     Then to assign, I will need the actual list with assigned numbers.
>  
> You will be giving me probably the only boost I will need!  I will be 
> available later on,
> if I want to take part in the ask/answer system here.
>  
>  
> Thanks a lot,
>  
> Anthony
>  
> 8:27 pm PST October 4th, 2008
>  
>  
> _________________________________________________________________
> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008 
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 
> 270.7.6/1710 - Release Date: 06/10/2008 9:23 AM
>
>   



From alan.gauld at btinternet.com  Tue Oct  7 10:27:30 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 7 Oct 2008 09:27:30 +0100
Subject: [Tutor] Using the curses module (or a better solution)
References: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
	<8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>
Message-ID: <gcf6hm$88j$1@ger.gmane.org>


"Tony Cappellini" <cappy2112 at gmail.com> wrote

> I'd like to add a 1-2 line no-scroll-area at the top of the screen, 
> so as to
> print a message which indicates the progress of the current test.
>
> ....I'm not sure if the curses module has this non-scroll area 
> capability.

Yes, curses works by defining viewport windows on the character 
screen. Thus you can define two windows, one for the scrolling text 
(and add a scrollbar to bring it back if needed) and one for the fixed 
display.

There are some wrappers around curses to make the learning
curve a little bit less steep. Although, personally I don't think
raw curses is all that hard... :-)

Alan G. 



From srilyk at gmail.com  Tue Oct  7 12:12:50 2008
From: srilyk at gmail.com (W W)
Date: Tue, 7 Oct 2008 05:12:50 -0500
Subject: [Tutor] Using the curses module (or a better solution)
In-Reply-To: <gcf6hm$88j$1@ger.gmane.org>
References: <8249c4ac0810061544q3c359860ifcc36f638792f9@mail.gmail.com>
	<8249c4ac0810061558x39fa51a0uad7ce3ab3d3f517e@mail.gmail.com>
	<gcf6hm$88j$1@ger.gmane.org>
Message-ID: <333efb450810070312h58880da3u535ebe2432e399e1@mail.gmail.com>

On Tue, Oct 7, 2008 at 3:27 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> There are some wrappers around curses to make the learning
> curve a little bit less steep. Although, personally I don't think
> raw curses is all that hard... :-)
>

Especially not for such a simple program. Less than 100 lines to do this
sort of thing, I'm sure.
-Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/b500b32f/attachment.htm>

From kent37 at tds.net  Tue Oct  7 12:41:06 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 7 Oct 2008 06:41:06 -0400
Subject: [Tutor] IF statment 2
In-Reply-To: <48EAC41F.6010503@SOCAL.RR.COM>
References: <48EAC41F.6010503@SOCAL.RR.COM>
Message-ID: <1c2a2c590810070341g30b8fd07r12b99d2ed9e74a7a@mail.gmail.com>

On Mon, Oct 6, 2008 at 10:06 PM, WM <WFERGUSON1 at socal.rr.com> wrote:
> Hey, guys, forgive me; I can't help being a fool.  Just now I READ the
> program and it worked perfectly!  42 is more than 1 so it printed "More".
>  My error was that I imagined there was a loop where no loop could be.  Oh,
> me; oh, my.

Glad you got it working. One more tip about the list - it is very
helpful if you respond to a thread by replying (to all) to one of the
messages in the thread. That way people using threaded readers see the
entire thread grouped together.

Kent

From d.conca at gmail.com  Tue Oct  7 16:08:32 2008
From: d.conca at gmail.com (Daniele)
Date: Tue, 7 Oct 2008 16:08:32 +0200
Subject: [Tutor] Default parameter in class method
Message-ID: <537341c70810070708kac64568r2e0fde9bf2aceea6@mail.gmail.com>

Hi all,
I know very little about OOP in Python, I'm working on it but, for the
time being, here's my problem:
I want to create a method of a class with a default value. The problem
is that this default value should be an instance field of that same
class. For example:

class Test():
  def __init__(self):
    self.field='Default'

  def myMethod(self, parameter=self.field):
    pass

I'm getting an error like "name 'self' is not defined"; it seems I
cannot access self.field in the method definition. Is there a
work-around (or maybe just the proper way to do it)?

Thank you very much,
Daniele

From kent37 at tds.net  Tue Oct  7 16:18:00 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 7 Oct 2008 10:18:00 -0400
Subject: [Tutor] Default parameter in class method
In-Reply-To: <537341c70810070708kac64568r2e0fde9bf2aceea6@mail.gmail.com>
References: <537341c70810070708kac64568r2e0fde9bf2aceea6@mail.gmail.com>
Message-ID: <1c2a2c590810070718g1b4e4067t41c3ec174e945166@mail.gmail.com>

On Tue, Oct 7, 2008 at 10:08 AM, Daniele <d.conca at gmail.com> wrote:
> Hi all,
> I know very little about OOP in Python, I'm working on it but, for the
> time being, here's my problem:
> I want to create a method of a class with a default value. The problem
> is that this default value should be an instance field of that same
> class. For example:
>
> class Test():
>  def __init__(self):
>    self.field='Default'
>
>  def myMethod(self, parameter=self.field):
>    pass
>
> I'm getting an error like "name 'self' is not defined"; it seems I
> cannot access self.field in the method definition. Is there a
> work-around (or maybe just the proper way to do it)?

def myMethod(self, parameter=None):
  if parameter is None:
    parameter = self.field

If None is actually a valid value for parameter, you can create a
unique marker object:
outside the class:
_marker = object()

then:
def myMethod(self, parameter=_marker):
  if parameter==_marker:
    parameter = self.field

Kent

From alan.gauld at btinternet.com  Tue Oct  7 17:29:14 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 7 Oct 2008 16:29:14 +0100
Subject: [Tutor] Default parameter in class method
References: <537341c70810070708kac64568r2e0fde9bf2aceea6@mail.gmail.com>
Message-ID: <gcfv8d$1q6$1@ger.gmane.org>

"Daniele" <d.conca at gmail.com> wrote

> I want to create a method of a class with a default value. The 
> problem
> is that this default value should be an instance field of that same
> class. For example:
>
> class Test():
>  def __init__(self):
>    self.field='Default'
>
>  def myMethod(self, parameter=self.field):
>    pass


This has little to do with OOP per se.
You cannot make a default value of a normal function refer to a
dynamic variable. It has to be a constant value (or the current
value of a variable at the time the function is defined).

Consider:

>>> myvar = None
>>> def f1():
...   global myvar
...   myvar = 42
...
>>> def f2(n = myvar):
...   print n
...
>>> myvar
None
>>> f2()
None
>>> f1()   # set myvar to 42
>>> myvar
42
>>> f2()   # still using the original myvar value
None
>>> myvar
42
>>>

So the default value is bound to the value of myvar
at the time the function was defined. Even if myvar
changes the default value will not.

So in the OOP case binding to a field value won't
work because the field doesn't get defined until
an object is instantiated but the class definition
(including the method) will be executed before
any instances are created.

Kent has shown how to use a default binding to
None to do what you want. I just wanted to point
out that the same issues arise using functions.

HTH,

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



From steve at alchemy.com  Tue Oct  7 17:53:41 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Tue, 7 Oct 2008 08:53:41 -0700
Subject: [Tutor] first call - newcomer
In-Reply-To: <48EB1C96.9020805@ncf.ca>
References: <48EB1C96.9020805@ncf.ca>
Message-ID: <20081007155341.GA6162@dragon.alchemy.com>

On Tue, Oct 07, 2008 at 04:23:50AM -0400, Pierre Dagenais wrote:
> Anthony Smith wrote:
> >1.  A brief (but complete) description regarding the use of script 
> >editor (I will be using

Place the files wherever you like, just use a .py extension on
the filenames.  Use any text editor you like which saves plain
ASCII files (notepad, IDLE, vi, emacs, etc).  IDLE comes with
Python and may be useful for new programmers especially.

> >2.  I have been unable to locate the gizmo in the literature to get 
> >ascii codes
> >    in python.  In the old days, it was a list of 256 (or so) 
> >characters that     represented all keyboard symbols (A equalled 36; B 
> >equalled 37; et cetera).

36?  Out of curiosity, what system were you using?  It can't have
been ASCII or EBCDIC.

> >   To assign a value, you used "Let A$ = ASC (36)" where A$ was a 
> >variable
> >    and 36 was the ASCII value for 'A'.  I believe the reverse of this 
> >process
> >    was PRINT VAL(A$) or something.  I want to play with a program 
> >that will

In Python:
	a = chr(36)
	print ord(a)

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From roadierich at googlemail.com  Tue Oct  7 19:15:56 2008
From: roadierich at googlemail.com (Richard Lovely)
Date: Tue, 7 Oct 2008 18:15:56 +0100
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <48E90EFF.9070101@embarqmail.com>
References: <48E8FEC7.5090000@embarqmail.com>
	<1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>
	<48E90EFF.9070101@embarqmail.com>
Message-ID: <f0b4202b0810071015t4584943cr2649bd634f97ff96@mail.gmail.com>

In a slightly related matter, Is is possible to use all() with a list
comprehension to check if a word contains all of the letters of
another?

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com

From vinayvinay at gmail.com  Tue Oct  7 19:22:35 2008
From: vinayvinay at gmail.com (Vinay Reddy)
Date: Tue, 7 Oct 2008 10:22:35 -0700
Subject: [Tutor] pexpect/pxssh
Message-ID: <537f59d10810071022w45813f4dh141bc7be6e6f5ab1@mail.gmail.com>

Hi,
I wish to automate some of my network related tasks, which involves
sshing into a remote box and executing some commands. I looked at
pxssh for that purpose but it seems to throw an exception when I have
ssh keys setup so that logins can happen without explicit password
authentication.

Is there a way to use pxssh (or some other tool) to just ssh in if
keys are setup correctly, else fallback to password based
authentication.

Thanks,
Vinay

From kent37 at tds.net  Tue Oct  7 19:54:13 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 7 Oct 2008 13:54:13 -0400
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <f0b4202b0810071015t4584943cr2649bd634f97ff96@mail.gmail.com>
References: <48E8FEC7.5090000@embarqmail.com>
	<1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>
	<48E90EFF.9070101@embarqmail.com>
	<f0b4202b0810071015t4584943cr2649bd634f97ff96@mail.gmail.com>
Message-ID: <1c2a2c590810071054r775a2648u54543b12c264b01b@mail.gmail.com>

On Tue, Oct 7, 2008 at 1:15 PM, Richard Lovely
<roadierich at googlemail.com> wrote:
> In a slightly related matter, Is is possible to use all() with a list
> comprehension to check if a word contains all of the letters of
> another?

Sure.

In [1]: all(letter in 'abcde' for letter in 'cde')
Out[1]: True

In [2]: all(letter in 'abcde' for letter in 'cdef')
Out[2]: False

Kent

From d.conca at gmail.com  Tue Oct  7 20:23:40 2008
From: d.conca at gmail.com (Daniele)
Date: Tue, 7 Oct 2008 20:23:40 +0200
Subject: [Tutor] Default parameter in class method
In-Reply-To: <1c2a2c590810070718g1b4e4067t41c3ec174e945166@mail.gmail.com>
References: <537341c70810070708kac64568r2e0fde9bf2aceea6@mail.gmail.com>
	<1c2a2c590810070718g1b4e4067t41c3ec174e945166@mail.gmail.com>
Message-ID: <537341c70810071123w250462aj53a2ecd3e8a1a3a4@mail.gmail.com>

2008/10/7 Kent Johnson <kent37 at tds.net>:
> On Tue, Oct 7, 2008 at 10:08 AM, Daniele <d.conca at gmail.com> wrote:
> def myMethod(self, parameter=_marker):
>  if parameter==_marker:
>    parameter = self.field

Thanks Kent and Alan, I've understood the point and I think I'll use
Kent's solution :)

From jeremiah.jester at panasonic.aero  Tue Oct  7 20:46:39 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Tue, 07 Oct 2008 11:46:39 -0700
Subject: [Tutor] cx_oracle module problems
Message-ID: <1223405199.21522.4.camel@jeremiah-laptop>

I've downloaded the cx_oracle source module for python, howerver every
time i try to build it, it keeps on failing. I've been unable to find a
port for Ubuntu. Is there one? Anyone know how to get this properly
installed?

# sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 36, in <module>
    oracleHome = os.environ["ORACLE_HOME"]
  File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
    raise KeyError(key)
KeyError: 'ORACLE_HOME'


Link:
http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.2.tar.gz?download	

Thanks,
JJ



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From xboxmuncher at gmail.com  Tue Oct  7 21:06:34 2008
From: xboxmuncher at gmail.com (xbmuncher)
Date: Tue, 7 Oct 2008 15:06:34 -0400
Subject: [Tutor] Monitoring HTTP connections?
In-Reply-To: <333efb450809281800t7b9b7658gf821b273d8736dae@mail.gmail.com>
References: <df531c470809272020w712d12edo270e67ddf56a841f@mail.gmail.com>
	<1c2a2c590809280439r19ade56avbd1f60fda494deb8@mail.gmail.com>
	<df531c470809281733h1af33ac1gb213c45d03ec6ef3@mail.gmail.com>
	<333efb450809281800t7b9b7658gf821b273d8736dae@mail.gmail.com>
Message-ID: <df531c470810071206x20fc217p362b3464e93de626@mail.gmail.com>

on proxy programs:
i want to sniff the http requests that are being made internally from a
program I have no control over, so a proxy server won't work, because I
can't make the program access the internet through a proxy, its not a
browser that is making the requests

Perhaps, you can tell me the "things" I need to accomplish with code for me
to be able to sniff the HTTP requests/responses coming from my wireless
card. I can explain what I want to do in primitive terms:
wireless card or computer machine makes requests of the protocol HTTP
I want to be able to sniff and get the text information of these requests, i
want to be able to trigger event like behavior on these requests, so my
program can respond instantly when an http request happens

how to describe these things in their technical aspects I am ignorant of, if
someone could outline or summarize what I would need to do technically with
python to achieve this, I'll be happy to study methods of how to do these
technical things and eventually write the code myself

thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/63eac455/attachment.htm>

From Mike.Hansen at atmel.com  Tue Oct  7 21:07:01 2008
From: Mike.Hansen at atmel.com (Hansen, Mike)
Date: Tue, 7 Oct 2008 13:07:01 -0600
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <1223405199.21522.4.camel@jeremiah-laptop>
References: <1223405199.21522.4.camel@jeremiah-laptop>
Message-ID: <7941B2693F32294AAF16C26B679A258D0401B94A@csomb01.corp.atmel.com>

 

> Subject: [Tutor] cx_oracle module problems
> 
> I've downloaded the cx_oracle source module for python, howerver every
> time i try to build it, it keeps on failing. I've been unable 
> to find a
> port for Ubuntu. Is there one? Anyone know how to get this properly
> installed?
> 
> # sudo python setup.py install
> Traceback (most recent call last):
>   File "setup.py", line 36, in <module>
>     oracleHome = os.environ["ORACLE_HOME"]
>   File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
>     raise KeyError(key)
> KeyError: 'ORACLE_HOME'
> 
> 
> Link:
> http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.2.tar
> .gz?download	
> 
> Thanks,
> JJ
> 
> 

Did you python setup.py build first? The README.txt mentions it along the option of doing a binary install.

Mike

From malaclypse2 at gmail.com  Tue Oct  7 21:27:30 2008
From: malaclypse2 at gmail.com (Jerry Hill)
Date: Tue, 7 Oct 2008 15:27:30 -0400
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <1223405199.21522.4.camel@jeremiah-laptop>
References: <1223405199.21522.4.camel@jeremiah-laptop>
Message-ID: <16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com>

On Tue, Oct 7, 2008 at 2:46 PM, jeremiah <jeremiah.jester at panasonic.aero> wrote:
> I've downloaded the cx_oracle source module for python, howerver every
> time i try to build it, it keeps on failing. I've been unable to find a
> port for Ubuntu. Is there one? Anyone know how to get this properly
> installed?
>
> # sudo python setup.py install
> Traceback (most recent call last):
>  File "setup.py", line 36, in <module>
>    oracleHome = os.environ["ORACLE_HOME"]
>  File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
>    raise KeyError(key)
> KeyError: 'ORACLE_HOME'

It looks to me like it expects you to already have the oracle client
libraries installed, since it's looking for the 'ORACLE_HOME'
environment variable.

-- 
Jerry

From bermanrl at embarqmail.com  Tue Oct  7 21:40:04 2008
From: bermanrl at embarqmail.com (Robert Berman)
Date: Tue, 07 Oct 2008 15:40:04 -0400
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <1c2a2c590810071054r775a2648u54543b12c264b01b@mail.gmail.com>
References: <48E8FEC7.5090000@embarqmail.com>	
	<1c2a2c590810051154j5d0fac89x539190ace8a6685f@mail.gmail.com>	
	<48E90EFF.9070101@embarqmail.com>	
	<f0b4202b0810071015t4584943cr2649bd634f97ff96@mail.gmail.com>
	<1c2a2c590810071054r775a2648u54543b12c264b01b@mail.gmail.com>
Message-ID: <48EBBB14.4020302@embarqmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/64c00c35/attachment.htm>

From kent37 at tds.net  Tue Oct  7 21:45:14 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 7 Oct 2008 15:45:14 -0400
Subject: [Tutor] Monitoring HTTP connections?
In-Reply-To: <df531c470810071206x20fc217p362b3464e93de626@mail.gmail.com>
References: <df531c470809272020w712d12edo270e67ddf56a841f@mail.gmail.com>
	<1c2a2c590809280439r19ade56avbd1f60fda494deb8@mail.gmail.com>
	<df531c470809281733h1af33ac1gb213c45d03ec6ef3@mail.gmail.com>
	<333efb450809281800t7b9b7658gf821b273d8736dae@mail.gmail.com>
	<df531c470810071206x20fc217p362b3464e93de626@mail.gmail.com>
Message-ID: <1c2a2c590810071245g35a0f778l95e4f40df372ee@mail.gmail.com>

On Tue, Oct 7, 2008 at 3:06 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> on proxy programs:
> i want to sniff the http requests that are being made internally from a
> program I have no control over, so a proxy server won't work, because I
> can't make the program access the internet through a proxy, its not a
> browser that is making the requests

Google 'python libpcap' for some leads, there seem to be three Python
bindings to libpcap.

Kent

From alan.gauld at btinternet.com  Tue Oct  7 23:02:37 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 7 Oct 2008 22:02:37 +0100
Subject: [Tutor] cx_oracle module problems
References: <1223405199.21522.4.camel@jeremiah-laptop>
Message-ID: <gcgiph$k24$1@ger.gmane.org>


"jeremiah" <jeremiah.jester at panasonic.aero> wrote

> port for Ubuntu. Is there one? Anyone know how to get this properly
> installed?
>
> # sudo python setup.py install
>  File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
>    raise KeyError(key)
> KeyError: 'ORACLE_HOME'

Given the error message, do you have ORACLE_HOME defined
as an environment variable for the user account running the script??

Assuming you have Oracle installed on the box you should have
it defined at least for the Oracle admin user ID if not for everyone.
If so try running the script as that user.

HTH,

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



From jeremiah.jester at panasonic.aero  Tue Oct  7 23:30:57 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Tue, 07 Oct 2008 14:30:57 -0700
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com>
References: <1223405199.21522.4.camel@jeremiah-laptop>
	<16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com>
Message-ID: <1223415057.27305.1.camel@jeremiah-laptop>

Got it. Thanks.

When i try 'python setup.py build' i get the following error.

$ sudo python setup.py build
Traceback (most recent call last):
  File "setup.py", line 72, in <module>
    raise DistutilsSetupError, "cannot locate an Oracle software
installation"
distutils.errors.DistutilsSetupError: cannot locate an Oracle software
installation


Thoughts?

Thanks,
JJ

On Tue, 2008-10-07 at 12:27 -0700, Jerry Hill wrote:
> On Tue, Oct 7, 2008 at 2:46 PM, jeremiah
> <jeremiah.jester at panasonic.aero> wrote:
> > I've downloaded the cx_oracle source module for python, howerver
> every
> > time i try to build it, it keeps on failing. I've been unable to
> find a
> > port for Ubuntu. Is there one? Anyone know how to get this properly
> > installed?
> >
> > # sudo python setup.py install
> > Traceback (most recent call last):
> >  File "setup.py", line 36, in <module>
> >    oracleHome = os.environ["ORACLE_HOME"]
> >  File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
> >    raise KeyError(key)
> > KeyError: 'ORACLE_HOME'
> 
> It looks to me like it expects you to already have the oracle client
> libraries installed, since it's looking for the 'ORACLE_HOME'
> environment variable.
> 
> --
> Jerry
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 


Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From srilyk at gmail.com  Tue Oct  7 23:32:43 2008
From: srilyk at gmail.com (W W)
Date: Tue, 7 Oct 2008 16:32:43 -0500
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <1223415057.27305.1.camel@jeremiah-laptop>
References: <1223405199.21522.4.camel@jeremiah-laptop>
	<16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com>
	<1223415057.27305.1.camel@jeremiah-laptop>
Message-ID: <333efb450810071432k74f58c99wbd20bd166775036f@mail.gmail.com>

On Tue, Oct 7, 2008 at 4:30 PM, jeremiah <jeremiah.jester at panasonic.aero>wrote:

> Got it. Thanks.
>
> When i try 'python setup.py build' i get the following error.
>
> $ sudo python setup.py build
> Traceback (most recent call last):
>   File "setup.py", line 72, in <module>
>    raise DistutilsSetupError, "cannot locate an Oracle software
> installation"
> distutils.errors.DistutilsSetupError: cannot locate an Oracle software
> installation
>
>
> Thoughts?


This means you don't have Oracle installed, or setup.py can't find it.

-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/f14f5a54/attachment.htm>

From jeremiah.jester at panasonic.aero  Tue Oct  7 23:42:50 2008
From: jeremiah.jester at panasonic.aero (jeremiah)
Date: Tue, 07 Oct 2008 14:42:50 -0700
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <333efb450810071432k74f58c99wbd20bd166775036f@mail.gmail.com>
References: <1223405199.21522.4.camel@jeremiah-laptop>
	<16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com>
	<1223415057.27305.1.camel@jeremiah-laptop>
	<333efb450810071432k74f58c99wbd20bd166775036f@mail.gmail.com>
Message-ID: <1223415770.27305.5.camel@jeremiah-laptop>

I'm working on a shared box and was told it was installed. How can i
verify installation?

'which oracle' does not return any results. Also, nothing in /etc/init.d
or /usr/bin

JJ

On Tue, 2008-10-07 at 14:32 -0700, W W wrote:
> On Tue, Oct 7, 2008 at 4:30 PM, jeremiah
> <jeremiah.jester at panasonic.aero> wrote:
>         Got it. Thanks.
>         
>         When i try 'python setup.py build' i get the following error.
>         
>         $ sudo python setup.py build
>         Traceback (most recent call last):
>         
>          File "setup.py", line 72, in <module>
>            raise DistutilsSetupError, "cannot locate an Oracle
>         software
>         installation"
>         distutils.errors.DistutilsSetupError: cannot locate an Oracle
>         software
>         installation
>         
>         
>         Thoughts?
> 
> This means you don't have Oracle installed, or setup.py can't find it.
> 
> -Wayne 
> 
> 
> 


Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.



From Mike.Hansen at atmel.com  Tue Oct  7 23:48:50 2008
From: Mike.Hansen at atmel.com (Hansen, Mike)
Date: Tue, 7 Oct 2008 15:48:50 -0600
Subject: [Tutor] cx_oracle module problems
In-Reply-To: <333efb450810071432k74f58c99wbd20bd166775036f@mail.gmail.com>
References: <1223405199.21522.4.camel@jeremiah-laptop><16651e80810071227o21fd109ag2579e29a8e0890c6@mail.gmail.com><1223415057.27305.1.camel@jeremiah-laptop>
	<333efb450810071432k74f58c99wbd20bd166775036f@mail.gmail.com>
Message-ID: <7941B2693F32294AAF16C26B679A258D0401BC1C@csomb01.corp.atmel.com>

>>Got it. Thanks. 
>> 
>>When i try 'python setup.py build' i get the following error. 
>> 
>>$ sudo python setup.py build 
>> 
>>Traceback (most recent call last): 
>> 
>> File "setup.py", line 72, in <module> 
>>   raise DistutilsSetupError, "cannot locate an Oracle software 
>>installation" 
>>distutils.errors.DistutilsSetupError: cannot locate an Oracle software 
>>installation 
>> 
>> 
>>Thoughts? 
> 
> 
>This means you don't have Oracle installed, or setup.py can't find it. 
> 
>-Wayne      
  
I'm guessing that you'll need to install the .deb file from this site. 
Someone can correct me if I'm wrong. 

http://www.oracle.com/technology/software/products/database/xe/htdocs/102xelinsoft.html 

There's installation instructions for Debian(Which I believe Ubuntu is 
derived from) here: 

http://www.oracle.com/technology/software/products/database/xe/files/install.102/b25144/toc.htm#BABFEDEI  

After the client is installed, then hopefully you can build and 
install the cx_oracle module. 

Good luck. If you get stuck maybe someone else can pipe in. Unless 
it's something simple, I usually have trouble if a package is unable 
to install due to some missing library or what not. 

Mike 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/d5695302/attachment.htm>

From srini_iyyer_bio at yahoo.com  Wed Oct  8 00:42:41 2008
From: srini_iyyer_bio at yahoo.com (Srinivas Iyyer)
Date: Tue, 7 Oct 2008 15:42:41 -0700 (PDT)
Subject: [Tutor] Batch searches on Googlescholar
Message-ID: <988932.35548.qm@web38107.mail.mud.yahoo.com>

Dear Tutors, 
This might ben off track question, but I am asking to seek help from experts here. 

I have a list of (n = 240) research publications (Biology and medicine). I have title, journal name and PubMedID. 

my aim is to identify how many times each publication got cited on google Scholar. 
since Googlescholars indexing is different from that of ISI, we have difference in number of citations. GS has more when compared to ISI. It would be nice If I can have both. 

I asked ISI web of knowledge and they do not seem to have batch extraction tools and I did not find any url hooks ( cgi) to automate and parse HTML. 

Any suggestions/ ideas please on Google Scholar. 

Thank you. 
Srini


      

From emile at fenx.com  Wed Oct  8 00:58:12 2008
From: emile at fenx.com (Emile van Sebille)
Date: Tue, 07 Oct 2008 15:58:12 -0700
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <48E8FEC7.5090000@embarqmail.com>
References: <48E8FEC7.5090000@embarqmail.com>
Message-ID: <gcgpif$9oa$1@ger.gmane.org>

Robert Berman wrote:
> Hi,
> 
> The below script which prints anagrams available for any word available 
> within a given database. It does work, but  it is not very fast. I am 
> relatively certain there are more Python friendly coding techniques but 
> I am more concerned with a faster algorithm.

You might consider looking up the permutations only (up to some length 
-- there are a lot of permutations for 8+ letter words :)

#from http://www.daniweb.com/code/snippet459.html

def permutate(seq):
     """permutate a sequence and return a list of the permutations"""
     if not seq:
         return [seq]  # is an empty sequence
     else:
         temp = []
         for k in range(len(seq)):
             part = seq[:k] + seq[k+1:]
             #print k, part  # test
             for m in permutate(part):
                 temp.append(seq[k:k+1] + m)
                 #print m, seq[k:k+1], temp  # test
         return temp

print permutate('myth')

['myth', 'myht', 'mtyh', 'mthy', 'mhyt', 'mhty', 'ymth', 'ymht', 'ytmh', 
'ythm', 'yhmt', 'yhtm', 'tmyh', 'tmhy', 'tymh', 'tyhm', 'thmy', 'thym', 
'hmyt', 'hmty', 'hymt', 'hytm', 'htmy', 'htym']

 >>> print len(permutate('mythsdfw'))
40320
 >>> print len(permutate('mythsdf'))
5040
 >>> print len(permutate('mythsd'))
720
 >>> print len(permutate('myths'))
120
 >>> print len(permutate('myth'))
24
 >>> print len(permutate('myt'))
6

so something like:

print [ xx for xx in permutate('myths') if xx in worddict ]


HTH,

Emile


From srilyk at gmail.com  Wed Oct  8 02:23:55 2008
From: srilyk at gmail.com (W W)
Date: Tue, 7 Oct 2008 19:23:55 -0500
Subject: [Tutor] Batch searches on Googlescholar
In-Reply-To: <988932.35548.qm@web38107.mail.mud.yahoo.com>
References: <988932.35548.qm@web38107.mail.mud.yahoo.com>
Message-ID: <333efb450810071723l63bcd89m3666dac49b500ff7@mail.gmail.com>

On Tue, Oct 7, 2008 at 5:42 PM, Srinivas Iyyer <srini_iyyer_bio at yahoo.com>wrote:

> Dear Tutors,
> This might ben off track question, but I am asking to seek help from
> experts here.
>
> I have a list of (n = 240) research publications (Biology and medicine). I
> have title, journal name and PubMedID.
>
> my aim is to identify how many times each publication got cited on google
> Scholar.
> since Googlescholars indexing is different from that of ISI, we have
> difference in number of citations. GS has more when compared to ISI. It
> would be nice If I can have both.
>
> I asked ISI web of knowledge and they do not seem to have batch extraction
> tools and I did not find any url hooks ( cgi) to automate and parse HTML.


You can use the urllib builtin module and beautiful soup for parsing HTML. I
don't know if the Googlescholars page allows python connections, I know
regular google queries do not (they frown on web scraping, AFAIK)

that's about as specific as you'll probably get without a more explicit
example.

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/119a894a/attachment.htm>

From srilyk at gmail.com  Wed Oct  8 02:39:33 2008
From: srilyk at gmail.com (W W)
Date: Tue, 7 Oct 2008 19:39:33 -0500
Subject: [Tutor] More Pythonesque or a more efficient method
In-Reply-To: <gcgpif$9oa$1@ger.gmane.org>
References: <48E8FEC7.5090000@embarqmail.com> <gcgpif$9oa$1@ger.gmane.org>
Message-ID: <333efb450810071739j78ec60b2j45c3636e31ea39ad@mail.gmail.com>

On Tue, Oct 7, 2008 at 5:58 PM, Emile van Sebille <emile at fenx.com> wrote:

> Robert Berman wrote:
>
>> Hi,
>>
>> The below script which prints anagrams available for any word available
>> within a given database. It does work, but  it is not very fast. I am
>> relatively certain there are more Python friendly coding techniques but I am
>> more concerned with a faster algorithm.
>>
>
> You might consider looking up the permutations only (up to some length --
> there are a lot of permutations for 8+ letter words :)
>

I'm not sure if this would be any faster, but I'd be curious at least to
know what the difference would be to have a database of every possible
permutation for every length up to 10, i.e:

0
01
10
012
021
102
120
201
210
.
.
.
etc.

And then simply use the key values of the letter... perhaps the anagrams
stored in a dict by length as the key:
mutations = {1: [(0,)], 2: [(0,1), (1,0)],}

so for instance:

myword = "if"
mylen = len(myword)
for mytuple in mutations[mylen]:
    for x in mytuple:
        print myword[x]

I think that would work anyway. I don't know if I have the code right, and
I'm not sure if it would be faster, slower, or no change, but it may be
worth a look.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081007/ea8174c1/attachment-0001.htm>

From alan.gauld at btinternet.com  Wed Oct  8 10:35:15 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 8 Oct 2008 09:35:15 +0100
Subject: [Tutor] Batch searches on Googlescholar
References: <988932.35548.qm@web38107.mail.mud.yahoo.com>
	<333efb450810071723l63bcd89m3666dac49b500ff7@mail.gmail.com>
Message-ID: <gchrc8$pt4$1@ger.gmane.org>


"W W" <srilyk at gmail.com> wrote

>> my aim is to identify how many times each publication got cited on 
>> google
>> Scholar.

> You can use the urllib builtin module and beautiful soup for parsing 
> HTML. I
> don't know if the Googlescholars page allows python connections, I 
> know
> regular google queries do not (they frown on web scraping, AFAIK)

Thats what I was about to say too.
But Google do have a Web Service API that might work on Scholar
too, that would be worth investigating...

Alan G. 



From mail at timgolden.me.uk  Wed Oct  8 10:38:44 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Wed, 08 Oct 2008 09:38:44 +0100
Subject: [Tutor] Batch searches on Googlescholar
In-Reply-To: <gchrc8$pt4$1@ger.gmane.org>
References: <988932.35548.qm@web38107.mail.mud.yahoo.com>	<333efb450810071723l63bcd89m3666dac49b500ff7@mail.gmail.com>
	<gchrc8$pt4$1@ger.gmane.org>
Message-ID: <48EC7194.1050602@timgolden.me.uk>

Alan Gauld wrote:
> 
> "W W" <srilyk at gmail.com> wrote
> 
>>> my aim is to identify how many times each publication got cited on 
>>> google
>>> Scholar.
> 
>> You can use the urllib builtin module and beautiful soup for parsing 
>> HTML. I
>> don't know if the Googlescholars page allows python connections, I know
>> regular google queries do not (they frown on web scraping, AFAIK)
> 
> Thats what I was about to say too.
> But Google do have a Web Service API that might work on Scholar
> too, that would be worth investigating...

per this page:

http://code.google.com/apis/soapsearch/reference.html

"""
As of December 5, 2006, we are no longer issuing new API keys 
for the SOAP Search API. Developers with existing SOAP Search 
API keys will not be affected.
"""


TJG

From matthill1979 at yahoo.com  Thu Oct  9 07:04:05 2008
From: matthill1979 at yahoo.com (Matthew Hill)
Date: Wed, 8 Oct 2008 22:04:05 -0700 (PDT)
Subject: [Tutor] Installation Problems
Message-ID: <85436.11100.qm@web45701.mail.sp1.yahoo.com>

I am a newly beginning aspiring programmer.? I have been learning Blender 3D and I want to use python with it.? I downloaded the newest version of python and I?tried running it with Blender 2.47.? Python would work alone but would not with Blender.? I read on a forum that I needed to get python 5.52 to match with what blender wants.? Only the new (5.52) version won't install.? It says 'contact the vender to verify this is a windows program' when I try the install.? What is going on?? Is 5.52 compatible with windows vista?? Am I just missing something?? The prompt I got inside blender with 2.6 was: 
'import site' failed; use -v for traceback
checking for installed Python... no installed Python found.
Only built-in modules are available. some scripts may not run.
continuing happily.
?
any insight to these problems would really help me out


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081008/4665c27a/attachment.htm>

From sierra_mtnview at sbcglobal.net  Thu Oct  9 17:49:24 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 09 Oct 2008 08:49:24 -0700
Subject: [Tutor] Reading Files and Such
In-Reply-To: <48E1566C.1090107@gmail.com>
References: <48E0BBB5.2050206@sbcglobal.net> <48E1566C.1090107@gmail.com>
Message-ID: <48EE2804.5050707@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/c2c5e39a/attachment.htm>

From sierra_mtnview at sbcglobal.net  Thu Oct  9 18:03:47 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 09 Oct 2008 09:03:47 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff), ...
Message-ID: <48EE2B63.4020000@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/048e2a56/attachment.htm>

From mccartneydamon at googlemail.com  Thu Oct  9 19:28:17 2008
From: mccartneydamon at googlemail.com (Damon McCartney)
Date: Thu, 9 Oct 2008 18:28:17 +0100
Subject: [Tutor] Pyserial and general python serial help
Message-ID: <1a98b3200810091028ue315838ia5f8150a795f3daf@mail.gmail.com>

Hi!

New to python but finding it fast and effective to use! But heres my
problem,

Im trying to read data from the serial port which is being sent from a
device every 10ms, I seem to be able to read the data in a while loop but
eventually the buffer seems to overflow and the data gets scrambled.

Any help would be fantastic!

Regards
D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/4e9f0908/attachment.htm>

From kent37 at tds.net  Thu Oct  9 20:22:26 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 9 Oct 2008 14:22:26 -0400
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
In-Reply-To: <48EE2B63.4020000@sbcglobal.net>
References: <48EE2B63.4020000@sbcglobal.net>
Message-ID: <1c2a2c590810091122q10ce397avdf1dafc5cf60885@mail.gmail.com>

On Thu, Oct 9, 2008 at 12:03 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Is there a Win Python environment that provides Linux like facilities like
> diff (compare) and checking in and out program files?

This is not really a Python question. There are many good diff
programs for Windows, a couple of free ones are WinMerge and ExamDiff.
http://www.winmerge.org/
http://www.prestosoft.com/ps.asp?page=edp_examdiff

A big list here:
http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools

For checkin/checkout you need a version control system, many are listed here:
http://en.wikipedia.org/wiki/List_of_revision_control_software

If you are already using a VCS then you just need the Windows client.

Kent

From kent37 at tds.net  Thu Oct  9 20:23:18 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 9 Oct 2008 14:23:18 -0400
Subject: [Tutor] Pyserial and general python serial help
In-Reply-To: <1a98b3200810091028ue315838ia5f8150a795f3daf@mail.gmail.com>
References: <1a98b3200810091028ue315838ia5f8150a795f3daf@mail.gmail.com>
Message-ID: <1c2a2c590810091123g6e50b845qcc1bae7b253960b4@mail.gmail.com>

On Thu, Oct 9, 2008 at 1:28 PM, Damon McCartney
<mccartneydamon at googlemail.com> wrote:

> Im trying to read data from the serial port which is being sent from a
> device every 10ms, I seem to be able to read the data in a while loop but
> eventually the buffer seems to overflow and the data gets scrambled.

It helps if you show us your code and evidence of the problem you are having.

Kent

From cfuller084 at thinkingplanet.net  Thu Oct  9 20:30:07 2008
From: cfuller084 at thinkingplanet.net (Chris Fuller)
Date: Thu, 9 Oct 2008 19:30:07 +0100 (BST)
Subject: [Tutor] Pyserial and general python serial help
Message-ID: <200810091830.m99IU7Ye007937@mail.authsmtp.com>

Are you reading everything in the buffer? How much data is sent every 
10ms? At 9600/8/N/1, the throughput is 960 byes a second, so if there's 
more than 9 bytes, something will give. Similarly, at 115200 baud, the 
limit is 115 bytes.

Some general advice: don't try to sync your program to the 10ms cycle, 
that will be very difficult to do under a modern operating system. Just 
grab all the data waiting in the buffer and find some way to divide it 
into the appropriate time slices.

PySerial has a method that returns the number of bytes in the buffer, so 
use that to set how many bytes you read.

Cheers


From wbgibson2 at yahoo.com  Thu Oct  9 20:42:21 2008
From: wbgibson2 at yahoo.com (Bill Gibson)
Date: Thu, 9 Oct 2008 11:42:21 -0700 (PDT)
Subject: [Tutor] return a dictionary?
Message-ID: <211696.69919.qm@web63002.mail.re1.yahoo.com>

Can I ?return? a dictionary from an imported Python script?
I have a utility module (NameAddress.py) ?done using Tkinter. (For example, Name/Address City,State,Zip,Email, Phone) that I want to use as imported module. I wanted to return the values as a dictionary to the module that imported but this does not seem to work.
This is the dictionary as printed out from the NameAddress.py by print theDict shows what I want:
{'City': 'San Francisco', 'Name': 'Sam Spade', 'Zip': '98765', 'Address1': 'Apt. #87', 'Address2': '2345 Union Street', 'Phone': '1-415-896-9876', 'State': 'Ca.', 'Email': 'samspade at yahoo.com'}
However the code for return in NameAddress.py ?, I.E. ????return theDict
gives this error when called from a testing module (Inter_module.py)? whose code looks like this:
??????????????? import NameAddress
??????????????? y = NameAddress.getName()? 
??????????????? print y
Traceback (most recent call last):
? File "C:\Python24\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py", line 310, in RunScript
??? exec codeObject in __main__.__dict__
? File "C:\Users\B\Desktop\Inter_module.py", line 6, in ?
??? y = NameAddress.getName()
? File "C:\Users\B\Desktop\NameAddress.py", line 22, in getName
??? theDict={'Name': w2.get(), 'Address1': w4.get(), 'Address2': w6.get(),'City':w8.get()}
? File "C:\Python24\Lib\lib-tk\Tkinter.py", line 2303, in get
??? return self.tk.call(self._w, 'get')
TclError: invalid command name ".43065216"


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/560e79ae/attachment-0001.htm>

From Mike.Hansen at atmel.com  Thu Oct  9 21:11:34 2008
From: Mike.Hansen at atmel.com (Hansen, Mike)
Date: Thu, 9 Oct 2008 13:11:34 -0600
Subject: [Tutor] Output parameters from a stored procedure
Message-ID: <7941B2693F32294AAF16C26B679A258D0408EAAE@csomb01.corp.atmel.com>

Does anyone know how to get the output parameters from a stored procedure?

I'm using pymssql on a linux box to call a stored procedure on a mssql
database. I'm not sure of the correct syntax to get the output
parameters.

import pymssql

con = pymssql.connect(host='xxxxx',user='xxxx',password='xxxxx',database='xxxxx')

cur = con.cursor()

query = "EXECUTE blah blah blah"

cur.execute(query)
con.commit()
con.close()

Mike

From alan.gauld at btinternet.com  Thu Oct  9 21:42:25 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 9 Oct 2008 20:42:25 +0100
Subject: [Tutor] Reading Files and Such
References: <48E0BBB5.2050206@sbcglobal.net> <48E1566C.1090107@gmail.com>
	<48EE2804.5050707@sbcglobal.net>
Message-ID: <gclmr7$ink$1@ger.gmane.org>


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

> Yes, listdir does not read files, it just prepares a list of all 
> files
> in the folder. I work my way through them as needed. It looks
> like glob does something similar.

Yes but glob can use wildcards to select only files matching
the pattern (eg *.txt to list only txt files)

> The real question is about tmp files. I believe there's a tmpfiles 
> module.
> What's so special about the tmp suffix?

On XP very little but on *nix it generally means a file to be stored
in the tmp folder and often with an auto generated filename based
on the process ID - which avoids problems when multiple
instances of the same program run. Also the tmp file is often
emptied when the system boots so avoiding disk wastage.
Using tempfuiles helps manage these things a little but on
XP has very luittle advantage because XP itself doesn't really
do much of anything with tmp files... But if you want the
script or module to ever be ported/used on *nix then using
tempfiles is still worthwhile.

HTH

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



From kent37 at tds.net  Thu Oct  9 21:45:40 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 9 Oct 2008 15:45:40 -0400
Subject: [Tutor] return a dictionary?
In-Reply-To: <211696.69919.qm@web63002.mail.re1.yahoo.com>
References: <211696.69919.qm@web63002.mail.re1.yahoo.com>
Message-ID: <1c2a2c590810091245y4e6213c1r2a49beeb21247e91@mail.gmail.com>

2008/10/9 Bill Gibson <wbgibson2 at yahoo.com>:

> Traceback (most recent call last):
>
>   File "C:\Python24\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py",
> line 310, in RunScript
>
>     exec codeObject in __main__.__dict__
>
>   File "C:\Users\B\Desktop\Inter_module.py", line 6, in ?
>
>     y = NameAddress.getName()
>
>   File "C:\Users\B\Desktop\NameAddress.py", line 22, in getName
>
>     theDict={'Name': w2.get(), 'Address1': w4.get(), 'Address2':
> w6.get(),'City':w8.get()}
>
>   File "C:\Python24\Lib\lib-tk\Tkinter.py", line 2303, in get
>
>     return self.tk.call(self._w, 'get')
>
> TclError: invalid command name ".43065216"

This looks like an error in NameAddress.py, perhaps something that is
not being initialized correctly when you import it? Do you have a
if __name__ == '__main__':
section in NameAddress.py? Does it do some required initialization?

It sounds like you are doing something similar to EasyGui's multienterbox:
http://easygui.sourceforge.net/easygui.html#-multenterbox

Kent

From alan.gauld at btinternet.com  Thu Oct  9 21:47:12 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 9 Oct 2008 20:47:12 +0100
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
References: <48EE2B63.4020000@sbcglobal.net>
Message-ID: <gcln45$jrc$1@ger.gmane.org>

"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote 

> Is there a Win Python environment that 
> provides Linux like facilities like diff (compare) 
> and checking in and out program files? 

Cygwin provides a fill Unix like environment on Windows 
and if you know Unix at all is a must-have addon  IMHO! :-)

But iof you don;t you can use the standard XP comp 
commandline tool, Try HELP COMP at the OS prompt...

For version control most toos have Windows versions: 
RCS, CVS, SVN etc Some are even file compatible with 
their *nix versions.

> Is there some way I might be able to simply identity 
> my code from the original?  

That depends, but COMP may be sufficient.
Othewise there are various GUI based diff tools that 
you can download, both freeware and shareware.
Try a search on download.com or simtel or any 
other download site

HTH,

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


From pierre.dagenais at ncf.ca  Thu Oct  9 21:55:32 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Thu, 09 Oct 2008 15:55:32 -0400
Subject: [Tutor] Installation Problems
In-Reply-To: <85436.11100.qm@web45701.mail.sp1.yahoo.com>
References: <85436.11100.qm@web45701.mail.sp1.yahoo.com>
Message-ID: <48EE61B4.4060306@ncf.ca>

Matthew Hill wrote:
> I am a newly beginning aspiring programmer.  I have been learning Blender 3D and I want to use python with it.  I downloaded the newest version of python and I tried running it with Blender 2.47.  Python would work alone but would not with Blender.  I read on a forum that I needed to get python 5.52 to match with what blender wants. 
>   
Version 5.52 ??? The latest version of python is 2.6 (3.0 for beta).
>  Only the new (5.52) version won't install.  It says 'contact the vender to verify this is a windows program' when I try the install.  What is going on?  Is 5.52 compatible with windows vista?  Am I just missing something?  The prompt I got inside blender with 2.6 was: 
> 'import site' failed; use -v for traceback
> checking for installed Python... no installed Python found.
>   
Sounds like a blender problem, blender can't find python.exe which 
usually is in C:\python26. Unfortunately I'm not familiar with blender.
> Only built-in modules are available. some scripts may not run.
> continuing happily.
>  
> any insight to these problems would really help me out
>
>
>       
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 08/10/2008 7:19 PM
>
>   


From alan.gauld at btinternet.com  Thu Oct  9 21:56:50 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 9 Oct 2008 20:56:50 +0100
Subject: [Tutor] return a dictionary?
References: <211696.69919.qm@web63002.mail.re1.yahoo.com>
Message-ID: <gclnm8$m23$1@ger.gmane.org>

"Bill Gibson" <wbgibson2 at yahoo.com> wrote

> Can I ?return? a dictionary from an imported Python script?

Yes.

> I have a utility module (NameAddress.py) done using
> Tkinter. ...I wanted to return the values as a dictionary
> to the module that imported but this does not seem to work.

I'm not totally clear what you mean here.

> This is the dictionary as printed out from the
> NameAddress.py by
> print theDict
> shows what I want:

Is the print statement in your module or in NameAddress.py?

> However the code for return in NameAddress.py , I.E.
> return theDict
> gives this error when called from a testing module
> (Inter_module.py) whose code looks like this:
> import NameAddress
> y = NameAddress.getName()
> print y
> Traceback (most recent call last):
> File "C:\Users\B\Desktop\Inter_module.py", line 6, in ?
> y = NameAddress.getName()
> File "C:\Users\B\Desktop\NameAddress.py", line 22, in getName
> theDict={'Name': w2.get(), 'Address1': w4.get(), ...
> File "C:\Python24\Lib\lib-tk\Tkinter.py", line 2303, in get
> return self.tk.call(self._w, 'get')
> TclError: invalid command name ".43065216"

This suggests an invalid reference is being sent to the method.
To me it doesn't look like you create any data or instances
or anything with NameAddress? I assume it does all of that
in its initialisation when you import it?

Othewise you are going to have to do something to initialise
some Tkinter widgets before trying to access them via getName().

Are there any data attributes you can access directly in
the module to prove it has initialised?

HTH,

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



From srilyk at gmail.com  Thu Oct  9 22:00:27 2008
From: srilyk at gmail.com (W W)
Date: Thu, 9 Oct 2008 15:00:27 -0500
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
In-Reply-To: <gcln45$jrc$1@ger.gmane.org>
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
Message-ID: <333efb450810091300y1d01ded3l945779f737e9a24a@mail.gmail.com>

Vim also has a diff mode.
-Wayne

From sierra_mtnview at sbcglobal.net  Fri Oct 10 01:41:57 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 09 Oct 2008 16:41:57 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
 ...
In-Reply-To: <1c2a2c590810091122q10ce397avdf1dafc5cf60885@mail.gmail.com>
References: <48EE2B63.4020000@sbcglobal.net>
	<1c2a2c590810091122q10ce397avdf1dafc5cf60885@mail.gmail.com>
Message-ID: <48EE96C5.8040809@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/1c0ae5c5/attachment-0001.htm>

From sierra_mtnview at sbcglobal.net  Fri Oct 10 01:48:00 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 09 Oct 2008 16:48:00 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
 ...
In-Reply-To: <gcln45$jrc$1@ger.gmane.org>
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
Message-ID: <48EE9830.9090001@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/4e7e213b/attachment.htm>

From sierra_mtnview at sbcglobal.net  Fri Oct 10 01:49:13 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 09 Oct 2008 16:49:13 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
 ...
In-Reply-To: <48EE97EA.2060408@sbcglobal.net>
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
	<48EE97EA.2060408@sbcglobal.net>
Message-ID: <48EE9879.1090806@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/43cadb10/attachment.htm>

From kent37 at tds.net  Fri Oct 10 06:09:16 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 10 Oct 2008 00:09:16 -0400
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
In-Reply-To: <48EE9830.9090001@sbcglobal.net>
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
	<48EE9830.9090001@sbcglobal.net>
Message-ID: <1c2a2c590810092109x4ce940bdsa60839d3fafd9067@mail.gmail.com>

On Thu, Oct 9, 2008 at 7:48 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Well, maybe I'll give Cygwin a go again. I tried it 2-3 years ago and it was
> troublesome. I'd really like to have Unix/Linux available, so maybe. I
> really don't use Linux any longer, but it does have some very good features
> like diff than can be helpful even in a Win env.

Many of the GNU tools - including diff - are available for native
Windows (not Cygwin) from the GnuWin32 project:
http://gnuwin32.sourceforge.net/packages.html

I use TCC as a shell, it's not bash but it is a bit smarter than
cmd.exe. Unfortunately it still runs in the brain-dead Windows
console.
http://jpsoft.com/

Kent

From alan.gauld at btinternet.com  Fri Oct 10 07:54:34 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 10 Oct 2008 06:54:34 +0100
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
	<48EE9830.9090001@sbcglobal.net>
Message-ID: <gcmqn0$5od$1@ger.gmane.org>


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote 

> What's the trick win comp? The window disappears quickly.

Its a command line tool, you need to run it from a CMD window.

Like so:

H:\PROJECTS\Python>comp foo.py foo.tst /L /A
Comparing foo.py and foo.tst...
Compare error at LINE 1
file1 = g
file2 = h
Compare more files (Y/N) ?

Use HELP COMP for more options.


HTH

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


From lie.1296 at gmail.com  Mon Oct  6 07:59:02 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Mon, 06 Oct 2008 12:59:02 +0700
Subject: [Tutor] first call - newcomer
In-Reply-To: <mailman.16704.1223263963.3486.tutor@python.org>
References: <mailman.16704.1223263963.3486.tutor@python.org>
Message-ID: <1223272743.6409.10.camel@lieryan-laptop>

On Mon, 2008-10-06 at 05:32 +0200, tutor-request at python.org wrote:
> 
> Message: 8
> Date: Sun, 5 Oct 2008 20:27:39 -0700
> From: Anthony Smith <gods_bud666 at hotmail.com>
> Subject: [Tutor] first call - newcomer
> To: <tutor at python.org>
> Message-ID: <BLU146-W21D0F815F794C49517F301CA390 at phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> 
> This is my first post - I will be brief...
>  
> One:  I have programmed before - but it has been DECADES...so just a
> few simple queries:
>  
> 1.  A brief (but complete) description regarding the use of script
> editor (I will be using

Your script editor can be any plain text-editing tools, Notepad could
do.

>      command prompt in Windows), as:
>  
>          a.  details about loading and saving programs (not in that
> order) and little
>               specs about pathnames or other requirements (I will
> probably store all
>               my little goodies in one folder or space).

Pathnames is free, you can name your program anything your OS allows for
a file. A convention is to name the script ending with .py/.pyw
extension (command-line script/GUI script), although python doesn't
complain if it is not in those extension (in Windows, the extension is
associated with the interpreter). Calling a program from command line is
done like this:

python filename.py

>       That should get me going ... a book and manual by my side should
> suffice for
>        the rest - - - except for one thing:

> 2.  I have been unable to locate the gizmo in the literature to get
> ascii codes
>     in python.  In the old days, it was a list of 256 (or so)
> characters that 
>     represented all keyboard symbols (A equalled 36; B equalled 37; et
> cetera).
>    To assign a value, you used "Let A$ = ASC (36)" where A$ was a
> variable
>     and 36 was the ASCII value for 'A'.  I believe the reverse of this
> process
>     was PRINT VAL(A$) or something.  I want to play with a program
> that will
>    assign a number to a word (using a simple algorhythm that will give
> a
>     specific number to every word).  Other stuff is pretty easy to
> find with
>     the book and on-line literature.  I will need to get an ascii code
> out of
>      a string (whose content is not known to the programmer, as
> raw_input).
>     Then to assign, I will need the actual list with assigned numbers.

a = ord('A')
b = chr(36)

-- read on the help file: Built-in Functions
 
> You will be giving me probably the only boost I will need!  I will be
> available later on,
> if I want to take part in the ask/answer system here.


From pierre.dagenais at ncf.ca  Fri Oct 10 12:38:10 2008
From: pierre.dagenais at ncf.ca (Pierre Dagenais)
Date: Fri, 10 Oct 2008 06:38:10 -0400
Subject: [Tutor] Installation Problems
In-Reply-To: <4932.19721.qm@web45705.mail.sp1.yahoo.com>
References: <4932.19721.qm@web45705.mail.sp1.yahoo.com>
Message-ID: <48EF3092.2070504@ncf.ca>

Matthew Hill wrote:
> oops  I ment to say 2.5.2 is what blender wanted and 2.6 was the newest one I had
>   
Then blender is likely to look for python.exe in c:\python25 while on 
your computer it's probably under c:\python26. Try renaming the 
directory c:\python26 to c:\python25 and see if that works. You might 
also have to modify the PATH and PYTHONPATH environments.
If you wish to install python v2.5.2 maybe you need to uninstall v 2.6, 
just gessing.
HTH

Pierre
> --- On Thu, 10/9/08, Pierre Dagenais <pierre.dagenais at ncf.ca> wrote:
>
> From: Pierre Dagenais <pierre.dagenais at ncf.ca>
> Subject: Re: [Tutor] Installation Problems
> To: 
> Cc: tutor at python.org
> Date: Thursday, October 9, 2008, 7:55 PM
>
> Matthew Hill wrote:
>   
>> I am a newly beginning aspiring programmer.  I have been learning Blender
>>     
> 3D and I want to use python with it.  I downloaded the newest version of python
> and I tried running it with Blender 2.47.  Python would work alone but would not
> with Blender.  I read on a forum that I needed to get python 5.52 to match with
> what blender wants. 
>   
>>   
>>     
> Version 5.52 ??? The latest version of python is 2.6 (3.0 for beta).
>   
>>  Only the new (5.52) version won't install.  It says 'contact the
>>     
> vender to verify this is a windows program' when I try the install.  What is
> going on?  Is 5.52 compatible with windows vista?  Am I just missing something? 
> The prompt I got inside blender with 2.6 was: 
>   
>> 'import site' failed; use -v for traceback
>> checking for installed Python... no installed Python found.
>>   
>>     
> Sounds like a blender problem, blender can't find python.exe which 
> usually is in C:\python26. Unfortunately I'm not familiar with blender.
>   
>> Only built-in modules are available. some scripts may not run.
>> continuing happily.
>>  
>> any insight to these problems would really help me out
>>
>>
>>       
>>   
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>   
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com 
>> Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 08/10/2008
>>     
> 7:19 PM
>   
>>   
>>     
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
>       
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.8.0/1717 - Release Date: 09/10/2008 4:56 PM
>
>   


From sierra_mtnview at sbcglobal.net  Fri Oct 10 17:39:02 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Fri, 10 Oct 2008 08:39:02 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
 ...
In-Reply-To: <48EE96C5.8040809@sbcglobal.net>
References: <48EE2B63.4020000@sbcglobal.net>	<1c2a2c590810091122q10ce397avdf1dafc5cf60885@mail.gmail.com>
	<48EE96C5.8040809@sbcglobal.net>
Message-ID: <48EF7716.40202@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081010/0491a55a/attachment.htm>

From f8lcoder at hotmail.com  Sat Oct 11 04:45:11 2008
From: f8lcoder at hotmail.com (S Potter)
Date: Fri, 10 Oct 2008 22:45:11 -0400
Subject: [Tutor] Iterating two one dimensional lists to create a
	multidemsional array
Message-ID: <BLU127-W463C33C9F3CF820C31814082340@phx.gbl>

OK I'm still new to the python list / array deal. I'm having problems with something very simple that I could accomplish in C++ but
for some reason I'm not grasping it python.

Here is my example psuedo code:

I have two lists:

items = ['roses','violets','sugar','so']

and

attributes = ['red','blue','sweet','you']

I have a variable:

action = 'are'

>From the above lists I would like to populate a multi dimensional array that would be like this;

poem ={ ['roses','are red'],
              ['violets','are blue'],
              ['sugar','are sweet']
              ['so','are you'] }

I'm assuming I would need two separate loops once through list(items) and then through list(attributes) and would have to concatenate variable(action) + str(attributes[0]).

But I'm having a severe brain squeeze right now and cannot get my code to work as desired.

Could someone please show me what the code should look like?

I know this is very elementary, I also know I can accomplish this in other languages but the objective is to
get my head around the python version.

Your help would be greatly appreciated.

Thanks





_________________________________________________________________
Want to do more with Windows Live? Learn ?10 hidden secrets? from Jamie.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081010/233e73b2/attachment.htm>

From kent37 at tds.net  Sat Oct 11 05:59:19 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 10 Oct 2008 23:59:19 -0400
Subject: [Tutor] Iterating two one dimensional lists to create a
	multidemsional array
In-Reply-To: <BLU127-W463C33C9F3CF820C31814082340@phx.gbl>
References: <BLU127-W463C33C9F3CF820C31814082340@phx.gbl>
Message-ID: <1c2a2c590810102059m40ac2821i76d103fff517c0b2@mail.gmail.com>

On Fri, Oct 10, 2008 at 10:45 PM, S Potter <f8lcoder at hotmail.com> wrote:
> OK I'm still new to the python list / array deal. I'm having problems with
> something very simple that I could accomplish in C++ but
> for some reason I'm not grasping it python.
>
> Here is my example psuedo code:
>
> I have two lists:
>
> items = ['roses','violets','sugar','so']
>
> and
>
> attributes = ['red','blue','sweet','you']
>
> I have a variable:
>
> action = 'are'
>
> From the above lists I would like to populate a multi dimensional array that
> would be like this;
>
> poem ={ ['roses','are red'],
>               ['violets','are blue'],
>               ['sugar','are sweet']
>               ['so','are you'] }

The zip() function is handy for processing multiple lists in parallel.
List comprehensions are handy for processing lists by item. Together
they make short work of this:

In [5]: items = ['roses','violets','sugar','so']

In [6]: attributes = ['red','blue','sweet','you']

In [7]: zip(items, attributes)
Out[7]: [('roses', 'red'), ('violets', 'blue'), ('sugar', 'sweet'),
('so', 'you')]

In [8]: [ [item, 'are '+attribute] for item, attribute in zip(items,
attributes) ]
Out[8]:
[['roses', 'are red'],
 ['violets', 'are blue'],
 ['sugar', 'are sweet'],
 ['so', 'are you']]

Kent

From sierra_mtnview at sbcglobal.net  Sat Oct 11 08:03:34 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Fri, 10 Oct 2008 23:03:34 -0700
Subject: [Tutor] Text Scatter Plots?
In-Reply-To: <1c2a2c590809290903p7a75c5e6y6d0aa9f8bd2913fa@mail.gmail.com>
References: <48E0BD38.9000904@sbcglobal.net> <gbqnpi$hv3$1@ger.gmane.org>	
	<48E0F557.70206@sbcglobal.net>
	<1c2a2c590809290903p7a75c5e6y6d0aa9f8bd2913fa@mail.gmail.com>
Message-ID: <48F041B6.7010600@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081010/71b6c2a0/attachment-0001.htm>

From srilyk at gmail.com  Sat Oct 11 13:13:34 2008
From: srilyk at gmail.com (W W)
Date: Sat, 11 Oct 2008 06:13:34 -0500
Subject: [Tutor] Iterating two one dimensional lists to create a
	multidemsional array
In-Reply-To: <1c2a2c590810102059m40ac2821i76d103fff517c0b2@mail.gmail.com>
References: <BLU127-W463C33C9F3CF820C31814082340@phx.gbl>
	<1c2a2c590810102059m40ac2821i76d103fff517c0b2@mail.gmail.com>
Message-ID: <333efb450810110413o1394e62fi5bae8f06cf7a884a@mail.gmail.com>

On Fri, Oct 10, 2008 at 10:59 PM, Kent Johnson <kent37 at tds.net> wrote:
> On Fri, Oct 10, 2008 at 10:45 PM, S Potter <f8lcoder at hotmail.com> wrote:
><snip>
>> poem ={ ['roses','are red'],
>>               ['violets','are blue'],
>>               ['sugar','are sweet']
>>               ['so','are you'] }

Another thing to note - the way you have it written here, { } is the
dictionary notation, and dictionaries are unordered, and require
immutable keys (lists are mutable).

HTH,
Wayne

From kent37 at tds.net  Sat Oct 11 14:10:59 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 11 Oct 2008 08:10:59 -0400
Subject: [Tutor] Text Scatter Plots?
In-Reply-To: <48F041B6.7010600@sbcglobal.net>
References: <48E0BD38.9000904@sbcglobal.net> <gbqnpi$hv3$1@ger.gmane.org>
	<48E0F557.70206@sbcglobal.net>
	<1c2a2c590809290903p7a75c5e6y6d0aa9f8bd2913fa@mail.gmail.com>
	<48F041B6.7010600@sbcglobal.net>
Message-ID: <1c2a2c590810110510k60c7bc35yadc672a9f5ac99f8@mail.gmail.com>

On Sat, Oct 11, 2008 at 2:03 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Hi, I'm finally in a position where I might want to use matplotlib. I looked
> at the site but I'm not sure there's a download for 2.4.

This page shows matplotlib-0.98.3.win32-py2.4.exe:
http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=278194

Kent

From sierra_mtnview at sbcglobal.net  Sat Oct 11 14:52:51 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 05:52:51 -0700
Subject: [Tutor] Running Two Versions of Python on the Same PC
Message-ID: <48F0A1A3.7010706@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/39b45940/attachment.htm>

From noufal at nibrahim.net.in  Sat Oct 11 15:23:17 2008
From: noufal at nibrahim.net.in (Noufal Ibrahim)
Date: Sat, 11 Oct 2008 18:53:17 +0530
Subject: [Tutor] Running Two Versions of Python on the Same PC
In-Reply-To: <48F0A1A3.7010706@sbcglobal.net>
References: <48F0A1A3.7010706@sbcglobal.net>
Message-ID: <48F0A8C5.30204@nibrahim.net.in>

Wayne Watson wrote:
> Is it possible to do as in Subject on Win XP? Say, 2.4 and 2.5.
> -- 

You can create virtual installations of Python which might work for you.
I do it for custom package installation etc.

The virtualenv pakcage is what I use.
http://pypi.python.org/pypi/virtualenv


-- 
~noufal
http://nibrahim.net.in/

From kent37 at tds.net  Sat Oct 11 16:21:03 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 11 Oct 2008 10:21:03 -0400
Subject: [Tutor] Running Two Versions of Python on the Same PC
In-Reply-To: <48F0A1A3.7010706@sbcglobal.net>
References: <48F0A1A3.7010706@sbcglobal.net>
Message-ID: <1c2a2c590810110721k45ec3eb6hac4b303ed16a3dc@mail.gmail.com>

On Sat, Oct 11, 2008 at 8:52 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Is it possible to do as in Subject on Win XP? Say, 2.4 and 2.5.

Yes, different 2.x versions of Python will peacefully coexist.
virtualenv is useful for setting up separate working environments but
it is not needed if you just want to have multiple Python installs.

Kent

From sierra_mtnview at sbcglobal.net  Sat Oct 11 16:53:22 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 07:53:22 -0700
Subject: [Tutor] Tuple of Tuples
Message-ID: <48F0BDE2.2060500@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/ae94aafd/attachment.htm>

From srilyk at gmail.com  Sat Oct 11 17:12:43 2008
From: srilyk at gmail.com (W W)
Date: Sat, 11 Oct 2008 10:12:43 -0500
Subject: [Tutor] Tuple of Tuples
In-Reply-To: <48F0BDE2.2060500@sbcglobal.net>
References: <48F0BDE2.2060500@sbcglobal.net>
Message-ID: <333efb450810110812h39f4ca1ar75c2424769bfe80d@mail.gmail.com>

On Sat, Oct 11, 2008 at 9:53 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> I would like to create a tuple of tuples. As I read (x,y) pairs I would like
> to "add" them to others. In the example below, I seem to be picking up ()
> each time I augment the tuple t.
> ===============
>>>> t = ()
>>>> t = t,(0,1)
>>>> t
> ((), (0, 1))
>>>> t,(2,3)
> (((), (0, 1)), (2, 3))
> ================
> Why the repeats of ()?
>
> Maybe I need to use another type? Lists?

Unless you want the tuple to never change, then yes. Tuples are
immutable (you can't change them):

>>> t = (0,2)
>>> t[0] = 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

What you're doing with this line
>>> t = t,(0,1)
Is the exact same as writing
t = ((), (0,1))

because you're creating a tuple with () and (0,1). Then your next
assignment does something similar:

t = t, (0,5)
is the same as writing
t = ((), (0,1)), (0,5)

A list of tuples would probably be the better way to go.
HTH,
Wayne

From sierra_mtnview at sbcglobal.net  Sat Oct 11 18:28:46 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 09:28:46 -0700
Subject: [Tutor] Critiquing My Program
Message-ID: <48F0D43E.4060007@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/17a14781/attachment-0001.htm>

From kent37 at tds.net  Sat Oct 11 20:47:48 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 11 Oct 2008 14:47:48 -0400
Subject: [Tutor] Critiquing My Program
In-Reply-To: <48F0D43E.4060007@sbcglobal.net>
References: <48F0D43E.4060007@sbcglobal.net>
Message-ID: <1c2a2c590810111147jff8c0ceyd3d10ad7b96ade6f@mail.gmail.com>

On Sat, Oct 11, 2008 at 12:28 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:

> Perhaps at the top of my list is the use of self. I sure get tired of using
> it. Maybe there's a short cut.

No, no short cut. You can use a different name than 'self', for
example 's', but I don't recommend it; 'self' is pretty universal in
Python.

It's possible you are over-using attributes; values which are only
used in a single method don't have to be attributes.

> Although I've organized the file data into
> records, I still find subscripting fields and data a bit unpleasing. For
> example, I used a list of tuples, but I'd list to represent items by names
> rather than indicies to enhance readability.

Python 2.6 adds a namedtuple function which is useful for this:
http://docs.python.org/library/collections.html#collections.namedtuple

For older versions the Bunch class is handy:
http://code.activestate.com/recipes/52308/

> If anyone wants to critique what I have, just ask for a copy.

You could post it to http://pastebin.com/

Kent

From sierra_mtnview at sbcglobal.net  Sun Oct 12 04:52:22 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 19:52:22 -0700
Subject: [Tutor] Critiquing My Program
In-Reply-To: <1c2a2c590810111359k42aae6a2gd1d73468be40d7fd@mail.gmail.com>
References: <48F0D43E.4060007@sbcglobal.net>	
	<1c2a2c590810111147jff8c0ceyd3d10ad7b96ade6f@mail.gmail.com>	
	<48F1075B.8090408@sbcglobal.net>
	<1c2a2c590810111359k42aae6a2gd1d73468be40d7fd@mail.gmail.com>
Message-ID: <48F16666.4030900@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/1fe8e437/attachment.htm>

From sierra_mtnview at sbcglobal.net  Sun Oct 12 04:54:05 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 19:54:05 -0700
Subject: [Tutor] Critiquing My Program
In-Reply-To: <1c2a2c590810111147jff8c0ceyd3d10ad7b96ade6f@mail.gmail.com>
References: <48F0D43E.4060007@sbcglobal.net>
	<1c2a2c590810111147jff8c0ceyd3d10ad7b96ade6f@mail.gmail.com>
Message-ID: <48F166CD.2060704@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/68ac2cc8/attachment.htm>

From sierra_mtnview at sbcglobal.net  Sun Oct 12 06:23:23 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sat, 11 Oct 2008 21:23:23 -0700
Subject: [Tutor] pylab Failure
Message-ID: <48F17BBB.4010005@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/5392bd09/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: moz-screenshot-93.jpg
Type: image/jpeg
Size: 11466 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20081011/5392bd09/attachment-0001.jpg>

From alan.gauld at btinternet.com  Sun Oct 12 08:21:24 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 12 Oct 2008 07:21:24 +0100
Subject: [Tutor] pylab Failure
References: <48F17BBB.4010005@sbcglobal.net>
Message-ID: <gcs511$jpg$1@ger.gmane.org>


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote
> Here's the code.
> If I just execute it, the terminal window opens briefly and 
> disappears.

What happens if you execute it from a terminal window?
That way any error messages will be visible.

What happens if you ruin it from inside IDLE or Pythonwin?

THe fact that you have a raw_input means the code should pause
at that point, if it isn't it probably suiggets a syntax error or 
similar
in the code before that point...

> from pylab import *
>
> def finish():
>    print; print "Bye"
>    print
>    raw_input('Press Enter to Quit')
>    sys.exit()
>
> t = arange(0.0, 2.0, 0.01)
> s = sin(2*pi*t)
> plot(t, s, linewidth=1.0)
>
> xlabel('time (s)')
> ylabel('voltage (mV)')
> title('About as simple as it gets, folks')
> grid(True)
> show()
> finish()

HTH,


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



From sierra_mtnview at sbcglobal.net  Sun Oct 12 13:56:56 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sun, 12 Oct 2008 04:56:56 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <gcs511$jpg$1@ger.gmane.org>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>
Message-ID: <48F1E608.8020109@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081012/07b1f416/attachment.htm>

From jmorcombe at westnet.com.au  Sun Oct 12 13:56:06 2008
From: jmorcombe at westnet.com.au (Jim Morcombe)
Date: Sun, 12 Oct 2008 19:56:06 +0800
Subject: [Tutor] Finding the IP address for your own PC
Message-ID: <48F1E5D6.9090202@westnet.com.au>

Hopefully this is an easy one.

How do you get the IP address of the Windows PC that your Python program 
is running on?

Jim Morcombe





From kent37 at tds.net  Sun Oct 12 14:41:42 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 12 Oct 2008 08:41:42 -0400
Subject: [Tutor] Critiquing My Program
In-Reply-To: <48F16666.4030900@sbcglobal.net>
References: <48F0D43E.4060007@sbcglobal.net>
	<1c2a2c590810111147jff8c0ceyd3d10ad7b96ade6f@mail.gmail.com>
	<48F1075B.8090408@sbcglobal.net>
	<1c2a2c590810111359k42aae6a2gd1d73468be40d7fd@mail.gmail.com>
	<48F16666.4030900@sbcglobal.net>
Message-ID: <1c2a2c590810120541x7f4dfees7b96ddad608393df@mail.gmail.com>

On Sat, Oct 11, 2008 at 10:52 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Here's where the code resides <http://pastebin.com/mb02edf4>

OK, some comments:
- Track_data.get_data() should just be part of Track_data.__init__(),
there is no need for it to be separate and the Track_data is not
usable until get_data() is called.

- You asked about named attributes; Track_data instances themselves
have named attributes. Instead of returning the data as a list, use
the Track_data directly. Assuming you remove get_data() as suggested
above, you would use Track_data like this:
            line_data = Track_data(line)
            stats.sum(fields.amplitude, fields.cntrd_x, fields.cntrd_y)

You could also pass the Track_data instance directly to the Stats methods.

- Similarly, Stats.sum need not return a list, and Stats.get_sums() is
not needed; just access the Stats attributes directly.

- You could combine Stats.sum() and stats.collection() into one method.
- Stats.n_frames is redundant, it is the same as len(stats.xya)
- You could use glob.glob('v2*.txt') instead of os.listdir()

-     if (file[-3:] == 'txt') & (file[0:2] == "v2"):
Should be 'and' instead of '&'

Kent

From sierra_mtnview at sbcglobal.net  Sun Oct 12 14:51:06 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sun, 12 Oct 2008 05:51:06 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <48F1E608.8020109@sbcglobal.net>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>
	<48F1E608.8020109@sbcglobal.net>
Message-ID: <48F1F2BA.7010106@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081012/4d450f30/attachment.htm>

From kent37 at tds.net  Sun Oct 12 15:17:49 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 12 Oct 2008 09:17:49 -0400
Subject: [Tutor] pylab Failure
In-Reply-To: <48F1E608.8020109@sbcglobal.net>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>
	<48F1E608.8020109@sbcglobal.net>
Message-ID: <1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>

On Sun, Oct 12, 2008 at 7:56 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> The terminal window flashed briefly, and apparently never got to the
> finish() def, which should keep the window open, but long enough to see
> there's nothing in it. The program came directly from the MatPlotLib web
> page. Another one died in a similar way. I put finish() after the plot line
> and it died the same way. Same if I put it before plot. Same before arrange.
> Dies same way with only the import line. There must be something wrong with
> the matplot module install?

When Alan says to run the program from a terminal window, he means,
- open terminal
- type the command to run your program - something like
> C:\Python24\python \path\to\myprogram.py

This is different from just double-clicking the program, the terminal
window will stay open.

You could also open a terminal window and just run Python, then type
or paste the pylab commands into the interpreter. I.e., run terminal,
then type
> \Python24\python
>>> from pylab import *

etc.

IIUC it is a bad idea to run a Tkinter program from IDLE, it can get a
bit confused. That may be the reason for your original error.

Kent

From kent37 at tds.net  Sun Oct 12 15:21:49 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 12 Oct 2008 09:21:49 -0400
Subject: [Tutor] Finding the IP address for your own PC
In-Reply-To: <48F1E5D6.9090202@westnet.com.au>
References: <48F1E5D6.9090202@westnet.com.au>
Message-ID: <1c2a2c590810120621h7b036c42y99ba22ba90b8b454@mail.gmail.com>

On Sun, Oct 12, 2008 at 7:56 AM, Jim Morcombe <jmorcombe at westnet.com.au> wrote:
> Hopefully this is an easy one.
>
> How do you get the IP address of the Windows PC that your Python program is
> running on?

See the comments to this recipe for a couple of suggestions:
http://code.activestate.com/recipes/439094/

Kent

From sierra_mtnview at sbcglobal.net  Mon Oct 13 02:34:23 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sun, 12 Oct 2008 17:34:23 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>	
	<48F1E608.8020109@sbcglobal.net>
	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>
Message-ID: <48F2978F.2020603@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081012/2d1b3d69/attachment.htm>

From sierra_mtnview at sbcglobal.net  Mon Oct 13 02:46:33 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sun, 12 Oct 2008 17:46:33 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <48F2978F.2020603@sbcglobal.net>
References: <48F17BBB.4010005@sbcglobal.net>
	<gcs511$jpg$1@ger.gmane.org>		<48F1E608.8020109@sbcglobal.net>	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>
	<48F2978F.2020603@sbcglobal.net>
Message-ID: <48F29A69.7030203@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081012/75d926ce/attachment-0001.htm>

From kent37 at tds.net  Mon Oct 13 02:48:22 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 12 Oct 2008 20:48:22 -0400
Subject: [Tutor] pylab Failure
In-Reply-To: <48F2978F.2020603@sbcglobal.net>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>
	<48F1E608.8020109@sbcglobal.net>
	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>
	<48F2978F.2020603@sbcglobal.net>
Message-ID: <1c2a2c590810121748m4e1bba90nb860d764b1d484d6@mail.gmail.com>

On Sun, Oct 12, 2008 at 8:34 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> What's more likely run python/Tkinter with graphics than IDLE?

See my previous suggestions.

> I'm looking at py2exe right now, but that seems useful for a completed
> program. On that topic, I noticed that my Start->All Progs menu item now,
> possibly it was there before I installed p2exe, a Python2.4 item show a
> Command Line sub-item.

OK, choosing that will open a Python interpreter with a >>> prompt.
What happens if you type
import pylab
at the prompt? Please try that and copy and paste the results to an email.

> I've finally figured out to use the Start->Run to get at the python program.
> I just tried a slight variation on:
>
> C:\Python24\python \path\to\myprogram.py gets nowhere.

What happens when you try it? Please be specific. "gets nowhere"
doesn't tell me much.

> I copied the program int c:\pytho24. I don't seem to be able to copy the
> window, so I see pretty much what I had before, except it adds:
> Fatal Pyton error: Pystring_InterInPlace: strings only please! The rest is
> about the run time error.

Details, please.

You seem to be struggling with some fundamentals of the command line
and running programs. This might help:
http://www.python.org/doc/faq/windows/#how-do-i-run-a-python-program-under-windows

Kent

From sierra_mtnview at sbcglobal.net  Mon Oct 13 04:18:35 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Sun, 12 Oct 2008 19:18:35 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <1c2a2c590810121748m4e1bba90nb860d764b1d484d6@mail.gmail.com>
References: <48F17BBB.4010005@sbcglobal.net> <gcs511$jpg$1@ger.gmane.org>	
	<48F1E608.8020109@sbcglobal.net>	
	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>	
	<48F2978F.2020603@sbcglobal.net>
	<1c2a2c590810121748m4e1bba90nb860d764b1d484d6@mail.gmail.com>
Message-ID: <48F2AFFB.70200@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081012/22e92130/attachment.htm>

From alan.gauld at btinternet.com  Mon Oct 13 09:45:42 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 13 Oct 2008 08:45:42 +0100
Subject: [Tutor] pylab Failure
References: <48F17BBB.4010005@sbcglobal.net>
	<gcs511$jpg$1@ger.gmane.org>	<48F1E608.8020109@sbcglobal.net>	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>	<48F2978F.2020603@sbcglobal.net><1c2a2c590810121748m4e1bba90nb860d764b1d484d6@mail.gmail.com>
	<48F2AFFB.70200@sbcglobal.net>
Message-ID: <gcuub5$e2i$1@ger.gmane.org>

"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

> Yes (below), command lines are surprisingly baffling.
> I've used the Win Run cmd lines before, but once one gets
> into using them like DOS, it's a bit weird.

For this kind of thing you want to eliminate as many
variables as posssible so its best to just start up a
basic CMD window with a DOS prompt and run the
program by hand.

To do that start a new DOS session via Start->Run CMD.

Then:
- use CD to navigate to the folder with your script.

- Run

C:\MyFolder> python myscript.py

That should show any error messages.

- To copy and paste the content of the window go to the
CMD icon at the top left corner and click on it.

- Select the Edit->Mark menu item and use the mouse
to highlight the error text.

- Then Select Edit->Copy to copy it to the clipboard

- Paste it into an email as usual and send to the list.

> Apparently, command line operation means something
> a bit different in python

There are two separate concepts:
1) The OS command line - thats the "DOS prompt"
2) The Python commandline - thats the >>> python
interpreter prompt

Most IDEs provide a simulation of the python command
prompt but it will behave slightly differently - usually
with added extras. Thats why its best when debugging
strange errors to go back to the vanilla python interpreter
since thats the one that will ultimately run your code
when you double click in Explorer etc.

There are a lot of tweaks that you can do to the XP/Vista
CMD prompt to make it more user friendly (command history,
completion, enhanced editing, cut n paste etc etc) But
they can wait till later.

>  bookmarked. I changed the misleading title (Windows FAQ) so that I 
> can find it later.

The title is OK - it's the FAQ for Python windows users.
This is one of the FAQs... :-)

HTH,

Alan G. 



From sierra_mtnview at sbcglobal.net  Mon Oct 13 13:19:45 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Mon, 13 Oct 2008 04:19:45 -0700
Subject: [Tutor] pylab Failure
In-Reply-To: <gcuub5$e2i$1@ger.gmane.org>
References: <48F17BBB.4010005@sbcglobal.net>	<gcs511$jpg$1@ger.gmane.org>	<48F1E608.8020109@sbcglobal.net>	<1c2a2c590810120617n51035318se66ca986b3e4d72a@mail.gmail.com>	<48F2978F.2020603@sbcglobal.net><1c2a2c590810121748m4e1bba90nb860d764b1d484d6@mail.gmail.com>	<48F2AFFB.70200@sbcglobal.net>
	<gcuub5$e2i$1@ger.gmane.org>
Message-ID: <48F32ED1.4000906@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081013/600d8744/attachment.htm>

From burmantanya at yahoo.ca  Mon Oct 13 19:52:40 2008
From: burmantanya at yahoo.ca (burmantanya at yahoo.ca)
Date: Mon, 13 Oct 2008 10:52:40 -0700 (PDT)
Subject: [Tutor] Python Basic Help
Message-ID: <978638.50624.qm@web65608.mail.ac4.yahoo.com>

Hey 

My name is Tanya and i am?new to python programmin. I have few questions which hopefully will clear my doubts.

	* First question, we are given a list
L = [ 345 , 32525 , 525 , 53245 , 6536 ]
how would i add them? like in this form - 3+4+5+3+2+5+.....
?
	* 2nd Question, we are givin a list
L = [-----++++--+--329234]
how would i tell python to use algebra basics here???
?
	* 3rd Question
how do we assign alphabets to numbers
for example - if we divide 200 by 16, we get quotient as 12 and remainder as 8.?12 equals to?C. so the answer should?display C8
?
Thank you. Your help would be really appreciated!
Thanks?once again for taking out your time to read it..
?
Tanya?


      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at
http://ca.toolbar.yahoo.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081013/68b77504/attachment.htm>

From rabidpoobear at gmail.com  Mon Oct 13 20:25:22 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 13 Oct 2008 13:25:22 -0500
Subject: [Tutor] Python Basic Help
In-Reply-To: <978638.50624.qm@web65608.mail.ac4.yahoo.com>
References: <978638.50624.qm@web65608.mail.ac4.yahoo.com>
Message-ID: <dfeb4470810131125p4ba5d38cl9176051893b8e8f0@mail.gmail.com>

smells like homework.

On Mon, Oct 13, 2008 at 12:52 PM, burmantanya at yahoo.ca
<burmantanya at yahoo.ca> wrote:
> Hey
>
> My name is Tanya and i am new to python programmin. I have few questions
> which hopefully will clear my doubts.
>
>
> First question, we are given a list
>
> L = [ 345 , 32525 , 525 , 53245 , 6536 ]
>
> how would i add them? like in this form - 3+4+5+3+2+5+.....
>
>
>
> 2nd Question, we are givin a list
>
> L = [-----++++--+--329234]
>
> how would i tell python to use algebra basics here???
>
>
>
> 3rd Question
>
> how do we assign alphabets to numbers
>
> for example - if we divide 200 by 16, we get quotient as 12 and remainder as
> 8. 12 equals to C. so the answer should display C8
>
>
>
> Thank you. Your help would be really appreciated!
>
> Thanks once again for taking out your time to read it..
>
>
>
> Tanya
>
> ________________________________
> Looking for the perfect gift? Give the gift of Flickr!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From srilyk at gmail.com  Mon Oct 13 20:49:33 2008
From: srilyk at gmail.com (W W)
Date: Mon, 13 Oct 2008 13:49:33 -0500
Subject: [Tutor] Python Basic Help
In-Reply-To: <dfeb4470810131125p4ba5d38cl9176051893b8e8f0@mail.gmail.com>
References: <978638.50624.qm@web65608.mail.ac4.yahoo.com>
	<dfeb4470810131125p4ba5d38cl9176051893b8e8f0@mail.gmail.com>
Message-ID: <333efb450810131149v3699944eh562c57276c1b01a2@mail.gmail.com>

What do you know so far? Do you know how to create a list or loop over the
values inside a list?
Try showing us what you've done so far and where you're stuck, then you'll
get plenty of pointers. If you're just doing this on your own and not
homework, you're probably starting on something a little too advanced. If
this is homework, the point of homework is to learn how to do it on your own
(that's the point of some online assignment as well, but you don't get
graded on that ;) )

HTH,
Wayne

On Mon, Oct 13, 2008 at 1:25 PM, Luke Paireepinart
<rabidpoobear at gmail.com>wrote:

> smells like homework.
>
> On Mon, Oct 13, 2008 at 12:52 PM, burmantanya at yahoo.ca
> <burmantanya at yahoo.ca> wrote:
> > Hey
> >
> > My name is Tanya and i am new to python programmin. I have few questions
> > which hopefully will clear my doubts.
> >
> >
> > First question, we are given a list
> >
> > L = [ 345 , 32525 , 525 , 53245 , 6536 ]
> >
> > how would i add them? like in this form - 3+4+5+3+2+5+.....
> >
> >
> >
> > 2nd Question, we are givin a list
> >
> > L = [-----++++--+--329234]
> >
> > how would i tell python to use algebra basics here???
> >
> >
> >
> > 3rd Question
> >
> > how do we assign alphabets to numbers
> >
> > for example - if we divide 200 by 16, we get quotient as 12 and remainder
> as
> > 8. 12 equals to C. so the answer should display C8
> >
> >
> >
> > Thank you. Your help would be really appreciated!
> >
> > Thanks once again for taking out your time to read it..
> >
> >
> >
> > Tanya
> >
> > ________________________________
> > Looking for the perfect gift? Give the gift of Flickr!
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081013/40f118f9/attachment.htm>

From dkuhlman at rexx.com  Mon Oct 13 20:28:53 2008
From: dkuhlman at rexx.com (Dave Kuhlman)
Date: Mon, 13 Oct 2008 11:28:53 -0700
Subject: [Tutor] Python Working Environment, Checkout, Compare (diff),
	...
In-Reply-To: <1c2a2c590810092109x4ce940bdsa60839d3fafd9067@mail.gmail.com>
References: <48EE2B63.4020000@sbcglobal.net> <gcln45$jrc$1@ger.gmane.org>
	<48EE9830.9090001@sbcglobal.net>
	<1c2a2c590810092109x4ce940bdsa60839d3fafd9067@mail.gmail.com>
Message-ID: <20081013182853.GA94148@cutter.rexx.com>

On Fri, Oct 10, 2008 at 12:09:16AM -0400, Kent Johnson wrote:
> On Thu, Oct 9, 2008 at 7:48 PM, Wayne Watson
> <sierra_mtnview at sbcglobal.net> wrote:
> > Well, maybe I'll give Cygwin a go again. I tried it 2-3 years ago and it was
> > troublesome. I'd really like to have Unix/Linux available, so maybe. I
> > really don't use Linux any longer, but it does have some very good features
> > like diff than can be helpful even in a Win env.
> 
> Many of the GNU tools - including diff - are available for native
> Windows (not Cygwin) from the GnuWin32 project:
> http://gnuwin32.sourceforge.net/packages.html
> 

Also look here:

    http://unxutils.sourceforge.net/

    "Here are some ports of common GNU utilities to native Win32. In
    this context, native means the executables do only depend on the
    Microsoft C-runtime (msvcrt.dll) and not an emulation layer like
    that provided by Cygwin tools."

- Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman

From srilyk at gmail.com  Tue Oct 14 01:23:57 2008
From: srilyk at gmail.com (W W)
Date: Mon, 13 Oct 2008 18:23:57 -0500
Subject: [Tutor] Python Basic Help
In-Reply-To: <260523.96954.qm@web65601.mail.ac4.yahoo.com>
References: <260523.96954.qm@web65601.mail.ac4.yahoo.com>
Message-ID: <333efb450810131623l46ceeba6v1c982fc3b6e8d629@mail.gmail.com>

If you hit reply to all, you'll send your response to the list, too.

On Mon, Oct 13, 2008 at 2:05 PM, burmantanya at yahoo.ca
<burmantanya at yahoo.ca>wrote:

> <snip>
> i am getting tons of error messages for the last one!!! i was wondering if
> we could use if loop inside another if loop
>

Yes, you can use loops inside other loops.

If you're getting errors, post the exact error message you get, for instance
when I type this:

In [29]: import zanzubar

I get this error:
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

C:\Documents and Settings\wayne\My Documents\mathbook\<ipython console> in
<module>()

ImportError: No module named zanzubar

(I'm using IPython, so your error will be formatted a little different)
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081013/94d5c432/attachment-0001.htm>

From phpfood at gmail.com  Tue Oct 14 03:53:37 2008
From: phpfood at gmail.com (phpfood)
Date: Mon, 13 Oct 2008 21:53:37 -0400
Subject: [Tutor] Python Basic Help
In-Reply-To: <333efb450810131623l46ceeba6v1c982fc3b6e8d629@mail.gmail.com>
References: <260523.96954.qm@web65601.mail.ac4.yahoo.com>
	<333efb450810131623l46ceeba6v1c982fc3b6e8d629@mail.gmail.com>
Message-ID: <df531c470810131853i1d9d13b8mee679ad12adfecc3@mail.gmail.com>

on turning numbers into letters:
you can first do the arithmetic with python, then:
you can convert the integer or double value to a string: str(answer)
and then parse through each number value in the string and replace it with
letters for the ones you choose....
On Mon, Oct 13, 2008 at 7:23 PM, W W <srilyk at gmail.com> wrote:

> If you hit reply to all, you'll send your response to the list, too.
>
> On Mon, Oct 13, 2008 at 2:05 PM, burmantanya at yahoo.ca <
> burmantanya at yahoo.ca> wrote:
>
>> <snip>
>> i am getting tons of error messages for the last one!!! i was wondering
>> if we could use if loop inside another if loop
>>
>
> Yes, you can use loops inside other loops.
>
> If you're getting errors, post the exact error message you get, for
> instance when I type this:
>
> In [29]: import zanzubar
>
> I get this error:
> ---------------------------------------------------------------------------
> ImportError                               Traceback (most recent call last)
>
> C:\Documents and Settings\wayne\My Documents\mathbook\<ipython console> in
> <module>()
>
> ImportError: No module named zanzubar
>
> (I'm using IPython, so your error will be formatted a little different)
> HTH,
> Wayne
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081013/fc085048/attachment.htm>

From srilyk at gmail.com  Tue Oct 14 15:13:55 2008
From: srilyk at gmail.com (W W)
Date: Tue, 14 Oct 2008 08:13:55 -0500
Subject: [Tutor] Technical aspect of os.path.isfile()
Message-ID: <333efb450810140613l6566941fk38e6cef3b02ff052@mail.gmail.com>

I suppose this is really more of a technical aspect, dealing with the
possibility of a race condition (although in my personal case, the
probability is infinitely small).

I'm writing a program that uses the ConfigParser module to open a config
file, and if that file isn't present, I'd like to create it. I'll also be
syncing a series of files from one directory to another. I'll be creating a
list of files in each dir using os.walk, and copying the files that aren't
present in the destination dir.

 After looking online I've found various opinions on what the "best" way is
to deal with the possibility of a race condition. The way I intend to use my
program, a race condition should never occur, but if I ever release the
source, I'd like it to at least fail gracefully.

Is there a solid way to prevent a race condition, or is it just sort of a
"do your best" type situation?

Thanks,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/3c00aa46/attachment.htm>

From ulandreman at msn.com  Tue Oct 14 16:04:01 2008
From: ulandreman at msn.com (URBAN LANDREMAN)
Date: Tue, 14 Oct 2008 09:04:01 -0500
Subject: [Tutor] Edit a Word document programmatically
Message-ID: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>

Good morning,

I'm trying to write some Python code to programmatically do a Find and Replace of a string within a Microsoft Word document.
Any suggestions on where I could look to find how to do such a function?

Thank you.

Urban Landreman


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/ae1e20f4/attachment.htm>

From rabidpoobear at gmail.com  Tue Oct 14 16:11:13 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 14 Oct 2008 09:11:13 -0500
Subject: [Tutor] Fwd:  Technical aspect of os.path.isfile()
In-Reply-To: <dfeb4470810140710s1fe0b4e8ye24d92fdde6d97cd@mail.gmail.com>
References: <333efb450810140613l6566941fk38e6cef3b02ff052@mail.gmail.com>
	<dfeb4470810140710s1fe0b4e8ye24d92fdde6d97cd@mail.gmail.com>
Message-ID: <dfeb4470810140711x7b44f3e5xd20fa9e878b5b342@mail.gmail.com>

Oops, replied off-list accidentally.


---------- Forwarded message ----------
From: Luke Paireepinart <rabidpoobear at gmail.com>
Date: Tue, Oct 14, 2008 at 9:10 AM
Subject: Re: [Tutor] Technical aspect of os.path.isfile()
To: W W <srilyk at gmail.com>


File renames are much faster than file copies.  So just copy the files
with an extra extension, and then when they're done copying, rename
them.  I believe that this prevents a race condition because the file
is not being exclusively accessed by the rename function.
As far as dealing with it, if you really think it's an issue, you can
always do interprocess communciation to allow them to keep up with the
current state of the other.  If that's not viable there are probably
alternatives.

On Tue, Oct 14, 2008 at 8:13 AM, W W <srilyk at gmail.com> wrote:
> I suppose this is really more of a technical aspect, dealing with the
> possibility of a race condition (although in my personal case, the
> probability is infinitely small).
>
> I'm writing a program that uses the ConfigParser module to open a config
> file, and if that file isn't present, I'd like to create it. I'll also be
> syncing a series of files from one directory to another. I'll be creating a
> list of files in each dir using os.walk, and copying the files that aren't
> present in the destination dir.
>
>  After looking online I've found various opinions on what the "best" way is
> to deal with the possibility of a race condition. The way I intend to use my
> program, a race condition should never occur, but if I ever release the
> source, I'd like it to at least fail gracefully.
>
> Is there a solid way to prevent a race condition, or is it just sort of a
> "do your best" type situation?
>
> Thanks,
> Wayne
>
> --
> To be considered stupid and to be told so is more painful than being called
> gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
> every vice, has found its defenders, its rhetoric, its ennoblement and
> exaltation, but stupidity hasn't. - Primo Levi
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From bcl at brianlane.com  Tue Oct 14 16:22:56 2008
From: bcl at brianlane.com (Brian C. Lane)
Date: Tue, 14 Oct 2008 07:22:56 -0700
Subject: [Tutor] Edit a Word document programmatically
In-Reply-To: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
Message-ID: <48F4AB40.2050805@brianlane.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

URBAN LANDREMAN wrote:
> Good morning,
> 
> I'm trying to write some Python code to programmatically do a Find and
> Replace of a string within a Microsoft Word document.
> Any suggestions on where I could look to find how to do such a function?
> 

Take a look at the win32com module. Here's a chapter on it from O'Reilly

http://oreilly.com/catalog/pythonwin32/chapter/ch12.html#49339

Brian

- --
- ---[Office 70.5F]--[Outside 46.5F]--[Server 104.9F]--[Coaster 71.0F]---
- ---[       WSF KITSAP (366772980) @ 47 34.7811 -122 27.7554       ]---
Software, Linux, Microcontrollers             http://www.brianlane.com
AIS Parser SDK                                http://www.aisparser.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFI9KtAIftj/pcSws0RAk9EAJ4/Dysv4TfAdyo+g5t2QLwvLMQR4gCfZ5l0
ic/hQOAv4psFxKN2ErMpEDQ=
=8tz8
-----END PGP SIGNATURE-----

From bgailer at gmail.com  Tue Oct 14 17:30:08 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 14 Oct 2008 11:30:08 -0400
Subject: [Tutor] Edit a Word document programmatically
In-Reply-To: <48F4AB40.2050805@brianlane.com>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
	<48F4AB40.2050805@brianlane.com>
Message-ID: <48F4BB00.3030708@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/aed6d64b/attachment.htm>

From bgailer at gmail.com  Tue Oct 14 17:32:03 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 14 Oct 2008 11:32:03 -0400
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
 not open
In-Reply-To: <48F4BB00.3030708@gmail.com>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>	<48F4AB40.2050805@brianlane.com>
	<48F4BB00.3030708@gmail.com>
Message-ID: <48F4BB73.6010501@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/36e4546e/attachment.htm>

From heinrich.massmann at ukonline.co.uk  Tue Oct 14 17:43:51 2008
From: heinrich.massmann at ukonline.co.uk (heinrich.massmann at ukonline.co.uk)
Date: Tue, 14 Oct 2008 16:43:51 +0100
Subject: [Tutor] twill module
In-Reply-To: <333efb450810140613l6566941fk38e6cef3b02ff052@mail.gmail.com>
References: <333efb450810140613l6566941fk38e6cef3b02ff052@mail.gmail.com>
Message-ID: <1223999031.48f4be370cd81@webmail.ukonline.net>

Hi all,

I'm new to this list (and python ;-)) and working on a small personal project. 

I'm basically using the twill to browse a website (weather reports) and do a re
search for a specific string that once found, needs to be printed in a web page
on it's own. The problem I found with twill is that it also prints the html that
comes along with it. (Apparently it's a known "functionality")

The way around this was for me to write my regexp find to another file and then
display that in another cgi script, surely there must be a cleaner way of doing
it? Also, any idea how I can call the second script from the first after the
first one is finished?


Any ideas appreciated. Code below.( No laughing please!)

Cheers

Heinrich



import cgitb; cgitb.enable()  # only for temp debugging
import re
import cgi
from twill.commands import *



url = "http://secure.metoffice.com/logon.jsp"
go(url)
fv(1, 'username', 'xxxxxxxx')
fv(1, 'password', 'xxxxxxxx')
submit()

go('/aviation/index.jsp')
go('report.jsp')
go('reports.do?type=METAR&list=02')
report = show()
result = re.search("EGKB.*</td>",report)
result = re.sub("</td>", "", result.group())

file = open('/var/www/cgi-bin/results.txt', 'w')
print >>file, result 
file.flush()


And then my second script runs this to display the one liner:

import cgi
import cgitb; cgitb.enable() # again only for temp debugging.

def dispmetar():
        f = open('results.txt', 'r')
        data = f.readlines()

        print 'Content-Type: text/html'
        print 

        for line in data:
                print "<u>METAR</u>: " + line

dispmetar()

Just playing around with creating my own functions as you can tell...

----------------------------------------------
This mail sent through http://www.ukonline.net

From ulandreman at msn.com  Tue Oct 14 18:23:59 2008
From: ulandreman at msn.com (URBAN LANDREMAN)
Date: Tue, 14 Oct 2008 11:23:59 -0500
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
 not open
In-Reply-To: <48F4BB73.6010501@gmail.com>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
	<48F4AB40.2050805@brianlane.com>	<48F4BB00.3030708@gmail.com> 
	<48F4BB73.6010501@gmail.com>
Message-ID: <BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl>

Thanks for the suggestion.

When I ran the slightly modified code:
import win32com.client
app = win32com.client.Dispatch('Word.Application')
docOrig = app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
range = docOrig.Content()
range.Find.Text = "e"
range.Find.Replacement.Text = "*"
range.Find.Execute()
docEditted = doc
docEditted.SaveAs('n:\\MetroPlanners\\2006\\MCHResearchProjectV2.doc')
app.Quit()


I got:

Traceback (most recent call last):
  File "N:/SPSS/Python/Examples/MSWord/WordFindAndReplaceV2", line 5, in <module>
    range.Find.Text = "e"
AttributeError: 'unicode' object has no attribute 'Find'

For what it's worth, I'm running Python 2.5.2

Urban

Date: Tue, 14 Oct 2008 11:32:03 -0400
From: bgailer at gmail.com
To: bcl at brianlane.com
CC: tutor at python.org
Subject: Re: [Tutor] Edit a Word document programmatically CORRECTION Open not open






  


bob gailer wrote:

  
Brian C. Lane wrote:
  
    -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

URBAN LANDREMAN wrote:
  
    
      Good morning,

I'm trying to write some Python code to programmatically do a Find and
Replace of a string within a Microsoft Word document.
Any suggestions on where I could look to find how to do such a function?

    
    
    Take a look at the win32com module. Here's a chapter on it from O'Reilly

http://oreilly.com/catalog/pythonwin32/chapter/ch12.html#49339
  
  
  

That chapter does not really address your question in a simple and
helpful way. Chapter 10 does. Not available online

  

You need some way to run Word from Python and then tell it what to do.

  

pywin32 gives you the tools to run Word. Download it from
  http://sourceforge.net/project/showfiles.php?group_id=78018.

  

import win32com.client

word = win32com.dispatch('word.application')

  

Now you have a COM connection to Word and can invoke the equivalent of
Visual Basic for Applications to manipulate the Word Document Object
Model. O'Reilly Learning Word Programming gives all the gory details.
Unfortunately for me I don't have Word installed at the moment so I
can't give you tested code.

  

doc = word.Documents.Open("c:\\test.doc") # provide path to your
document instead,

range = doc.Content()

range.Find.Text = "text to replace"

range.Find.Replacement.Text = "replacement text"

range.Find.Execute()

doc.Save()

  

Give that a try. Let me know what happens. Reply to the list not just
me.

  

  -- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?
  
  
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
  





-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/8c8880ce/attachment.htm>

From marc.tompkins at gmail.com  Tue Oct 14 19:07:30 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Tue, 14 Oct 2008 10:07:30 -0700
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
	not open
In-Reply-To: <BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
	<48F4AB40.2050805@brianlane.com> <48F4BB00.3030708@gmail.com>
	<48F4BB73.6010501@gmail.com>
	<BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl>
Message-ID: <40af687b0810141007h3c30e474tbb7cfc53a1c897f2@mail.gmail.com>

On Tue, Oct 14, 2008 at 9:23 AM, URBAN LANDREMAN <ulandreman at msn.com> wrote:

> Thanks for the suggestion.
>
> When I ran the slightly modified code:
> import win32com.client
> app = win32com.client.Dispatch('Word.Application')
> docOrig =
> app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
> range = docOrig.Content()
> range.Find.Text = "e"
> range.Find.Replacement.Text = "*"
> range.Find.Execute()
> docEditted = doc
> docEditted.SaveAs('n:\\MetroPlanners\\2006\\MCHResearchProjectV2.doc')
> app.Quit()
>
>
> I got:
>
> Traceback (most recent call last):
>   File "N:/SPSS/Python/Examples/MSWord/WordFindAndReplaceV2", line 5, in
> <module>
>     range.Find.Text = "e"
> AttributeError: 'unicode' object has no attribute 'Find'
>

docOrig.Content() returns you a Unicode object, which isn't the same as a
Word document at all.  You're then trying to use methods on that object
which aren't supported.  I can't give you specifics without doing a bit of
Googling myself, but you probably want a different call on line 4 to give
you an object you can work with.


-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/bfe820a5/attachment.htm>

From bgailer at gmail.com  Tue Oct 14 20:42:21 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 14 Oct 2008 14:42:21 -0400
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
 not open
In-Reply-To: <40af687b0810141007h3c30e474tbb7cfc53a1c897f2@mail.gmail.com>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>	<48F4AB40.2050805@brianlane.com>
	<48F4BB00.3030708@gmail.com>	<48F4BB73.6010501@gmail.com>	<BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl>
	<40af687b0810141007h3c30e474tbb7cfc53a1c897f2@mail.gmail.com>
Message-ID: <48F4E80D.4010606@gmail.com>

Marc Tompkins wrote:
> On Tue, Oct 14, 2008 at 9:23 AM, URBAN LANDREMAN <ulandreman at msn.com 
> <mailto:ulandreman at msn.com>> wrote:
>
>     Thanks for the suggestion.
>
>     When I ran the slightly modified code:
>     import win32com.client
>     app = win32com.client.Dispatch('Word.Application')
>     docOrig =
>     app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
>     range = docOrig.Content()
>
Try range = docOrig.Range()
>
>     range.Find.Text = "e"
>     range.Find.Replacement.Text = "*"
>     range.Find.Execute()
>     docEditted = doc
>
And note that doc is undefined
>
>     docEditted.SaveAs('n:\\MetroPlanners\\2006\\MCHResearchProjectV2.doc')
>     app.Quit()
>
>
>     I got:
>
>     Traceback (most recent call last):
>       File "N:/SPSS/Python/Examples/MSWord/WordFindAndReplaceV2", line
>     5, in <module>
>         range.Find.Text = "e"
>     AttributeError: 'unicode' object has no attribute 'Find'
>
>
> docOrig.Content() returns you a Unicode object, which isn't the same 
> as a Word document at all.  You're then trying to use methods on that 
> object which aren't supported.  I can't give you specifics without 
> doing a bit of Googling myself, but you probably want a different call 
> on line 4 to give you an object you can work with.
>
>
> -- 
> www.fsrtechnologies.com <http://www.fsrtechnologies.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From telmoandres at gmail.com  Tue Oct 14 21:37:37 2008
From: telmoandres at gmail.com (Telmo Andres Sanchez)
Date: Tue, 14 Oct 2008 15:37:37 -0400
Subject: [Tutor] Learning to extract information from ABAQUS .dat and .rpt
	files using Python
Message-ID: <b26033170810141237l5cf3b673n31cda9e3f614a3da@mail.gmail.com>

Hello folks,

This is something that must have been asked several times. I want to post
process data obtained after running a FEM in ABAQUS. The requested results
are usually printed to the .dat file or .rpt file. I would like to learn how
to extract the information that I need (i.e. displacements and stresses at
the nodes) from this file using Python. The fact is that I am kind of new at
ABAQUS and have zero knowledge about Python. Therefore, any help with
websites, examples, tutorials, etc. would be appreciated.

Thank you!

Andres
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/60c2540f/attachment.htm>

From alan.gauld at btinternet.com  Wed Oct 15 01:08:25 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 15 Oct 2008 00:08:25 +0100
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
	not open
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>	<48F4AB40.2050805@brianlane.com><48F4BB00.3030708@gmail.com>	<48F4BB73.6010501@gmail.com>	<BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl><40af687b0810141007h3c30e474tbb7cfc53a1c897f2@mail.gmail.com>
	<48F4E80D.4010606@gmail.com>
Message-ID: <gd38p9$icp$1@ger.gmane.org>


"bob gailer" <bgailer at gmail.com> wrote

>>     docOrig =
>> 
>> app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
>>     range = docOrig.Content()
>>
> Try range = docOrig.Range()

But don't use range as a variable name or you will hide the
builtin function range().
And that will make many for loops difficult to do!

HTH,

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



From bgailer at gmail.com  Wed Oct 15 01:49:24 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 14 Oct 2008 19:49:24 -0400
Subject: [Tutor] Edit a Word document programmatically CORRECTION Open
 not open
In-Reply-To: <gd38p9$icp$1@ger.gmane.org>
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>	<48F4AB40.2050805@brianlane.com><48F4BB00.3030708@gmail.com>	<48F4BB73.6010501@gmail.com>	<BAY111-W218FBB55D75ACB3BF9E263C2310@phx.gbl><40af687b0810141007h3c30e474tbb7cfc53a1c897f2@mail.gmail.com>	<48F4E80D.4010606@gmail.com>
	<gd38p9$icp$1@ger.gmane.org>
Message-ID: <48F53004.6@gmail.com>

Alan Gauld wrote:
>
> "bob gailer" <bgailer at gmail.com> wrote
>
>>>     docOrig =
>>>
>>> app.Documents.Open('n:\\MetroPlanners\\2006\\MCHResearchProject.doc')
>>>     range = docOrig.Content()
>>>
>> Try range = docOrig.Range()
>
> But don't use range as a variable name or you will hide the
> builtin function range().
> And that will make many for loops difficult to do!

Ah yes. Thanks for that reminder!


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From metolone+gmane at gmail.com  Wed Oct 15 04:26:51 2008
From: metolone+gmane at gmail.com (Mark Tolonen)
Date: Tue, 14 Oct 2008 19:26:51 -0700
Subject: [Tutor] Edit a Word document programmatically
References: <BAY111-W364B7C4C69E8579B0F9A9DC2310@phx.gbl>
Message-ID: <gd3kd4$am3$1@ger.gmane.org>

These two lines connect to Word.  The EnsureDispatch makes sure Word constants work later:

>>> import win32com.client
>>> word = win32com.client.gencache.EnsureDispatch('Word.Application')

Then record a Word macro to do what you want (this was a find/replace all):

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "fox"
        .Replacement.Text = "cat"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

Then translate to Python:

>>> find = word.Selection.Find
>>> find.ClearFormatting()
>>> find.Replacement.ClearFormatting()
>>> find.Text = 'fox'
>>> find.Replacement.Text = 'cat'
>>> find.Forward = True
>>> find.Wrap = win32com.client.constants.wdFindContinue
>>> find.Execute(Replace=win32com.client.constants.wdReplaceAll)
True

-Mark



"URBAN LANDREMAN" <ulandreman at msn.com> wrote in message news:BAY111-W364B7C4C69E8579B0F9A9DC2310 at phx.gbl...
  Good morning,

  I'm trying to write some Python code to programmatically do a Find and Replace of a string within a Microsoft Word document.
  Any suggestions on where I could look to find how to do such a function?

  Thank you.


  Urban Landreman 




------------------------------------------------------------------------------


  _______________________________________________
  Tutor maillist  -  Tutor at python.org
  http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/33078d59/attachment.htm>

From sierra_mtnview at sbcglobal.net  Wed Oct 15 07:25:28 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Tue, 14 Oct 2008 22:25:28 -0700
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
	Instead ...
Message-ID: <48F57EC8.8030108@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/2be2dea1/attachment.htm>

From basilbthoppil at gmail.com  Wed Oct 15 07:27:05 2008
From: basilbthoppil at gmail.com (Basil B Thoppil)
Date: Wed, 15 Oct 2008 10:57:05 +0530
Subject: [Tutor] Use Regular Expressions
Message-ID: <fc12ae40810142227k61b1b7d9g628d557469f34dc3@mail.gmail.com>

Hi everyone,
I am using the cPAMIE library for automation of websites. It has a function
findTextbox(name) , which takes the name(a string) of the text box and
searches for it and return True if it exists. Now I dont have a static name
and so  I wanted to use regular expression. I cannot pass regular
expressions directly since it doesnt take a regular expression. How can I
make use of RE in my function.

regards
-basiL-

-- 



_______________________________________________________
"Dream is not what you see in sleep. Dream is the thing which does not let
you sleep" - Dr.Abdul Kalam

_______________________________________________________
_______________________________________________________

_______   Basil B Thoppil
_______   Room No. C-22, Mens Hostel,
_______   Government Engineering College,
_______   Thrissur-9, Kerala.
_______   +919846717505
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/cb94402c/attachment.htm>

From rajeev1204 at gmail.com  Wed Oct 15 08:34:37 2008
From: rajeev1204 at gmail.com (Rajeev Nair)
Date: Wed, 15 Oct 2008 12:04:37 +0530
Subject: [Tutor] using lists as values for key in dictionary?
Message-ID: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>

hi.

Is it possible to use and how to acess it?




regards

rajeev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/e8996f1f/attachment.htm>

From marc.tompkins at gmail.com  Wed Oct 15 08:54:46 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Tue, 14 Oct 2008 23:54:46 -0700
Subject: [Tutor] using lists as values for key in dictionary?
In-Reply-To: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
References: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
Message-ID: <40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>

Dictionary keys must be immutable - in other words, they must be objects
that aren't allowed to change.  Lists can change, so the answer is no.
However, tuples are immutable, so if you turn your list into a tuple (I can
never remember, is that a cast or a coercion?), you can use it as a
dictionary key.

>>> lX = [1, 2, 3, 'guido']
>>> lX
[1, 2, 3, 'guido']
>>> lX = tuple(lX)
>>> lX
(1, 2, 3, 'guido')

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/d0c8fc97/attachment.htm>

From marc.tompkins at gmail.com  Wed Oct 15 09:01:30 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Wed, 15 Oct 2008 00:01:30 -0700
Subject: [Tutor] using lists as values for key in dictionary?
In-Reply-To: <40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>
References: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
	<40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>
Message-ID: <40af687b0810150001o44b42c6g8660921b7124654e@mail.gmail.com>

On Tue, Oct 14, 2008 at 11:54 PM, Marc Tompkins <marc.tompkins at gmail.com>wrote:

> so if you turn your list into a tuple (I can never remember, is that a cast
> or a coercion?)
>

To answer my own question: neither, but it's closer (in spirit) to a cast.

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/4d28ed01/attachment.htm>

From wescpy at gmail.com  Wed Oct 15 09:22:10 2008
From: wescpy at gmail.com (wesley chun)
Date: Wed, 15 Oct 2008 00:22:10 -0700
Subject: [Tutor] using lists as values for key in dictionary?
In-Reply-To: <40af687b0810150001o44b42c6g8660921b7124654e@mail.gmail.com>
References: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
	<40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>
	<40af687b0810150001o44b42c6g8660921b7124654e@mail.gmail.com>
Message-ID: <78b3a9580810150022q2c4f20adx1cdf9c35ef51fdd6@mail.gmail.com>

>> so if you turn your list into a tuple (I can never remember, is that a
>> cast or a coercion?)
>
>> lX = tuple(lX)
>
> To answer my own question: neither, but it's closer (in spirit) to a cast.

you're keeping everyone is suspense! :-)  you are creating a brand new
tuple by copying out the references to the objects in the list. then
you assign that tuple to the variable that previously referenced your
original list.

NOTE: the original object remained as a list with no modifications,
but was probably marked for deallocation when you dropped your
references to it unless there were other references to it.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

"Python Web Development with Django", Addison Wesley, (c) 2008
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

From marc.tompkins at gmail.com  Wed Oct 15 09:40:08 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Wed, 15 Oct 2008 00:40:08 -0700
Subject: [Tutor] using lists as values for key in dictionary?
In-Reply-To: <78b3a9580810150022q2c4f20adx1cdf9c35ef51fdd6@mail.gmail.com>
References: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
	<40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>
	<40af687b0810150001o44b42c6g8660921b7124654e@mail.gmail.com>
	<78b3a9580810150022q2c4f20adx1cdf9c35ef51fdd6@mail.gmail.com>
Message-ID: <40af687b0810150040i75c6e454h52bf3fe736562781@mail.gmail.com>

On Wed, Oct 15, 2008 at 12:22 AM, wesley chun <wescpy at gmail.com> wrote:

> >> so if you turn your list into a tuple (I can never remember, is that a
> >> cast or a coercion?)
> >
> >> lX = tuple(lX)
> >
> > To answer my own question: neither, but it's closer (in spirit) to a
> cast.
>
> you're keeping everyone is suspense! :-)  you are creating a brand new
> tuple by copying out the references to the objects in the list. then
> you assign that tuple to the variable that previously referenced your
> original list.
>
> NOTE: the original object remained as a list with no modifications,
> but was probably marked for deallocation when you dropped your
> references to it unless there were other references to it.
>

Yes - if I had stopped and thought for just a few more seconds, I would
never have said that in the first place.  tuple() is a function like any
other; assigning its return value to an object of the same name as its input
obviously has nothing to do with either casting or coercion and it was a
dumb thing to say.  Which was why I retracted it almost immediately.
However, what I meant by "closer in spirit" - and it was still a dumb thing
to say - was that, if the whole thing happened in a black box and you had no
idea of the mechanics, it would have the "flavor" of a cast, as opposed to
the "flavor" of coercion.  Sorta.  Not really.  Unfortunately, thanks to the
magic of the Internet, I can't just ask everybody to forget I mentioned
it... can I?  Please?


-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/e1089736/attachment.htm>

From kent37 at tds.net  Wed Oct 15 12:35:21 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 15 Oct 2008 06:35:21 -0400
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
	Instead ...
In-Reply-To: <48F57EC8.8030108@sbcglobal.net>
References: <48F57EC8.8030108@sbcglobal.net>
Message-ID: <1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>

On Wed, Oct 15, 2008 at 1:25 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> ... of mov files. (See Subject). Our meteor software program uses a py
> program to produce a movie from images taken by an all-sky camera. The
> frames are in a simple but different format than likely used anywhere else.
> From these, it produces a mov file. As I understand it, mov files are used
> by QuickTime. If easily done, I'd like to produce avi files instead. Perhaps
> someone might be able to give me a clue if it's possible to modify this
> program for avi. Maybe there's a program that translates mov files to avi?

How does the program create the .mov files? Maybe you could post a
snippet to give us some help.

Kent

From kent37 at tds.net  Wed Oct 15 12:42:22 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 15 Oct 2008 06:42:22 -0400
Subject: [Tutor] Use Regular Expressions
In-Reply-To: <fc12ae40810142227k61b1b7d9g628d557469f34dc3@mail.gmail.com>
References: <fc12ae40810142227k61b1b7d9g628d557469f34dc3@mail.gmail.com>
Message-ID: <1c2a2c590810150342x40bc8208q6e67292b60eef43c@mail.gmail.com>

On Wed, Oct 15, 2008 at 1:27 AM, Basil B Thoppil
<basilbthoppil at gmail.com> wrote:
> Hi everyone,
> I am using the cPAMIE library for automation of websites. It has a function
> findTextbox(name) , which takes the name(a string) of the text box and
> searches for it and return True if it exists. Now I dont have a static name
> and so  I wanted to use regular expression. I cannot pass regular
> expressions directly since it doesnt take a regular expression. How can I
> make use of RE in my function.

Can you get a list of all the text boxes and check their names against
your regex?

Kent

From kent37 at tds.net  Wed Oct 15 13:02:02 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 15 Oct 2008 07:02:02 -0400
Subject: [Tutor] Learning to extract information from ABAQUS .dat and
	.rpt files using Python
In-Reply-To: <b26033170810141237l5cf3b673n31cda9e3f614a3da@mail.gmail.com>
References: <b26033170810141237l5cf3b673n31cda9e3f614a3da@mail.gmail.com>
Message-ID: <1c2a2c590810150402p1f3201d6v40deac1c9af7bdd1@mail.gmail.com>

On Tue, Oct 14, 2008 at 3:37 PM, Telmo Andres Sanchez
<telmoandres at gmail.com> wrote:
> I want to post
> process data obtained after running a FEM in ABAQUS. The requested results
> are usually printed to the .dat file or .rpt file. I would like to learn how
> to extract the information that I need (i.e. displacements and stresses at
> the nodes) from this file using Python. The fact is that I am kind of new at
> ABAQUS and have zero knowledge about Python. Therefore, any help with
> websites, examples, tutorials, etc. would be appreciated.

You should start reading one of the Python beginners tutorials listed here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Pay particular attention to the section about reading files.

When you are comfortable with the basics then show us what you are
trying to do in more detail.

I see that Abaqus is scriptable in Python; that may give you a better
way to proceed than trying to parse the output file. I can't find any
info online about this however so the help we can give may be limited
unless there is another Abaqus user on this list. You might also try
the Abaqus list at
http://tech.groups.yahoo.com/group/ABAQUS/

Kent

From sierra_mtnview at sbcglobal.net  Wed Oct 15 15:26:00 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Wed, 15 Oct 2008 06:26:00 -0700
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
 Instead ...
In-Reply-To: <1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>
References: <48F57EC8.8030108@sbcglobal.net>
	<1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>
Message-ID: <48F5EF68.6090405@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/034e417c/attachment.htm>

From kent37 at tds.net  Wed Oct 15 16:00:34 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 15 Oct 2008 10:00:34 -0400
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
	Instead ...
In-Reply-To: <48F5EF68.6090405@sbcglobal.net>
References: <48F57EC8.8030108@sbcglobal.net>
	<1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>
	<48F5EF68.6090405@sbcglobal.net>
Message-ID: <1c2a2c590810150700s4184ca6btedb9fd67cfd9655c@mail.gmail.com>

On Wed, Oct 15, 2008 at 9:26 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> See movie-clue at <http://pastebin.com/m5077868c>

Wow. Someone has reverse-engineered the entire .mov file format! I
don't think you will be able to reuse any of that except perhaps
MakeJPEG().

The only solution I can find for creating .avi files from Python is PyMedia:
http://pymedia.org/features.html

Kent

From cezary.krzyzanowski at gmail.com  Wed Oct 15 16:42:02 2008
From: cezary.krzyzanowski at gmail.com (Cezary =?UTF-8?Q?Krzy=C5=BCanowski?=)
Date: Wed, 15 Oct 2008 16:42:02 +0200
Subject: [Tutor] First time webaps as example
Message-ID: <1224081722.6300.42.camel@kacper>

Hi!

I'm encouraging the students I teach to use python for their webapps.
It's usually their first encounter with python, mostly even with
webapps. C#, PHP+MySQL is something put into them in my university.

So I'm looking for good ideas of first-time webaps to write. I tell them
to use django/pylons/turbogears to write something like kittenwars,
hotornot, a wiki, a simple shop, paster, a messageboard.

I'd like to find some other simple and interesting apps to show them,
similar to kittenwar and hotornot, as they attract the most students and
make them much more enthusiastic.

Since I'm already asking, maybe some ideas for other, 'non-webaps' to
show them to mimic and try out stuff like Pair Programming, Test Driven
Developement and other 'strange' (to them) ways of programming.

Thanks in advance,
Cz at rny


From bgailer at gmail.com  Wed Oct 15 17:39:46 2008
From: bgailer at gmail.com (bob gailer)
Date: Wed, 15 Oct 2008 11:39:46 -0400
Subject: [Tutor] First time webaps as example
In-Reply-To: <1224081722.6300.42.camel@kacper>
References: <1224081722.6300.42.camel@kacper>
Message-ID: <48F60EC2.2030806@gmail.com>

Cezary Krzy?anowski wrote:
> Hi!
>
> I'm encouraging the students I teach to use python for their webapps.
> It's usually their first encounter with python, 

Now I begin to understand why students come to this list confused about 
assignments!

IMHO it is essential when introducing a new language to first get the 
students comfortable with the language before attempting to learn a web 
framework or database processing or accounting or anything else than the 
basic lanaguage.

What do you think?

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From david at abbottdavid.com  Wed Oct 15 17:32:49 2008
From: david at abbottdavid.com (David)
Date: Wed, 15 Oct 2008 11:32:49 -0400
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
 Instead ...
In-Reply-To: <48F60BCF.6000603@abbottdavid.com>
References: <48F57EC8.8030108@sbcglobal.net>
	<1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>
	<48F60BCF.6000603@abbottdavid.com>
Message-ID: <48F60D21.1010507@abbottdavid.com>

David wrote:
> You could use mencoder, part of mplayer;
> mencoder -oac mp3lame -ovc lavc -vf scale=0:0:0:0:0:0:qpal
> somemovfile.mov -o outavifile.avi
>
> Here is a program to convert ogg theora to avi;
>
> #!/usr/bin/python
> #Filename = ogg_to_avi.py
>  
> import os,sys
>  
> print '\n\togg theora video to avi video\n'
> ogg = raw_input('Enter the ogg file to convert: ')
> avi = raw_input('Enter the avi to be created: ')
>  
> os.system("mencoder %s -ovc lavc -oac mp3lame -o %s" % (ogg, avi))
>  
> if os.path.exists(avi):
>     print '\n\tYour', avi, 'has been created.\n'
>     sys.exit()
>  
> else:
>     print 'error, something went wrong!'
>     sys.exit()
>
>
>   


-- 
powered by Gentoo/GNU Linux
http://linuxcrazy.com


From kent37 at tds.net  Wed Oct 15 18:05:37 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 15 Oct 2008 12:05:37 -0400
Subject: [Tutor] First time webaps as example
In-Reply-To: <1224081722.6300.42.camel@kacper>
References: <1224081722.6300.42.camel@kacper>
Message-ID: <1c2a2c590810150905m2ce2a7c5xb448af18e26d2d4a@mail.gmail.com>

On Wed, Oct 15, 2008 at 10:42 AM, Cezary Krzy?anowski
<cezary.krzyzanowski at gmail.com> wrote:

> So I'm looking for good ideas of first-time webaps to write. I tell them
> to use django/pylons/turbogears to write something like kittenwars,
> hotornot, a wiki, a simple shop, paster, a messageboard.

You might want to point them at Pinax, which is basically a Django
toolkit for building social-networking sites.
http://pinaxproject.com/

Kent

From lie.1296 at gmail.com  Wed Oct 15 20:24:25 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Thu, 16 Oct 2008 01:24:25 +0700
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
	Instead ...
Message-ID: <1224095065.22903.1.camel@lieryan-laptop>

On Wed, Oct 15, 2008 at 1:25 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> ... of mov files. (See Subject). Our meteor software program uses a py
> program to produce a movie from images taken by an all-sky camera. The
> frames are in a simple but different format than likely used anywhere
> else. From these, it produces a mov file. As I understand it, mov
> files are used by QuickTime. If easily done, I'd like to produce avi
> files instead. Perhaps someone might be able to give me a clue if it's
> possible to modify this program for avi. Maybe there's a program that
> translates mov files to avi?

Sure is, ffmpeg and mencoder are two most used video converter[1]. And
since they are based on command-line that means your python program only
need to use the subprocess module to control them (in fact, many free
and paid video encoder/converter is merely a GUI for ffmpeg or mencoder
or both).

[1] The term "converter" is an understatement compared to what they can
do
[2] ffmpeg's page: http://ffmpeg.mplayerhq.hu/
[3] mencoder's page: http://www.mplayerhq.hu/design7/news.html



From wescpy at gmail.com  Wed Oct 15 20:27:26 2008
From: wescpy at gmail.com (wesley chun)
Date: Wed, 15 Oct 2008 11:27:26 -0700
Subject: [Tutor] using lists as values for key in dictionary?
In-Reply-To: <40af687b0810150040i75c6e454h52bf3fe736562781@mail.gmail.com>
References: <eec116310810142334w33627660ne7d08159c0ce5268@mail.gmail.com>
	<40af687b0810142354v706ba745r359739094cba021f@mail.gmail.com>
	<40af687b0810150001o44b42c6g8660921b7124654e@mail.gmail.com>
	<78b3a9580810150022q2c4f20adx1cdf9c35ef51fdd6@mail.gmail.com>
	<40af687b0810150040i75c6e454h52bf3fe736562781@mail.gmail.com>
Message-ID: <78b3a9580810151127h54c45980h2297e984faef665f@mail.gmail.com>

>> >> so if you turn your list into a tuple (I can never remember, is that a
>> >> cast or a coercion?)
>> >
>> >> lX = tuple(lX)
>> >
>> > To answer my own question: neither, but it's closer (in spirit) to a
>> > cast.
>>
>> you're keeping everyone is suspense! :-)  you are creating a brand new
>> tuple by copying out the references to the objects in the list. then
>> you assign that tuple to the variable that previously referenced your
>> original list.
>>
>> NOTE: the original object remained as a list with no modifications,
>> but was probably marked for deallocation when you dropped your
>> references to it unless there were other references to it.
>
> Yes - if I had stopped and thought for just a few more seconds, I would
> never have said that in the first place.  tuple() is a function like any
> other; assigning its return value to an object of the same name as its input
> obviously has nothing to do with either casting or coercion and it was a
> dumb thing to say.  Which was why I retracted it almost immediately.

tuple() is *almost* like any other built-in function... its main magic
is that it's a *factory* function, one who's name is really a type and
so is the return value because if generates a new object of that type.


> However, what I meant by "closer in spirit" - and it was still a dumb thing
> to say - was that, if the whole thing happened in a black box and you had no
> idea of the mechanics, it would have the "flavor" of a cast, as opposed to
> the "flavor" of coercion.  Sorta.  Not really.  Unfortunately, thanks to the
> magic of the Internet, I can't just ask everybody to forget I mentioned
> it... can I?  Please?

you response will outlive you on google forever... your grandkids will
see it, and so will their's... :-)

the good news is that you're familiar with coercion, something that
newbies to Python may not be fully aware of, which is to convert all
numbers to the same type so that you can perform an operation on it --
recall that in most languages (not just Python) that operations are
usually only supported if both operands are of the same type:

>>> 1.5 + 3
4.5

you may *think* you're adding an integer 3 to float 1.5, but
internally, it gets converted, oops, i mean *coerced* into a float to
perform the math and give you the result.  at the risk of showing
people a function that will *no longer exist* in Python 3.x, this
example is purely to show what happens internally:

>>> coerce(1.5, 3)
(1.5, 3.0)

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

From sierra_mtnview at sbcglobal.net  Wed Oct 15 23:23:59 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Wed, 15 Oct 2008 14:23:59 -0700
Subject: [Tutor] Looking for Clues to Make a Program Produce avi Files
 Instead ...
In-Reply-To: <48F60D21.1010507@abbottdavid.com>
References: <48F57EC8.8030108@sbcglobal.net>	<1c2a2c590810150335u245e664kfa06b2b265d55b25@mail.gmail.com>	<48F60BCF.6000603@abbottdavid.com>
	<48F60D21.1010507@abbottdavid.com>
Message-ID: <48F65F6F.5010208@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/c73eda64/attachment.htm>

From emadnawfal at gmail.com  Wed Oct 15 23:59:58 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Wed, 15 Oct 2008 17:59:58 -0400
Subject: [Tutor] Difficult loop?
Message-ID: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>

Dear Tutors,
I needed a program to go through  a word like this "Almuta$r~id"

1-  a, i,u,  and o are the short vowels
2-  ~ is the double consonant.
I wanted the program to do the following:

- For each letter of the word, if the letter is not a short vowel, print the
letter with the 5 preceding letters (that are not short vowels),  then the
letter itself, then the 5 following letters (no short vowels), then the
short vowel following the letter.
- If the letter is followed by the double character "~", do the same, but
instead of printing just the vowel following the letter as the last
character, print the "~" + the short vowel
-  if the letter is not followed by a vowel, print an underscore as the last
character.

- if there a "+" sign, ignore it.
- If there are fewer than  5 preceding or following letters, print an
underscore in place of each missing letter.

For example, the word "Almuta$r~id" would be printed as follows:

_  _  _  _  _  A  l  m  t  $  r  _
_  _  _  _  A  l  m  t  $  r  d  _
_  _  _  A  l  m  t  $  r  d  _  u
_  _  A  l  m  t  $  r  d  _  _  a
_  A  l  m  t  $  r  d  _  _  _  a
A  l  m  t  $  r  d  _  _  _  _  ~i
l  m  t  $  r  d  _  _  _  _  _  _

I took the problem to a friend of mine who is a Haskel programmer. He wrote
the following python script which works perfectly, but I'm wondering whether
there is an easier, more Pythonic, way to write this:


# Given a transliterated Arabic text like:
# luwnog biyt$ Al+wilAy+At+u ...

# + are to be ignored
# y, A, and w are the long vowels
# shadda is written ~

# produce a table with:
# (letter, vowel, pre5, post5)
# where vowel is either - if the letter is not followed by a vowel or a
vowel
# or a shadda with a vowel, pre5 and post5 are the letters surrounding the
# letter

###############################################################################

# Initializes a few variables to be used or updated by the main loop below
space = ' '
plus = '+'
dash = '_'
shadda = '~'
vowels = ('a', 'e', 'i', 'o', 'u')
skips = (space,plus) + vowels

# a small input for testing

inputString = "Al+muta$ar~id+i Al+muta$ar~id+i Al+muta$ar~id+i"

# for convenience surround the input with six dashes both ways to make the
# loop below uniform

def makeWord (s): return dash*6 + s + dash*6

# A few utility constants, variables, and functions...

def shiftLeft (context, ch): return context[1:] + (ch,)

def isSkip (ch): return (ch in skips)

def isShadda (ch): return (ch == shadda)

def isVowel (ch): return (ch in vowels)

def nextCh (str,i):
    c = str[i]
    try:
        if isSkip(c):
            return nextCh(str,i+1)
        elif isShadda(str[i+1]):
            if isVowel(str[i+2]):
                return (c,str[i+1:i+3],i+3)
            else:
                return (c,dash,i+2)
        elif isVowel(str[i+1]):
            return (c,str[i+1],i+2)
        else:
            return (c,dash,i+1)
    except IndexError:
        return (c,dash,i+1)

def advance (str,pre,post,horizon):
    (cc,cv) = post[0]
    (hc,hv,nextHorizon) = nextCh(str,horizon)
    nextPre = shiftLeft(pre,(cc,cv))
    nextPost = shiftLeft(post,(hc,hv))
    return (cc,cv,nextPre,nextPost,nextHorizon)

def printLine (cc,cv,pre,post):
    if cc == dash: return
    simplePre = [c for (c,v) in pre]
    simplePost = [c for (c,v) in post[1:]]
    for c in simplePre: print "%s " % c,
    print "%s " % cc,
    for c in simplePost: print "%s " % c,
    print cv

def processWord (str):
    d = (dash,dash)
    pre = (d,d,d,d,d)
    post = (d,d,d,d,d,d)
    horizon = 6
    while horizon < len(str):
        (cc,cv,nextPre,nextPost,nextHorizon) = advance(str,pre,post,horizon)
        printLine(cc,cv,pre,post)
        pre = nextPre
        post = nextPost
        horizon = nextHorizon

def main ():
    strlist = map(makeWord, inputString.split())
    map(processWord,strlist)

main()


###############################################################################



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/468f4269/attachment-0001.htm>

From emadnawfal at gmail.com  Thu Oct 16 01:25:19 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Wed, 15 Oct 2008 19:25:19 -0400
Subject: [Tutor] Difficult loop?
In-Reply-To: <5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
Message-ID: <652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>

2008/10/15 John Fouhy <john at fouhy.net>

> 2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
> > Dear Tutors,
> > I needed a program to go through  a word like this "Almuta$r~id"
> >
> > 1-  a, i,u,  and o are the short vowels
> > 2-  ~ is the double consonant.
> > I wanted the program to do the following:
> >
> > - For each letter of the word, if the letter is not a short vowel, print
> the
> > letter with the 5 preceding letters (that are not short vowels),  then
> the
> > letter itself, then the 5 following letters (no short vowels), then the
> > short vowel following the letter.
> > - If the letter is followed by the double character "~", do the same, but
> > instead of printing just the vowel following the letter as the last
> > character, print the "~" + the short vowel
> > -  if the letter is not followed by a vowel, print an underscore as the
> last
> > character.
> >
> > - if there a "+" sign, ignore it.
> > - If there are fewer than  5 preceding or following letters, print an
> > underscore in place of each missing letter.
> >
> > For example, the word "Almuta$r~id" would be printed as follows:
> >
> > _  _  _  _  _  A  l  m  t  $  r  _
> > _  _  _  _  A  l  m  t  $  r  d  _
> > _  _  _  A  l  m  t  $  r  d  _  u
> > _  _  A  l  m  t  $  r  d  _  _  a
> > _  A  l  m  t  $  r  d  _  _  _  a
> > A  l  m  t  $  r  d  _  _  _  _  ~i
> > l  m  t  $  r  d  _  _  _  _  _  _
>
> Hi Emad,
>
> I had a crack at this.  My solution is below.  I think it is simpler
> than the one your friend provided :-)  Although I think there is
> something I don't understand about your rules, because I get slightly
> different results for your sample word:
>
> _  _  _  _  _  A  l  m  t  $  r  u
> _  _  _  _  A  l  m  t  $  r  ~  u
> _  _  _  A  l  m  t  $  r  ~  d  u
> _  _  A  l  m  t  $  r  ~  d  _  a
> _  A  l  m  t  $  r  ~  d  _  _  ~i
> A  l  m  t  $  r  ~  d  _  _  _  ~i
> l  m  t  $  r  ~  d  _  _  _  _  i
> m  t  $  r  ~  d  _  _  _  _  _  _
>
> Let me know if you have any trouble understanding any of the code:
>
> #####
>
> shortVowels = 'aiuo'
> double = '~'
>
> def notSV(c):
>    return c not in (shortVowels + '+')
>
> def nextSV(s, idx):
>    """ Find the next short vowel, or ~ + short vowel.
>
>    s :: string to search
>    idx :: index to start from
>
>    Return: short vowel, or ~ + short vowel, or _ if no following short
> vowel.
>    """
>
>    for i, c in enumerate(s[idx+1:]):
>        if c in shortVowels:
>            return c
>        elif c == double:
>            # return c and the character after it.
>            # assuming ~ is always followed by a short vowel
>            return s[i+idx+1:i+idx+3]
>
>    # If we exit the loop without finding a short vowel or a ~
>    return '_'
>
> def processChar(s, idx):
>    """ Process a single character of s according to the rules.
>
>    s :: string to work with
>    idx :: index to start from
>
>    Output tuple: (preceeding, following, last)
>    """
>
>    preceeding = filter(notSV, s[:idx])[-5:]
>    preceeding = '_'*(5-len(preceeding)) + preceeding
>
>    following = filter(notSV, s[idx+1:])[:5]
>    following = following + '_'*(5-len(following))
>
>    last = nextSV(s, idx)
>
>    return preceeding, following, last
>
> def process(s):
>    """ Process and print string according to the rules. """
>
>    for i, c in enumerate(s):
>        if c in shortVowels + '+':
>            continue
>        preceeding, following, last = processChar(s, i)
>        print '  '.join(preceeding + c + following) + '  ' + last
>
> if __name__ == '__main__':
>    test = "Almuta$r~id"
>    process(test)
>

Thank you so much John for thinking about this. The difference is here:
_  _  _  _  _  A  l  m  t  $  r  u
_  _  _  _  A  l  m  t  $  r  ~  u
_  _  _  A  l  m  t  $  r  ~  d  u

The focus  letter will always be # 6 on the line. A is not a short vowel,
and it is not followed by a short vowel, so the last character should be
"_", not a "u"

The same is true for lines 2 and 3 . The letter "l" is not followed by a
short vowel, so the last character should be "_"

Same for line 3 as well. "m" is not a short vowel, and it is not followed by
a short vowel

The purpose of this program is to calculate vector similarities in the
context of the letters in a machine learning approach called "Memory-based
learning"
-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/f4111106/attachment.htm>

From john at fouhy.net  Thu Oct 16 01:58:51 2008
From: john at fouhy.net (John Fouhy)
Date: Thu, 16 Oct 2008 12:58:51 +1300
Subject: [Tutor] Difficult loop?
In-Reply-To: <652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
	<652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
Message-ID: <5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>

2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
> The focus  letter will always be # 6 on the line. A is not a short vowel,
> and it is not followed by a short vowel, so the last character should be
> "_", not a "u"

Oh, I see.  I misunderstood the meaning of "followed by".  I can fix
that by changing one function in my code:

def nextSV(s, idx):
    """ Find the next short vowel, or ~ + short vowel.

    s :: string to search
    idx :: index to start from

    Return: short vowel, or ~ + short vowel, or _ if no following short vowel.
    """

    try:
        if s[idx+1] in shortVowels:
            return s[idx+1]
        elif s[idx+1] == double:
            return s[idx+1:idx+3]
        else:
            return '_'
    except IndexError:
        return '_'

> The purpose of this program is to calculate vector similarities in the
> context of the letters in a machine learning approach called "Memory-based
> learning"

I did wonder what it was for ;-)

-- 
John.

From emadnawfal at gmail.com  Thu Oct 16 02:15:55 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Wed, 15 Oct 2008 20:15:55 -0400
Subject: [Tutor] Difficult loop?
In-Reply-To: <5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
	<652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
	<5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>
Message-ID: <652641e90810151715y725c0db1i20b863104f18a671@mail.gmail.com>

That's great.
There is still only one thing that I was not aware of when I asked the
question.
When the double consonant sign  "~" is there, it should slo be skipped like
the short vowels. In other words, it cannot appear except in the pre-final
position along with another short vowel.
Is that easy to fix?

One more question,
I'm a linguistics person, I know some Java and some Python (and failed to
learn Prolog). What things do I need to learn to write such "difficult"
scripts? Are there any recommendations? books, certain things to learn?

To see how my friend's script was used, just look at the paper in this link:
http://jones.ling.indiana.edu/~skuebler/papers/vocal.pdf

Thank you so much,
Emad

2008/10/15 John Fouhy <john at fouhy.net>

> 2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
> > The focus  letter will always be # 6 on the line. A is not a short vowel,
> > and it is not followed by a short vowel, so the last character should be
> > "_", not a "u"
>
> Oh, I see.  I misunderstood the meaning of "followed by".  I can fix
> that by changing one function in my code:
>
> def nextSV(s, idx):
>    """ Find the next short vowel, or ~ + short vowel.
>
>    s :: string to search
>    idx :: index to start from
>
>    Return: short vowel, or ~ + short vowel, or _ if no following short
> vowel.
>    """
>
>     try:
>        if s[idx+1] in shortVowels:
>            return s[idx+1]
>        elif s[idx+1] == double:
>            return s[idx+1:idx+3]
>        else:
>            return '_'
>    except IndexError:
>        return '_'
>
> > The purpose of this program is to calculate vector similarities in the
> > context of the letters in a machine learning approach called
> "Memory-based
> > learning"
>
> I did wonder what it was for ;-)
>
> --
> John.
>



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/b8c6435e/attachment-0001.htm>

From john at fouhy.net  Thu Oct 16 02:28:32 2008
From: john at fouhy.net (John Fouhy)
Date: Thu, 16 Oct 2008 13:28:32 +1300
Subject: [Tutor] Difficult loop?
In-Reply-To: <652641e90810151715y725c0db1i20b863104f18a671@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
	<652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
	<5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>
	<652641e90810151715y725c0db1i20b863104f18a671@mail.gmail.com>
Message-ID: <5e58f2e40810151728u77c5c311o2b826b83f8a380d6@mail.gmail.com>

2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
> One more question,
> I'm a linguistics person, I know some Java and some Python (and failed to
> learn Prolog). What things do I need to learn to write such "difficult"
> scripts? Are there any recommendations? books, certain things to learn?

Well, there's a few tutorials around that you could work through.  The
best way to learn, in my opinion, is to find something not-too-hard
that you want to do and then start building it.  Combine that with the
documentation and ask questions on this list when you get stuck.

For example, you could look at the code I wrote and figure out how to
make the last change yourself :-)

-- 
John.

From emadnawfal at gmail.com  Thu Oct 16 02:35:34 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Wed, 15 Oct 2008 20:35:34 -0400
Subject: [Tutor] Difficult loop?
In-Reply-To: <5e58f2e40810151728u77c5c311o2b826b83f8a380d6@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
	<652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
	<5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>
	<652641e90810151715y725c0db1i20b863104f18a671@mail.gmail.com>
	<5e58f2e40810151728u77c5c311o2b826b83f8a380d6@mail.gmail.com>
Message-ID: <652641e90810151735q6de0d250m923cc8013292a527@mail.gmail.com>

2008/10/15 John Fouhy <john at fouhy.net>

> 2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
> > One more question,
> > I'm a linguistics person, I know some Java and some Python (and failed to
> > learn Prolog). What things do I need to learn to write such "difficult"
> > scripts? Are there any recommendations? books, certain things to learn?
>
> Well, there's a few tutorials around that you could work through.  The
> best way to learn, in my opinion, is to find something not-too-hard
> that you want to do and then start building it.  Combine that with the
> documentation and ask questions on this list when you get stuck.
>
> For example, you could look at the code I wrote and figure out how to
> make the last change yourself :-)



I will.
Thank you so much for your helpfulness.

>
> --
> John.
>



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/76ad6604/attachment.htm>

From sierra_mtnview at sbcglobal.net  Thu Oct 16 02:56:16 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Wed, 15 Oct 2008 17:56:16 -0700
Subject: [Tutor] How Do I tell Which Versions of Libraries/Modules I Have?
Message-ID: <48F69130.3090208@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/522c6e3c/attachment.htm>

From john at fouhy.net  Thu Oct 16 03:10:56 2008
From: john at fouhy.net (John Fouhy)
Date: Thu, 16 Oct 2008 14:10:56 +1300
Subject: [Tutor] How Do I tell Which Versions of Libraries/Modules I
	Have?
In-Reply-To: <48F69130.3090208@sbcglobal.net>
References: <48F69130.3090208@sbcglobal.net>
Message-ID: <5e58f2e40810151810j18909a18o32dfffdfed88ea83@mail.gmail.com>

2008/10/16 Wayne Watson <sierra_mtnview at sbcglobal.net>:
> That's the question in the Subject. Can Idle tell me? I see a Path Browser.

You could check the __version__ attribute.  Not all modules provide it, though.

(e.g.: import pickle ; pickle.__version__ )

-- 
John.

From emadnawfal at gmail.com  Thu Oct 16 03:32:49 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Wed, 15 Oct 2008 21:32:49 -0400
Subject: [Tutor] Difficult loop?
In-Reply-To: <652641e90810151735q6de0d250m923cc8013292a527@mail.gmail.com>
References: <652641e90810151459q6efa84ccp75d093e23e51db72@mail.gmail.com>
	<5e58f2e40810151600n2db2f4d7p1d05712f5e4bb97a@mail.gmail.com>
	<652641e90810151625w2d4ae1cas477e2f236e172bd3@mail.gmail.com>
	<5e58f2e40810151658l15a80ad1y984f4f5510f5173d@mail.gmail.com>
	<652641e90810151715y725c0db1i20b863104f18a671@mail.gmail.com>
	<5e58f2e40810151728u77c5c311o2b826b83f8a380d6@mail.gmail.com>
	<652641e90810151735q6de0d250m923cc8013292a527@mail.gmail.com>
Message-ID: <652641e90810151832m5b083d66v1e7524cfdc6b1b11@mail.gmail.com>

2008/10/15 Emad Nawfal (???? ????) <emadnawfal at gmail.com>

>
>
> 2008/10/15 John Fouhy <john at fouhy.net>
>
>> 2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:
>> > One more question,
>> > I'm a linguistics person, I know some Java and some Python (and failed
>> to
>> > learn Prolog). What things do I need to learn to write such "difficult"
>> > scripts? Are there any recommendations? books, certain things to learn?
>>
>> Well, there's a few tutorials around that you could work through.  The
>> best way to learn, in my opinion, is to find something not-too-hard
>> that you want to do and then start building it.  Combine that with the
>> documentation and ask questions on this list when you get stuck.
>>
>> For example, you could look at the code I wrote and figure out how to
>> make the last change yourself :-)
>>
>
>
> I will.
> Thank you so much for your helpfulness.
>
>>
Hi John and Tutors,
I have added a function notDouble, and changed a couple of  lines (marked
below), and the results are exactly what I want. Please let me know whether
this is the right, or the good, way to do it.

shortVowels = 'aiuo'
double = '~'
def notDouble(c):  # I added this function
    return c not in double
def notSV(c):
   return c not in (shortVowels + '+' )

def nextSV(s, idx):
   """ Find the next short vowel, or ~ + short vowel.

   s :: string to search
   idx :: index to start from

   Return: short vowel, or ~ + short vowel, or _ if no following short
vowel.
   """

   try:
       if s[idx+1] in shortVowels:
           return s[idx+1]
       elif s[idx+1] == double:
           return s[idx+1:idx+3]
       else:
           return '_'
   except IndexError:
       return '_'

def processChar(s, idx):
   """ Process a single character of s according to the rules.

   s :: string to work with
   idx :: index to start from

   Output tuple: (preceeding, following, last)
   """

   preceeding = filter(notSV, s[:idx])[-5:]
   preceeding = filter(notDouble, preceeding)[-5:] # I added this
   preceeding = '_'*(5-len(preceeding)) + preceeding

   following = filter(notSV, s[idx+1:])[:5]
   following = filter(notDouble, following)[:5] # I added this
   following = following + '_'*(5-len(following))

   last = nextSV(s, idx)

   return preceeding, following, last

def process(s):
   """ Process and print string according to the rules. """

   for i, c in enumerate(s):
       if c in shortVowels + '+' + double: # I added double
           continue
       preceeding, following, last = processChar(s, i)
       print '  '.join(preceeding + c + following) + '  ' + last

if __name__ == '__main__':
   test = "AlmutasAhilwn"
   process(test)

>
>> --
>> John.
>>
>
>
>
> --
> ?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
> ???????
> "No victim has ever been more repressed and alienated than the truth"
>
> Emad Soliman Nawfal
> Indiana University, Bloomington
> http://emnawfal.googlepages.com
> --------------------------------------------------------
>



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081015/bb65b533/attachment-0001.htm>

From coyote_v2002 at yahoo.com  Thu Oct 16 10:25:01 2008
From: coyote_v2002 at yahoo.com (Visvaldas K.)
Date: Thu, 16 Oct 2008 01:25:01 -0700 (PDT)
Subject: [Tutor] newbie question about list element manipulation after
	split()
Message-ID: <907029.97882.qm@web30701.mail.mud.yahoo.com>

Hi,

I feel very stupid, but I am stuck. I could try some workaround, but I want to understand what I am doing wrong.

The line:

for line in open("parameterfile").readlines( ):
    print line.split()                # trouble line


The "trouble line" works fine in this example. It prints
what I want, something which looks like lists of words:

['CT', 'CT', '268.0', '1.529']...  etc.

However, if I want to manipulate the individual list elements, I run into trouble. While

print line.split()[0]

still works, (it yields CT  - first element), 

however,

print line.split()[1]

gives error:

File "readatoms.py", line 103, in <module>
    print line.split()[1]
IndexError: list index out of range

Could you please tell me what's wrong. (I come from Perl background so Python seems out-of-the-body experience to me).

Sincerely,

Vis






 





      

From emadnawfal at gmail.com  Thu Oct 16 11:17:41 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Thu, 16 Oct 2008 05:17:41 -0400
Subject: [Tutor] newbie question about list element manipulation after
	split()
In-Reply-To: <907029.97882.qm@web30701.mail.mud.yahoo.com>
References: <907029.97882.qm@web30701.mail.mud.yahoo.com>
Message-ID: <652641e90810160217t52d9e41bj3443aaafded0069f@mail.gmail.com>

Here is a solution:
>>> for line in open('DBAN1001.txt').readlines():
...     line = line.split()
...     if len(line) > 1: # This is what makes it work for me.
...             print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.


On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. <coyote_v2002 at yahoo.com>wrote:

> Hi,
>
> I feel very stupid, but I am stuck. I could try some workaround, but I want
> to understand what I am doing wrong.
>
> The line:
>
> for line in open("parameterfile").readlines( ):
>    print line.split()                # trouble line
>
>
> The "trouble line" works fine in this example. It prints
> what I want, something which looks like lists of words:
>
> ['CT', 'CT', '268.0', '1.529']...  etc.
>
> However, if I want to manipulate the individual list elements, I run into
> trouble. While
>
> print line.split()[0]
>
> still works, (it yields CT  - first element),
>
> however,
>
> print line.split()[1]
>
> gives error:
>
> File "readatoms.py", line 103, in <module>
>    print line.split()[1]
> IndexError: list index out of range
>
> Could you please tell me what's wrong. (I come from Perl background so
> Python seems out-of-the-body experience to me).
>
> Sincerely,
>
> Vis
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/abc25cdf/attachment.htm>

From emadnawfal at gmail.com  Thu Oct 16 11:21:15 2008
From: emadnawfal at gmail.com (=?WINDOWS-1256?Q?Emad_Nawfal_(=DA=E3=C7=CF_=E4=E6=DD=E1)?=)
Date: Thu, 16 Oct 2008 05:21:15 -0400
Subject: [Tutor] newbie question about list element manipulation after
	split()
In-Reply-To: <907029.97882.qm@web30701.mail.mud.yahoo.com>
References: <907029.97882.qm@web30701.mail.mud.yahoo.com>
Message-ID: <652641e90810160221y73dfaaa9m83e9e683dcfe15ee@mail.gmail.com>

On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. <coyote_v2002 at yahoo.com>wrote:

> Hi,
>
> I feel very stupid, but I am stuck. I could try some workaround, but I want
> to understand what I am doing wrong.
>
> The line:
>
> for line in open("parameterfile").readlines( ):
>    print line.split()                # trouble line
>
>
> The "trouble line" works fine in this example. It prints
> what I want, something which looks like lists of words:
>
> ['CT', 'CT', '268.0', '1.529']...  etc.
>
> However, if I want to manipulate the individual list elements, I run into
> trouble. While
>
> print line.split()[0]
>
> still works, (it yields CT  - first element),
>
> however,
>
> print line.split()[1]
>
> gives error:
>
> File "readatoms.py", line 103, in <module>
>    print line.split()[1]
> IndexError: list index out of range
>
> Could you please tell me what's wrong. (I come from Perl background so
> Python seems out-of-the-body experience to me).
>
> Sincerely,
>
> Vis
>

Here is a solution:
>>> for line in open('DBAN1001.txt').readlines():
...     line = line.split()
...     if len(line) > 1: # This is what makes it work for me.
...             print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.


>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
?? ???? ?????? ????? ????? ??? ???? ??? ????? ?? ?????? ????????.....????
???????
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/4eab3100/attachment.htm>

From kent37 at tds.net  Thu Oct 16 12:24:01 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 16 Oct 2008 06:24:01 -0400
Subject: [Tutor] newbie question about list element manipulation after
	split()
In-Reply-To: <652641e90810160217t52d9e41bj3443aaafded0069f@mail.gmail.com>
References: <907029.97882.qm@web30701.mail.mud.yahoo.com>
	<652641e90810160217t52d9e41bj3443aaafded0069f@mail.gmail.com>
Message-ID: <1c2a2c590810160324p19665c8dg9af560f9f50c31a8@mail.gmail.com>

2008/10/16 Emad Nawfal (???? ????) <emadnawfal at gmail.com>:

> It works fine. It seems that in the file you have there are lines whose
> length is less than you should expect

Yes, my guess is there is a blank line in the file.

Kent

From roberto03 at gmail.com  Thu Oct 16 13:15:06 2008
From: roberto03 at gmail.com (roberto)
Date: Thu, 16 Oct 2008 13:15:06 +0200
Subject: [Tutor] school physics/math courses
Message-ID: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>

hello
(i am rather new in python ...)

i am about to start a course of physics and math for students aged
14-17 (high school)
and i am deeply interested in the possibilty of teaching fundamental
concepts of these subjects via teaching programming;
i chose python (i won't change my mind ...)

so i am looking for resources on how to deal with these topics via
this great programming language;

i need some help from you and moreover if you are aware of books
already covering these need

thank you in advance
-- 
roberto
OS: GNU/Linux, Debian

From kent37 at tds.net  Thu Oct 16 15:07:06 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 16 Oct 2008 09:07:06 -0400
Subject: [Tutor] school physics/math courses
In-Reply-To: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
Message-ID: <1c2a2c590810160607m2d709896r6a9e075af87c6629@mail.gmail.com>

On Thu, Oct 16, 2008 at 7:15 AM, roberto <roberto03 at gmail.com> wrote:
> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)

You should ask on the edu-sig list:
http://www.python.org/community/sigs/current/edu-sig/

Also see
http://www.4dsolutions.net/ocn/cp4e.html

Kent

From kent37 at tds.net  Thu Oct 16 15:07:50 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 16 Oct 2008 09:07:50 -0400
Subject: [Tutor] school physics/math courses
In-Reply-To: <1c2a2c590810160607m2d709896r6a9e075af87c6629@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<1c2a2c590810160607m2d709896r6a9e075af87c6629@mail.gmail.com>
Message-ID: <1c2a2c590810160607l78eb4946k17832b705b54293e@mail.gmail.com>

On Thu, Oct 16, 2008 at 9:07 AM, Kent Johnson <kent37 at tds.net> wrote:

> You should ask on the edu-sig list:
> http://www.python.org/community/sigs/current/edu-sig/

Oops, I see you cross-posted. Apologies to edu-sig!

Kent

From ksterling at mindspring.com  Thu Oct 16 15:10:32 2008
From: ksterling at mindspring.com (Ken Oliver)
Date: Thu, 16 Oct 2008 09:10:32 -0400 (EDT)
Subject: [Tutor] school physics/math courses
Message-ID: <20505737.1224162633033.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>

For a starting place, you may want to look at "Mathematics for the Digital Age and Programming in Python" by Maria and Gary Litvin.  ISBN 978-0-9727055-8-5

Both authors are very helpful and often contribute to math and CS electronic discussion groups. Communications possible through information below:

Skylight Publishing
9 Bartlet Street, Suite 70
Andover, MA 01810

web: http://www.skylit.com
e-mail: sales at skylit.com
        support at skylit.com


-----Original Message-----
>From: roberto <roberto03 at gmail.com>
>Sent: Oct 16, 2008 7:15 AM
>To: "edu-sig at python.org" <edu-sig at python.org>
>Cc: tutor at python.org
>Subject: [Tutor] school physics/math courses
>
>hello
>(i am rather new in python ...)
>
>i am about to start a course of physics and math for students aged
>14-17 (high school)
>and i am deeply interested in the possibilty of teaching fundamental
>concepts of these subjects via teaching programming;
>i chose python (i won't change my mind ...)
>
>so i am looking for resources on how to deal with these topics via
>this great programming language;
>
>i need some help from you and moreover if you are aware of books
>already covering these need
>
>thank you in advance
>-- 
>roberto
>OS: GNU/Linux, Debian
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor


From bgailer at gmail.com  Thu Oct 16 15:24:16 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 16 Oct 2008 09:24:16 -0400
Subject: [Tutor] Difficult loop?
Message-ID: <48F74080.1030205@gmail.com>

How about:

word = "Almuta$r~id"
predecessors = "_" * 5
successors = "".join(letter for letter in word if letter not in "aiou+~")
for index, letter in enumerate(word):
  if letter not in "aiou~+":
    next = word[index+1] if index < len(word) - 1 else ""
    if next in "aiou":
      tail = next
    elif next == "~":
      next = word[index+2] # bold assumption that a short vowel will 
follow ~
      tail = "~" + next
    else:
      tail = "_"
    print predecessors + successors + tail
    predecessors = predecessors[1:] + letter
    successors = successors[1:] + ("_" if len(successors) <= 5 else "")

Simple - procedural - no functions. 16 lines of code. Easy to read and 
maintain.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From bgailer at gmail.com  Thu Oct 16 17:41:52 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 16 Oct 2008 11:41:52 -0400
Subject: [Tutor] Difficult loop?
Message-ID: <48F760C0.6020507@gmail.com>

I just can't leave well enough alone. Down to 14 lines.
More names, less magic numbers.

word = "Almuta$r~id"
window = position = 5
shortAndOmit = "aiou+~"
rest = "_" * window + "".join(letter for letter in word
		if letter not in shortAndOmit) + "_" * window
word = iter(word + "+")
for letter in word:
   while letter not in shortAndOmit:
     position += 1
     print rest[position-window:position+window+1] + "_"
     letter = word.next()
   if letter in shortAndOmit[:4]:
     print rest[position-window:position+window+1] + letter
   elif letter == "~":
     print rest[position-window:position+window+1] + "~" + word.next()


-- 
Bob Gailer
Chapel Hill NC
919-636-4239

When we take the time to be aware of our feelings and
needs we have more satisfying interactions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?



From bgailer at gmail.com  Thu Oct 16 17:47:52 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 16 Oct 2008 11:47:52 -0400
Subject: [Tutor] Difficult loop?
Message-ID: <48F76228.70005@gmail.com>

Last post for this assignment for now - simplified even more.

word = "Almuta$r~id"
window = position = 5
shortAndOmit = "aiou+~"
rest = "_" * window + "".join(letter for letter in word
		if letter not in shortAndOmit) + "_" * window
word = iter(word)
for letter in word:
   if letter not in shortAndOmit:
     position += 1
     print rest[position-window:position+window+1] + "_"
   elif letter in shortAndOmit[:4]:
     print rest[position-window:position+window+1] + letter
   elif letter == "~":
     print rest[position-window:position+window+1] + "~" + word.next()


-- 
Bob Gailer
Chapel Hill NC
919-636-4239

When we take the time to be aware of our feelings and
needs we have more satisfying interactions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?



From sierra_mtnview at sbcglobal.net  Thu Oct 16 18:04:03 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 16 Oct 2008 09:04:03 -0700
Subject: [Tutor] school physics/math courses
In-Reply-To: <20505737.1224162633033.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>
References: <20505737.1224162633033.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>
Message-ID: <48F765F3.40301@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/baf59835/attachment-0001.htm>

From alan.gauld at btinternet.com  Thu Oct 16 19:53:13 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 16 Oct 2008 18:53:13 +0100
Subject: [Tutor] school physics/math courses
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
Message-ID: <gd7v2a$ahr$1@ger.gmane.org>


"roberto" <roberto03 at gmail.com> wrote

> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;

Try the Python edu-sig mailing list.
It is for those using Python in education.

There are probably others there who have done this already.

Alan G 



From alan.gauld at btinternet.com  Thu Oct 16 19:55:33 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 16 Oct 2008 18:55:33 +0100
Subject: [Tutor] school physics/math courses
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com><1c2a2c590810160607m2d709896r6a9e075af87c6629@mail.gmail.com>
	<1c2a2c590810160607l78eb4946k17832b705b54293e@mail.gmail.com>
Message-ID: <gd7v6m$b20$1@ger.gmane.org>


"Kent Johnson" <kent37 at tds.net> wrote in message 

> Oops, I see you cross-posted. Apologies to edu-sig!
> 
> Kent

If it makes you feel better I didn't notice either. :-)
And I also didn't notice the other emails...

Alan G


From greg at thewhittiers.com  Thu Oct 16 20:12:13 2008
From: greg at thewhittiers.com (greg whittier)
Date: Thu, 16 Oct 2008 14:12:13 -0400
Subject: [Tutor] school physics/math courses
In-Reply-To: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
Message-ID: <a250eacf0810161112q7a40e666v5612937fd4630ae2@mail.gmail.com>

On Thu, Oct 16, 2008 at 7:15 AM, roberto <roberto03 at gmail.com> wrote:

> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;
>

You might take a look at VPython.  I've used it before, but not for
educational purposes.  There are some interesting looking videos at
http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/17e44385/attachment.htm>

From mpaul213 at gmail.com  Fri Oct 17 00:55:46 2008
From: mpaul213 at gmail.com (michel paul)
Date: Thu, 16 Oct 2008 15:55:46 -0700
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
Message-ID: <40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>

This would be a great text for a high school math/CS class:  Math for the
Digital Age <http://www.skylit.com/mathandpython.html>.

- Michel

On Thu, Oct 16, 2008 at 4:15 AM, roberto <roberto03 at gmail.com> wrote:

> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;
>
> i need some help from you and moreover if you are aware of books
> already covering these need
>
> thank you in advance
> --
> roberto
> OS: GNU/Linux, Debian
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/448d54b6/attachment.htm>

From sierra_mtnview at sbcglobal.net  Fri Oct 17 04:34:03 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Thu, 16 Oct 2008 19:34:03 -0700
Subject: [Tutor] Convert a Sequence of Images into an AVI file
Message-ID: <48F7F99B.6010604@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/95b72478/attachment.htm>

From xboxmuncher at gmail.com  Fri Oct 17 05:40:30 2008
From: xboxmuncher at gmail.com (xbmuncher)
Date: Thu, 16 Oct 2008 23:40:30 -0400
Subject: [Tutor] retrieving httponly cookies on accessing webpage with
	urllib2
Message-ID: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>

I'm trying to mimic my firefox browser in requesting a webpage with python.
Here are the headers obtained by wireshark when I accessed it with firefox:
GET /dirName/ HTTP/1.1
Host: www.website.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)
Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive


the website responds with this header:
HTTP/1.1 200 OK
Date: Fri, 17 Oct 2008 03:16:19 GMT
Server: Apache/2.0.59 (FreeBSD) PHP/4.4.7 with Suhosin-Patch
X-Powered-By: PHP/4.4.7
Set-Cookie: bbsessionhash=1c9eacae7c56fefc79e627b07a9af8ae; path=/; HttpOnly
Set-Cookie: bblastvisit=1224613379; expires=Sat, 17 Oct 2009 03:16:19 GMT;
path=/
Set-Cookie: bblastactivity=0; expires=Sat, 17 Oct 2009 03:16:19 GMT; path=/
Cache-Control: private
Pragma: private
X-UA-Compatible: IE=7
Content-Encoding: gzip
Content-Length: 7099
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1



So I tried trusty ol' urllib2 to request it in python:
import urllib2


url = 'http://www.website.com'

#headers
h = {
'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)
Gecko/2008092417 Firefox/3.0.3',
'Accept' :
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'en-us,en;q=0.5',
'Accept-Encoding' : 'gzip,deflate',
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive' : '300',
'Connection' : 'keep-alive'
}
#request page
reqObj = urllib2.Request(url, None, h)
urlObj = urllib2.urlopen(reqObj)

#read response
print urlObj.read()
print urlObj.geturl()
print urlObj.info()

#close urlObj
urlObj.close()

raw_input('press a key...')


it returns these headers:
Date: Fri, 17 Oct 2008 03:39:20 GMT
Server: Apache/2.0.59 (FreeBSD) PHP/4.4.7 with Suhosin-Patch
X-Powered-By: PHP/4.4.7
Content-Length: 1311
Connection: close
Content-Type: text/html


Notice the content length is considerably smaller, and no cookies are sent
to me like they were in firefox. I know only a little about httpOnly
cookies, but that it is some kind of special cookie that I suppose has
something to do with python not being able to access it like firefox. All I
want to do is have python receive the same cookies that firefox did, how can
I do this? I read somewhere that httpOnly cookies were implemented in the
python cookie module:
http://glyphobet.net/blog/blurb/285
....yet the other cookies aren't being sent either...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081016/11fc7d5a/attachment.htm>

From carme.colominas at gmail.com  Fri Oct 17 10:59:11 2008
From: carme.colominas at gmail.com (carme colominas)
Date: Fri, 17 Oct 2008 10:59:11 +0200
Subject: [Tutor] name 'x" is not defined
Message-ID: <6ba13a40810170159v559bd12fj66490d100dee64ac@mail.gmail.com>

hi,

I'm a  linguist and absolut new on Python; I'm trying to follow the first
chapter of *Natural Language Processing in Python.
I'm aware this is a very basic question, but I'm stuck; can someone explain
me, what does it mean that a function is not defined and how to proceed?
*
For example, for fdist:

>> for word in nltk.corpus.brown.words():
    if fdist(word)>= 3:
        print(word)

I get the following:

Traceback (most recent call last):
  File "<pyshell#47>", line 2, in <module>
    if fdist(word)>= 3:
NameError: name 'fdist' is not defined

Thanks in advance!

carme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/78b51186/attachment-0001.htm>

From WFERGUSON1 at SOCAL.RR.COM  Fri Oct 17 10:09:17 2008
From: WFERGUSON1 at SOCAL.RR.COM (WM)
Date: Fri, 17 Oct 2008 01:09:17 -0700
Subject: [Tutor] SAVING & RUNNING A PROGRAM:
Message-ID: <48F8482D.6000005@SOCAL.RR.COM>

I wrote this two liner.  I wanted to save it and then to bring it back 
as  program.

IDLE 2.6      
 >>> brain = 'life'
 >>> print brain
life

I saved it as brain.py,

IDLE 2.6      
 >>> brain = 'life'
 >>> print brain
life
 >>>
python/brain.py

Traceback (most recent call last):
  File "<pyshell#2>", line 2, in <module>
    python/brain.py
NameError: name 'python' is not defined
 >>>

I think the line which drew the error message is close, but I have tried 
many versions and nothing works.
What am I doing wrong?  I get a similar result if I do the command line 
thing.l

From echerlin at gmail.com  Fri Oct 17 11:19:33 2008
From: echerlin at gmail.com (Edward Cherlin)
Date: Fri, 17 Oct 2008 02:19:33 -0700
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
Message-ID: <e574f6eb0810170219y4fe2db0kdd0e5f9259154553@mail.gmail.com>

On Thu, Oct 16, 2008 at 4:15 AM, roberto <roberto03 at gmail.com> wrote:
> hello
> (i am rather new in python ...)

Have you looked at NumPy and SciPy yet? Or anything written using them?

> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;
>
> i need some help from you and moreover if you are aware of books
> already covering these need
>
> thank you in advance
> --
> roberto
> OS: GNU/Linux, Debian
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>



-- 
Don't panic.--HHGTTG, Douglas Adams
fivethirtyeight.com, 3bluedudes.com Obama still moving ahead in EC!
http://www.obamapedia.org/page/Smears Join us!
http://wiki.sugarlabs.org/go/User:Mokurai For the children

Silent Thunder (??/??????????????? ) is my name
And Children are my nation.
The Cosmos is my dwelling place,
The Truth my destination.

From kent37 at tds.net  Fri Oct 17 13:29:42 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 17 Oct 2008 07:29:42 -0400
Subject: [Tutor] retrieving httponly cookies on accessing webpage with
	urllib2
In-Reply-To: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>
References: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>
Message-ID: <1c2a2c590810170429g11770242sb30b8112078af021@mail.gmail.com>

On Thu, Oct 16, 2008 at 11:40 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> I'm trying to mimic my firefox browser in requesting a webpage with python.

> So I tried trusty ol' urllib2 to request it in python:
> import urllib2
>
>
> url = 'http://www.website.com'
>
> #headers
> h = {
> 'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)
<snip>
> }
> #request page
> reqObj = urllib2.Request(url, None, h)
> urlObj = urllib2.urlopen(reqObj)

It doesn't work to set the User-Agent header this way. See
http://personalpages.tds.net/~kent37/kk/00010.html#e10request-headers
for a recipe.

> #read response
> print urlObj.read()

What content do you get? Is it an error message? What does wireshark
show for this request?

> Notice the content length is considerably smaller, and no cookies are sent
> to me like they were in firefox. I know only a little about httpOnly
> cookies, but that it is some kind of special cookie that I suppose has
> something to do with python not being able to access it like firefox. All I
> want to do is have python receive the same cookies that firefox did, how can
> I do this? I read somewhere that httpOnly cookies were implemented in the
> python cookie module:
> http://glyphobet.net/blog/blurb/285
> ....yet the other cookies aren't being sent either...

I don't think that has anything to do with your problem. httpOnly is
set by the server and interpreted by the browser. The Python change
was to allow httpOnly to be set by servers written in Python.

Kent

From kent37 at tds.net  Fri Oct 17 13:31:57 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 17 Oct 2008 07:31:57 -0400
Subject: [Tutor] name 'x" is not defined
In-Reply-To: <6ba13a40810170159v559bd12fj66490d100dee64ac@mail.gmail.com>
References: <6ba13a40810170159v559bd12fj66490d100dee64ac@mail.gmail.com>
Message-ID: <1c2a2c590810170431t7f0d3d5albfe8dd06b7b5d1c5@mail.gmail.com>

On Fri, Oct 17, 2008 at 4:59 AM, carme colominas
<carme.colominas at gmail.com> wrote:
> can someone explain
> me, what does it mean that a function is not defined and how to proceed?
>
> For example, for fdist:
>
>>> for word in nltk.corpus.brown.words():
>     if fdist(word)>= 3:
>         print(word)
>
> I get the following:
>
> Traceback (most recent call last):
>   File "<pyshell#47>", line 2, in <module>
>     if fdist(word)>= 3:
> NameError: name 'fdist' is not defined

It means that Python doesn't know what fdist means. You have to tell
it, either by defining an fdist() function yourself (using def) or by
importing a module that includes it.

Kent

From sharadgana at gmail.com  Fri Oct 17 13:30:28 2008
From: sharadgana at gmail.com (Sharad Ganapathy)
Date: Fri, 17 Oct 2008 17:00:28 +0530
Subject: [Tutor] SAVING & RUNNING A PROGRAM:
In-Reply-To: <48F8482D.6000005@SOCAL.RR.COM>
References: <48F8482D.6000005@SOCAL.RR.COM>
Message-ID: <gd9t0k$rpv$2@ger.gmane.org>

WM wrote:
> I wrote this two liner.  I wanted to save it and then to bring it back 
> as  program.
> 
> IDLE 2.6      >>> brain = 'life'
>  >>> print brain
> life
> 
> I saved it as brain.py,
> 
> IDLE 2.6      >>> brain = 'life'
>  >>> print brain
> life
>  >>>
> python/brain.py
> 
> Traceback (most recent call last):
>  File "<pyshell#2>", line 2, in <module>
>    python/brain.py
> NameError: name 'python' is not defined
>  >>>
> 
> I think the line which drew the error message is close, but I have tried 
> many versions and nothing works.
> What am I doing wrong?  I get a similar result if I do the command line 
> thing.l


If you are trying to use the saved file then you need to import it.

The file/module should be in your PYTHONPATH .

Sharad


From kent37 at tds.net  Fri Oct 17 13:35:39 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 17 Oct 2008 07:35:39 -0400
Subject: [Tutor] SAVING & RUNNING A PROGRAM:
In-Reply-To: <48F8482D.6000005@SOCAL.RR.COM>
References: <48F8482D.6000005@SOCAL.RR.COM>
Message-ID: <1c2a2c590810170435j6721d61u28ba4c4044e264a7@mail.gmail.com>

On Fri, Oct 17, 2008 at 4:09 AM, WM <WFERGUSON1 at socal.rr.com> wrote:
> I wrote this two liner.  I wanted to save it and then to bring it back as
>  program.

See http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/
Look for the section that starts, "Now that we've paddled long enough,
we might be asking: ok, this is neat, but if we close down Python and
start it up again, how do we get the computer to remember what we
typed?"

Don't include the >>> in your file, just include the part that you
actually typed.

Kent

From tomar.arun at gmail.com  Fri Oct 17 16:18:34 2008
From: tomar.arun at gmail.com (Arun Tomar)
Date: Fri, 17 Oct 2008 19:48:34 +0530
Subject: [Tutor] automatically generate python/pylons documentation
Message-ID: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>

hi!

I'm trying to generate documentation for my pylons web application.

my personal opinion:
1. pudge:
I've reviewed pudge. it was not very useful & hard to know as most of
the links are not working on the site and lack of support.
2. epydoc
I liked epydoc, the generated document looks more like what is
generate by ruby tools, i guess rdoc. if i give it a single python
file it works fine. but if i want epydoc to go into a specific folder
& generate the documentation for all the files & files in the sub
directories, it doesn't automatically do that. any pointers there.
3. sphinx:
i've read a little about it. haven't tried it yet.

my objective is to automatically generate documentation for my entire
pylons webapp or any other python application.

regds,
arun.

From marshall.jiang at gmail.com  Fri Oct 17 16:44:58 2008
From: marshall.jiang at gmail.com (Shuai Jiang (Runiteking1))
Date: Fri, 17 Oct 2008 10:44:58 -0400
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <e574f6eb0810170219y4fe2db0kdd0e5f9259154553@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<e574f6eb0810170219y4fe2db0kdd0e5f9259154553@mail.gmail.com>
Message-ID: <a678270c0810170744o40d33d6ao25df2f586136fe19@mail.gmail.com>

How about http://projecteuler.net/? From their website:

> Project Euler is a series of challenging mathematical/computer programming
> problems that will require more than just mathematical insights to solve.
> Although mathematics will help you arrive at elegant and efficient methods,
> the use of a computer and programming skills will be required to solve most
> problems.
>


On Fri, Oct 17, 2008 at 5:19 AM, Edward Cherlin <echerlin at gmail.com> wrote:

> On Thu, Oct 16, 2008 at 4:15 AM, roberto <roberto03 at gmail.com> wrote:
> > hello
> > (i am rather new in python ...)
>
> Have you looked at NumPy and SciPy yet? Or anything written using them?
>
> > i am about to start a course of physics and math for students aged
> > 14-17 (high school)
> > and i am deeply interested in the possibilty of teaching fundamental
> > concepts of these subjects via teaching programming;
> > i chose python (i won't change my mind ...)
> >
> > so i am looking for resources on how to deal with these topics via
> > this great programming language;
> >
> > i need some help from you and moreover if you are aware of books
> > already covering these need
> >
> > thank you in advance
> > --
> > roberto
> > OS: GNU/Linux, Debian
> > _______________________________________________
> > Edu-sig mailing list
> > Edu-sig at python.org
> > http://mail.python.org/mailman/listinfo/edu-sig
> >
>
>
>
> --
> Don't panic.--HHGTTG, Douglas Adams
> fivethirtyeight.com, 3bluedudes.com Obama still moving ahead in EC!
> http://www.obamapedia.org/page/Smears Join us!
> http://wiki.sugarlabs.org/go/User:Mokurai For the children
>
> Silent Thunder (??/??????????????? ) is my name
> And Children are my nation.
> The Cosmos is my dwelling place,
> The Truth my destination.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Visit my blog at runiteking1.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/dbf7857c/attachment-0001.htm>

From ilikefbsd at web.de  Fri Oct 17 17:57:27 2008
From: ilikefbsd at web.de (Marco)
Date: Fri, 17 Oct 2008 17:57:27 +0200
Subject: [Tutor] documentation tut.html Error 404
Message-ID: <48F8B5E7.2090709@web.de>

hi list,

the link provided in one of the initiation mails from the tutor-mailinglist:

...
http://www.python.org/doc/current/tut/tut.html
...

responds with a 404 error.

Best regards, 
 marco


From dyoo at cs.wpi.edu  Fri Oct 17 18:03:25 2008
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Fri, 17 Oct 2008 12:03:25 -0400
Subject: [Tutor] documentation tut.html Error 404
In-Reply-To: <48F8B5E7.2090709@web.de>
References: <48F8B5E7.2090709@web.de>
Message-ID: <d06401780810170903r6d1fdc81u6ccfdf1a7a391f17@mail.gmail.com>

On Fri, Oct 17, 2008 at 11:57 AM, Marco <ilikefbsd at web.de> wrote:
> hi list,
>
> the link provided in one of the initiation mails from the tutor-mailinglist:
>
> ...
> http://www.python.org/doc/current/tut/tut.html

Ok, thanks.  This should be fixed now.  The link appears to have moved to:

    http://www.python.org/doc/current/tutorial/index.html

From alan.gauld at btinternet.com  Fri Oct 17 18:46:19 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 17 Oct 2008 17:46:19 +0100
Subject: [Tutor] documentation tut.html Error 404
References: <48F8B5E7.2090709@web.de>
Message-ID: <gdafgt$3lq$1@ger.gmane.org>

"Marco" <ilikefbsd at web.de> wrote

> the link provided in one of the initiation mails from the 
> tutor-mailinglist:
> ...
> http://www.python.org/doc/current/tut/tut.html
> ...
> responds with a 404 error.

So it does, It should be

http://docs.python.org/tutorial/

Good catch!

Hopefully one of our list admins can fix that?

Alan G. 



From alan.gauld at btinternet.com  Fri Oct 17 18:55:44 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 17 Oct 2008 17:55:44 +0100
Subject: [Tutor] name 'x" is not defined
References: <6ba13a40810170159v559bd12fj66490d100dee64ac@mail.gmail.com>
Message-ID: <gdag2i$5ld$1@ger.gmane.org>

"carme colominas" <carme.colominas at gmail.com> wrote

> I'm a  linguist and absolut new on Python; I'm trying to follow the 
> first
> chapter of *Natural Language Processing in Python.

I'm not familiar witrh it but if the code you have is from the first
chapter then I suggest you should go through one of the beginner
Python tutorials first.

You don't say whether you know any other programjing languages
but from your question it doesn't look like it so I'll suggest you
try the Non Programmers tutorials:

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

> what does it mean that a function is not defined
> and how to proceed?

> Traceback (most recent call last):
>  File "<pyshell#47>", line 2, in <module>
>    if fdist(word)>= 3:
> NameError: name 'fdist' is not defined

Note that it doesn't say the function is not defined it says
the *name* is not defined.  That's a different thing. These
kinds of details matter in programming.

A name can be as variable or a function or a class or
a module or most any other kind of object in Python.
Names have to be created before they are used in Python.
In this case it is a function and we create it by defining
the function or by importing the function from another module.
The other possibility is to access it from another module
which we have already imported - like you did with the
words() function:

nltk.corpus.brown.words()

You may just need to preface the fdist() function with the
name of the module where it is defined.

But all of this will makemuch more sense if you go through
one of the tutorials on the link above.

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



From marc.tompkins at gmail.com  Fri Oct 17 19:02:37 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Fri, 17 Oct 2008 10:02:37 -0700
Subject: [Tutor] documentation tut.html Error 404
In-Reply-To: <gdafgt$3lq$1@ger.gmane.org>
References: <48F8B5E7.2090709@web.de> <gdafgt$3lq$1@ger.gmane.org>
Message-ID: <40af687b0810171002n2605115k5b8cda05bdcba163@mail.gmail.com>

>
> ...
>> http://www.python.org/doc/current/tut/tut.html
>>
>
Reminds me of Christopher Robin helping Winnie-the-Pooh try to fool the
bees:  "Tut tut, looks like rain!  Tut tut, looks like rain!"

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/da396da7/attachment.htm>

From marc.tompkins at gmail.com  Fri Oct 17 19:07:08 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Fri, 17 Oct 2008 10:07:08 -0700
Subject: [Tutor] documentation tut.html Error 404
In-Reply-To: <gdafgt$3lq$1@ger.gmane.org>
References: <48F8B5E7.2090709@web.de> <gdafgt$3lq$1@ger.gmane.org>
Message-ID: <40af687b0810171007t3a73d20ci2561878a41f4f3f8@mail.gmail.com>

>
> http://www.python.org/doc/current/tut/tut.html
>>
> Reminds me of Christopher Robin helping Winnie-the-Pooh try to fool the
bees: "Tut tut, looks like rain!  Tut tut, looks like rain!"

At least that's how Stanley Holloway said it on the Disney record I had as a
child...
-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/6d20a796/attachment.htm>

From sierra_mtnview at sbcglobal.net  Fri Oct 17 22:58:05 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Fri, 17 Oct 2008 13:58:05 -0700
Subject: [Tutor] school physics/math courses
In-Reply-To: <48F765F3.40301@sbcglobal.net>
References: <20505737.1224162633033.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>
	<48F765F3.40301@sbcglobal.net>
Message-ID: <48F8FC5D.9030300@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/b05f1d6a/attachment-0001.htm>

From sierra_mtnview at sbcglobal.net  Sat Oct 18 01:26:49 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Fri, 17 Oct 2008 16:26:49 -0700
Subject: [Tutor] Convert a Sequence of Images into an AVI file
In-Reply-To: <48F7F99B.6010604@sbcglobal.net>
References: <48F7F99B.6010604@sbcglobal.net>
Message-ID: <48F91F39.9060707@sbcglobal.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/669798a5/attachment.htm>

From alan.gauld at btinternet.com  Sat Oct 18 10:35:37 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 18 Oct 2008 09:35:37 +0100
Subject: [Tutor] Convert a Sequence of Images into an AVI file
References: <48F7F99B.6010604@sbcglobal.net> <48F91F39.9060707@sbcglobal.net>
Message-ID: <gdc74l$baf$1@ger.gmane.org>


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

>  I have a file of images shot at a frame rate of 1/30th of a second.
> ...I'd like to simply take the large images out of the file and make
> an avi file from them. What in Python will help me do that?

Have you looked at PIL?
The Python wrapper around ImageMagick may be of use too.

Alan G 



From carme.colominas at gmail.com  Sat Oct 18 11:56:19 2008
From: carme.colominas at gmail.com (carme colominas)
Date: Sat, 18 Oct 2008 11:56:19 +0200
Subject: [Tutor] name 'x" is not defined
In-Reply-To: <gdag2i$5ld$1@ger.gmane.org>
References: <6ba13a40810170159v559bd12fj66490d100dee64ac@mail.gmail.com>
	<gdag2i$5ld$1@ger.gmane.org>
Message-ID: <6ba13a40810180256m9b9fe82i8a5590a84d3a439d@mail.gmail.com>

thank you very much,  very clear explanation, I will try with the beginner
Phyton tutorials.
carme

2008/10/17 Alan Gauld <alan.gauld at btinternet.com>

> "carme colominas" <carme.colominas at gmail.com> wrote
> it
>
>> I'm a  linguist and absolut new on Python; I'm trying to follow the first
>> chapter of *Natural Language Processing in Python.
>>
>
> I'm not familiar witrh it but if the code you have is from the first
> chapter then I suggest you should go through one of the beginner
> Python tutorials first.
>
> You don't say whether you know any other programjing languages
> but from your question it doesn't look like it so I'll suggest you
> try the Non Programmers tutorials:
>
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>
> what does it mean that a function is not defined
>> and how to proceed?
>>
>
>  Traceback (most recent call last):
>>  File "<pyshell#47>", line 2, in <module>
>>   if fdist(word)>= 3:
>> NameError: name 'fdist' is not defined
>>
>
> Note that it doesn't say the function is not defined it says
> the *name* is not defined.  That's a different thing. These
> kinds of details matter in programming.
>
> A name can be as variable or a function or a class or
> a module or most any other kind of object in Python.
> Names have to be created before they are used in Python.
> In this case it is a function and we create it by defining
> the function or by importing the function from another module.
> The other possibility is to access it from another module
> which we have already imported - like you did with the
> words() function:
>
> nltk.corpus.brown.words()
>
> You may just need to preface the fdist() function with the
> name of the module where it is defined.
>
> But all of this will makemuch more sense if you go through
> one of the tutorials on the link above.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081018/8f949f71/attachment.htm>

From mpaul213 at gmail.com  Sat Oct 18 06:30:54 2008
From: mpaul213 at gmail.com (michel paul)
Date: Fri, 17 Oct 2008 21:30:54 -0700
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>
	<F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>
Message-ID: <40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>

"We should abandon the vision that physicists seek an ultimate mathematical
description of the universe since it is not obvious that it exists.  The job
of the physicist is that of modeling phenomena within the physical scales of
observed events. For some systems, the modeling can be done more effectively
using algorithms."

This is very interesting.  Thanks for sending it.

On Thu, Oct 16, 2008 at 7:14 PM, Massimo Di Pierro
<mdipierro at cs.depaul.edu>wrote:

> Hi Paul,
>
> this is a document I write as a summary of a meeting I attended in 2006 at
> Argonne National Laboratory about revising the Physics curriculum. If it is
> of any use you can do anything you want with it.
>
> Massimo
>
>
>
>
> On Oct 16, 2008, at 5:55 PM, michel paul wrote:
>
> This would be a great text for a high school math/CS class:  Math for the
> Digital Age <http://www.skylit.com/mathandpython.html>.
>
> - Michel
>
> On Thu, Oct 16, 2008 at 4:15 AM, roberto <roberto03 at gmail.com> wrote:
>
>> hello
>> (i am rather new in python ...)
>>
>> i am about to start a course of physics and math for students aged
>> 14-17 (high school)
>> and i am deeply interested in the possibilty of teaching fundamental
>> concepts of these subjects via teaching programming;
>> i chose python (i won't change my mind ...)
>>
>> so i am looking for resources on how to deal with these topics via
>> this great programming language;
>>
>> i need some help from you and moreover if you are aware of books
>> already covering these need
>>
>> thank you in advance
>> --
>> roberto
>> OS: GNU/Linux, Debian
>> _______________________________________________
>> Edu-sig mailing list
>> Edu-sig at python.org
>> http://mail.python.org/mailman/listinfo/edu-sig
>>
>
> <ATT00001.txt>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081017/a59cd865/attachment.htm>

From echerlin at gmail.com  Sat Oct 18 07:03:41 2008
From: echerlin at gmail.com (Edward Cherlin)
Date: Fri, 17 Oct 2008 22:03:41 -0700
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>
	<F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>
	<40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>
Message-ID: <e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>

2008/10/17 michel paul <mpaul213 at gmail.com>:
> "We should abandon the vision that physicists seek an ultimate mathematical
> description of the universe since it is not obvious that it exists.

I disagree with this attitude. We can seek an ultimate mathematical
description, since it is not obvious that it does not exist. We should
also be aware that we do not have one, and have some idea of the range
of validity of our models. This will help us to avoid mathematical
absurdities, particularly the infinities that result from calculations
on unphysical point masses and point charges.

> The job
> of the physicist is that of modeling phenomena within the physical scales of
> observed events.

True much of the time. Another part of the job is to model outside the
scale of the observed, and go make the new observations needed, as in
the case of General Relativity.

> For some systems, the modeling can be done more effectively
> using algorithms."

As a mathematician, I don't know what that means. Every algorithm can
be represented by a system of equations in a number of ways, and every
system of equations can be solved, at least approximately, by various
algorithms.

As a teacher, I know very well what it means. Some representations are
easier to understand, or easier to work with, or easier to learn from.
Various thinkers, including Babbage, Whitehead, and Iverson, have
commented on the effects of the way we represent problems on our
ability to think about them, and not only they but luminaries from
Fibonacci to Einstein have labored to invent or teach new notations
and representations.

> This is very interesting.  Thanks for sending it.
>
> On Thu, Oct 16, 2008 at 7:14 PM, Massimo Di Pierro <mdipierro at cs.depaul.edu>
> wrote:
>>
>> Hi Paul,
>> this is a document I write as a summary of a meeting I attended in 2006 at
>> Argonne National Laboratory about revising the Physics curriculum. If it is
>> of any use you can do anything you want with it.
>> Massimo
>>
>>
>>
>> On Oct 16, 2008, at 5:55 PM, michel paul wrote:
>>
>> This would be a great text for a high school math/CS class:  Math for the
>> Digital Age.
>>
>> - Michel
>>
>> On Thu, Oct 16, 2008 at 4:15 AM, roberto <roberto03 at gmail.com> wrote:
>>>
>>> hello
>>> (i am rather new in python ...)
>>>
>>> i am about to start a course of physics and math for students aged
>>> 14-17 (high school)
>>> and i am deeply interested in the possibilty of teaching fundamental
>>> concepts of these subjects via teaching programming;
>>> i chose python (i won't change my mind ...)
>>>
>>> so i am looking for resources on how to deal with these topics via
>>> this great programming language;
>>>
>>> i need some help from you and moreover if you are aware of books
>>> already covering these need
>>>
>>> thank you in advance
>>> --
>>> roberto
>>> OS: GNU/Linux, Debian
>>> _______________________________________________
>>> Edu-sig mailing list
>>> Edu-sig at python.org
>>> http://mail.python.org/mailman/listinfo/edu-sig
>>
>> <ATT00001.txt>
>>
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>



-- 
Don't panic.--HHGTTG, Douglas Adams
fivethirtyeight.com, 3bluedudes.com Obama still moving ahead in EC!
http://www.obamapedia.org/page/Smears Join us!
http://wiki.sugarlabs.org/go/User:Mokurai For the children

Silent Thunder (??/??????????????? ) is my name
And Children are my nation.
The Cosmos is my dwelling place,
The Truth my destination.

From kent37 at tds.net  Sat Oct 18 13:47:15 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 18 Oct 2008 07:47:15 -0400
Subject: [Tutor] automatically generate python/pylons documentation
In-Reply-To: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
Message-ID: <1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>

On Fri, Oct 17, 2008 at 10:18 AM, Arun Tomar <tomar.arun at gmail.com> wrote:
> hi!
>
> I'm trying to generate documentation for my pylons web application.

> 2. epydoc
> I liked epydoc, the generated document looks more like what is
> generate by ruby tools, i guess rdoc. if i give it a single python
> file it works fine. but if i want epydoc to go into a specific folder
> & generate the documentation for all the files & files in the sub
> directories, it doesn't automatically do that. any pointers there.

I have used epydoc to create docs for entire packages by giving it the
package name on the command line. The package must be in the current
Python path.

Looking at epydoc's own makefile it appears that you can also specify
a directory.

Kent

From tomar.arun at gmail.com  Sat Oct 18 15:45:55 2008
From: tomar.arun at gmail.com (Arun Tomar)
Date: Sat, 18 Oct 2008 19:15:55 +0530
Subject: [Tutor] automatically generate python/pylons documentation
In-Reply-To: <1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
	<1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
Message-ID: <202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>

hi!

On Sat, Oct 18, 2008 at 5:17 PM, Kent Johnson <kent37 at tds.net> wrote:
> On Fri, Oct 17, 2008 at 10:18 AM, Arun Tomar <tomar.arun at gmail.com> wrote:
>> hi!
>>
>> I'm trying to generate documentation for my pylons web application.
>
>> 2. epydoc
>> I liked epydoc, the generated document looks more like what is
>> generate by ruby tools, i guess rdoc. if i give it a single python
>> file it works fine. but if i want epydoc to go into a specific folder
>> & generate the documentation for all the files & files in the sub
>> directories, it doesn't automatically do that. any pointers there.
>
> I have used epydoc to create docs for entire packages by giving it the
> package name on the command line. The package must be in the current
> Python path.
>
> Looking at epydoc's own makefile it appears that you can also specify
> a directory.

I've a pylons web application in the directory called helloworld.
if i give the command for epydoc to generate the documentation it
gives the below mentioned errors:

 epydoc helloworld/
  Error: Directory 'helloworld/' is not a package
  Error: Nothing left to document!

Can you guide me how can i accomplish this task.

> Kent
>

Regds,
Arun.

From marc.tompkins at gmail.com  Sat Oct 18 17:59:20 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sat, 18 Oct 2008 08:59:20 -0700
Subject: [Tutor] automatically generate python/pylons documentation
In-Reply-To: <202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
	<1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
	<202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>
Message-ID: <40af687b0810180859r5de8256aj11a05e7e97aad0f9@mail.gmail.com>

On Sat, Oct 18, 2008 at 6:45 AM, Arun Tomar <tomar.arun at gmail.com> wrote:

>
> I've a pylons web application in the directory called helloworld.
> if i give the command for epydoc to generate the documentation it
> gives the below mentioned errors:
>
>  epydoc helloworld/
>  Error: Directory 'helloworld/' is not a package
>  Error: Nothing left to document!
>
> Can you guide me how can i accomplish this task.
>

To turn a folder into a proper Python package, just create a file called
"__init__.py"
The file can be empty - that's probably good enough to let epydoc work
properly - but you can also add initialization and imports.

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081018/a9563721/attachment.htm>

From bgailer at gmail.com  Sat Oct 18 18:06:46 2008
From: bgailer at gmail.com (bob gailer)
Date: Sat, 18 Oct 2008 12:06:46 -0400
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>	<40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>	<F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>	<40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>
	<e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>
Message-ID: <48FA0996.7000800@gmail.com>

Edward Cherlin wrote:
> [snip]
>
> As a teacher, I know very well what it means. Some representations are
> easier to understand, or easier to work with, or easier to learn from.
> Various thinkers, including Babbage, Whitehead, and Iverson, have
> commented on the effects of the way we represent problems on our
> ability to think about them, and not only they but luminaries from
> Fibonacci to Einstein have labored to invent or teach new notations
> and representations.
>   
I'm glad to see Iverson amongst Babbage and Whitehead. In 1974 I was 
introduced to his invention: APL. That transformed how I thought about 
problems and expressed algorithms. I still wish for some way to bring 
some of that magic into Python.

I found it interesting to hear (in the migration to Python 3) that the 
Python reduce function was not used a lot or well understood. I 
certainly use and understand it.

A brief tutorial for any who have read this far and are curious: In 
Python one may combine the elements of a list using sum() (if the sum is 
desired). For other functions one uses reduce. To get the product of the 
elements of a list Y: reduce(operator.mul, Y). In APL reduce is / and 
multiply is x so one writes x/Y. (Classic APL had only upper case for 
names).

I can write and comprehend x/Y much faster than the wordy equivalent.

And Y can  be an array of 0 or more dimensions. +/Y computes the "row 
sum" giving an array of one less dimensions*. So if Y were:
1 2 3
4 5 6
the row sum is 6 15.
* if the number of dimensions is 0 (a "scalar" value) the result is the 
scalar value unchanged.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From gslindstrom at gmail.com  Sat Oct 18 16:58:10 2008
From: gslindstrom at gmail.com (Greg Lindstrom)
Date: Sat, 18 Oct 2008 09:58:10 -0500
Subject: [Tutor] PyCon 2009 (US) - Call for Tutorials
Message-ID: <a9f39a410810180758k687645c6pf1057047aa433a92@mail.gmail.com>

The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
"pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at <http://us.pycon
.org/2009/tutorials/proposals/>.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact pycon-tutorials at python.org.

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081018/2417999b/attachment.htm>

From MDiPierro at cs.depaul.edu  Sat Oct 18 16:31:38 2008
From: MDiPierro at cs.depaul.edu (Massimo Di Pierro)
Date: Sat, 18 Oct 2008 09:31:38 -0500
Subject: [Tutor] [Edu-sig] school physics/math courses
In-Reply-To: <e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>
	<F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>
	<40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>
	<e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>
Message-ID: <0AF6B568-EB3C-4D6D-921E-A67B3AB30EDA@cs.depaul.edu>



On Oct 18, 2008, at 12:03 AM, Edward Cherlin wrote:
> 2008/10/17 michel paul <mpaul213 at gmail.com>:
>> "We should abandon the vision that physicists seek an ultimate  
>> mathematical
>> description of the universe since it is not obvious that it exists.
>
> I disagree with this attitude. We can seek an ultimate mathematical
> description, since it is not obvious that it does not exist. We should
> also be aware that we do not have one, and have some idea of the range
> of validity of our models. This will help us to avoid mathematical
> absurdities, particularly the infinities that result from calculations
> on unphysical point masses and point charges.

a consequence of the Godel theorem is that even if a complete  
mathematical description of the universe exists, and we find it, we  
cannot prove it is complete. We can only prove it works for those  
phenomena we have observed.

I say the goal if to seek a comprehensive effective theory that  
describes and explains observed phenomena.

>
>> The job
>> of the physicist is that of modeling phenomena within the physical  
>> scales of
>> observed events.
>
> True much of the time. Another part of the job is to model outside the
> scale of the observed, and go make the new observations needed, as in
> the case of General Relativity.

General relativity describes observed phenomena. It was so even at  
times of Einstein (orbit of planets)

>
>> For some systems, the modeling can be done more effectively
>> using algorithms."
>
> As a mathematician, I don't know what that means. Every algorithm can
> be represented by a system of equations in a number of ways, and every
> system of equations can be solved, at least approximately, by various
> algorithms.

Mathematical formulas described relations between quantities.  
Algorithms described a process (for example a process to solve a  
mathematical formula).
If you believe you can find a ultimate model for everything, it has  
to be described in mathematical terms. If you believe you cannot do  
better than explain known events observed with a finite precision,  
then numerical algorithms provide an efficient way to model the  
physics. I am not saying one can have one without the other. I am  
saying it is easier to teach Newton's gravity using Euler's  
approximate algorithm that it is to do it using symbolic integration.


> As a teacher, I know very well what it means. Some representations are
> easier to understand, or easier to work with, or easier to learn from.
> Various thinkers, including Babbage, Whitehead, and Iverson, have
> commented on the effects of the way we represent problems on our
> ability to think about them, and not only they but luminaries from
> Fibonacci to Einstein have labored to invent or teach new notations
> and representations.

I agree.

Massimo

From xboxmuncher at gmail.com  Sat Oct 18 18:26:35 2008
From: xboxmuncher at gmail.com (xbmuncher)
Date: Sat, 18 Oct 2008 12:26:35 -0400
Subject: [Tutor] retrieving httponly cookies on accessing webpage with
	urllib2
In-Reply-To: <1c2a2c590810170429g11770242sb30b8112078af021@mail.gmail.com>
References: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>
	<1c2a2c590810170429g11770242sb30b8112078af021@mail.gmail.com>
Message-ID: <df531c470810180926r3d349a0cx307f6ac71b71c175@mail.gmail.com>

Thanks for the insight Kent. The problem wasn't because of the httpOnly
cookies, I just wasn't requesting the right page. I did get it to send me
the httpOnly cookies when I requested the right page. Apparently, the right
page was a redirection of the original page. When I used to use cURL in PHP
I remember that it had an option to automatically follow redirects. How can
I do this with urllib2?

For the headers, I did verify that it sent the headers as I had formed them
(just not in the right order) with wireshark. So my method does work, I also
got this method from here:
http://www.voidspace.org.uk/python/articles/urllib2.shtml#headers

On Fri, Oct 17, 2008 at 7:29 AM, Kent Johnson <kent37 at tds.net> wrote:

> On Thu, Oct 16, 2008 at 11:40 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> > I'm trying to mimic my firefox browser in requesting a webpage with
> python.
>
> > So I tried trusty ol' urllib2 to request it in python:
> > import urllib2
> >
> >
> > url = 'http://www.website.com'
> >
> > #headers
> > h = {
> > 'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> 1.9.0.3)
> <snip>
> > }
> > #request page
> > reqObj = urllib2.Request(url, None, h)
> > urlObj = urllib2.urlopen(reqObj)
>
> It doesn't work to set the User-Agent header this way. See
> http://personalpages.tds.net/~kent37/kk/00010.html#e10request-headers<http://personalpages.tds.net/%7Ekent37/kk/00010.html#e10request-headers>
> for a recipe.
>
> > #read response
> > print urlObj.read()
>
> What content do you get? Is it an error message? What does wireshark
> show for this request?
>
> > Notice the content length is considerably smaller, and no cookies are
> sent
> > to me like they were in firefox. I know only a little about httpOnly
> > cookies, but that it is some kind of special cookie that I suppose has
> > something to do with python not being able to access it like firefox. All
> I
> > want to do is have python receive the same cookies that firefox did, how
> can
> > I do this? I read somewhere that httpOnly cookies were implemented in the
> > python cookie module:
> > http://glyphobet.net/blog/blurb/285
> > ....yet the other cookies aren't being sent either...
>
> I don't think that has anything to do with your problem. httpOnly is
> set by the server and interpreted by the browser. The Python change
> was to allow httpOnly to be set by servers written in Python.
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081018/78392b04/attachment.htm>

From alan.gauld at btinternet.com  Sat Oct 18 19:12:14 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 18 Oct 2008 18:12:14 +0100
Subject: [Tutor] automatically generate python/pylons documentation
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com><1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
	<202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>
Message-ID: <gdd5d9$vjh$1@ger.gmane.org>

"Arun Tomar" <tomar.arun at gmail.com> wrote 

> if i give the command for epydoc to generate the documentation it
> gives the below mentioned errors:
> 
> epydoc helloworld/
>  Error: Directory 'helloworld/' is not a package
>  Error: Nothing left to document!

What happens if you don;t pass the trainiling slash:

epydoc helloworld

Alrternatively just make it a package by creating 
an init.py file as suggested by Marc

Alan G


From kent37 at tds.net  Sat Oct 18 19:32:23 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 18 Oct 2008 13:32:23 -0400
Subject: [Tutor] retrieving httponly cookies on accessing webpage with
	urllib2
In-Reply-To: <df531c470810180926r3d349a0cx307f6ac71b71c175@mail.gmail.com>
References: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>
	<1c2a2c590810170429g11770242sb30b8112078af021@mail.gmail.com>
	<df531c470810180926r3d349a0cx307f6ac71b71c175@mail.gmail.com>
Message-ID: <1c2a2c590810181032u4945510bhc7921bf26ed041c8@mail.gmail.com>

On Sat, Oct 18, 2008 at 12:26 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> Apparently, the right
> page was a redirection of the original page. When I used to use cURL in PHP
> I remember that it had an option to automatically follow redirects. How can
> I do this with urllib2?

urllib2 will follow HTTP redirects (30x status codes). It won't follow
redirects in <meta> tags or JavaScript. The fetch_html() function here
will follow some <meta> redirects:
http://code.google.com/p/blogmaker/source/browse/trunk/blogmaker/util/fetch.py

> For the headers, I did verify that it sent the headers as I had formed them
> (just not in the right order) with wireshark. So my method does work, I also
> got this method from here:
> http://www.voidspace.org.uk/python/articles/urllib2.shtml#headers

OK. I have definitely had trouble with that in the past but maybe it
is fixed now.

Kent

From kent37 at tds.net  Sat Oct 18 21:43:45 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 18 Oct 2008 15:43:45 -0400
Subject: [Tutor] retrieving httponly cookies on accessing webpage with
	urllib2
In-Reply-To: <1c2a2c590810181032u4945510bhc7921bf26ed041c8@mail.gmail.com>
References: <df531c470810162040j42281cc8ga873c9821424113c@mail.gmail.com>
	<1c2a2c590810170429g11770242sb30b8112078af021@mail.gmail.com>
	<df531c470810180926r3d349a0cx307f6ac71b71c175@mail.gmail.com>
	<1c2a2c590810181032u4945510bhc7921bf26ed041c8@mail.gmail.com>
Message-ID: <1c2a2c590810181243r104f1b7q64093837d118294b@mail.gmail.com>

On Sat, Oct 18, 2008 at 1:32 PM, Kent Johnson <kent37 at tds.net> wrote:
>> For the headers, I did verify that it sent the headers as I had formed them
>> (just not in the right order) with wireshark. So my method does work, I also
>> got this method from here:
>> http://www.voidspace.org.uk/python/articles/urllib2.shtml#headers
>
> OK. I have definitely had trouble with that in the past but maybe it
> is fixed now.

I guess I have been using urllib2 for a while, this bug was fixed in 2002 :-)
http://bugs.python.org/issue599836

Kent

From tomar.arun at gmail.com  Sun Oct 19 04:52:22 2008
From: tomar.arun at gmail.com (Arun Tomar)
Date: Sun, 19 Oct 2008 08:22:22 +0530
Subject: [Tutor] automatically generate python/pylons documentation
In-Reply-To: <gdd5d9$vjh$1@ger.gmane.org>
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
	<1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
	<202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>
	<gdd5d9$vjh$1@ger.gmane.org>
Message-ID: <202c460810181952r1f9f08h324c1faf9e49a3eb@mail.gmail.com>

hi!

On Sat, Oct 18, 2008 at 10:42 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Arun Tomar" <tomar.arun at gmail.com> wrote
>>
>> if i give the command for epydoc to generate the documentation it
>> gives the below mentioned errors:
>>
>> epydoc helloworld/
>>  Error: Directory 'helloworld/' is not a package
>>  Error: Nothing left to document!
>
> What happens if you don;t pass the trainiling slash:
>
> epydoc helloworld

if i do not give a trailing slash, the output is like this
epydoc helloworld
+-----------------------------------------------------------------------------------------------------------------------
| In helloworld:
| No documentation available!
|     Error: Import failed:
|            ImportError: No module named helloworld
|
  Error: Nothing left to document!

>
> Alrternatively just make it a package by creating an init.py file as
> suggested by Marc
>
> Alan G

creating a __init__.py file does the trick but not completely.
 epydoc helloworld
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/setup.py:
| Import failed (but source code parsing was successful).
|     Error: SystemExit: usage: (imported) [global_opts] cmd1
[cmd1_opts] [cmd2 [cmd2_opts] ...]
|               or: (imported) --help [cmd1 cmd2 ...]
|               or: (imported) --help-commands
|               or: (imported) cmd --help
|
|            error: no commands supplied (line 30)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/websetup.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named config.environment (line 7)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/config/middleware.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named config.environment (line 13)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/config/environment.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named lib.app_globals (line 6)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/controllers/template.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named lib.base (line 1)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/controllers/error.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named lib.base (line 6)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/tests/__init__.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named config.middleware (line 33)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/tests/test_models.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named config.middleware (line 33)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/tests/functional/__init__.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named config.middleware (line 33)
|
+-----------------------------------------------------------------------------------------------------------------------
| In /tmp/helloworld/helloworld/lib/base.py:
| Import failed (but source code parsing was successful).
|     Error: ImportError: No module named lib.helpers (line 13)
|
Warning: No information available for
helloworld.helloworld.lib.base.BaseController's base
         pylons.controllers.WSGIController
Warning: 1 markup error was found while processing docstrings.  Use
the verbose switch (-v) to display markup errors.

this creates a directory with the documentation which is working but
as you can see there are some import errors.

regds,
arun

From kent37 at tds.net  Sun Oct 19 06:54:35 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 19 Oct 2008 00:54:35 -0400
Subject: [Tutor] automatically generate python/pylons documentation
In-Reply-To: <202c460810181952r1f9f08h324c1faf9e49a3eb@mail.gmail.com>
References: <202c460810170718j202c37ffx2fd43df157c7cf45@mail.gmail.com>
	<1c2a2c590810180447y51139c80h6752e3aea2c9d006@mail.gmail.com>
	<202c460810180645x1f61c437ta76de1fef2fb832f@mail.gmail.com>
	<gdd5d9$vjh$1@ger.gmane.org>
	<202c460810181952r1f9f08h324c1faf9e49a3eb@mail.gmail.com>
Message-ID: <1c2a2c590810182154o4a2dc2feoc72c962fa180d542@mail.gmail.com>

On Sat, Oct 18, 2008 at 10:52 PM, Arun Tomar <tomar.arun at gmail.com> wrote:

> creating a __init__.py file does the trick but not completely.
>  epydoc helloworld
> +-----------------------------------------------------------------------------------------------------------------------
> | In /tmp/helloworld/setup.py:
> | Import failed (but source code parsing was successful).
> |     Error: SystemExit: usage: (imported) [global_opts] cmd1
> [cmd1_opts] [cmd2 [cmd2_opts] ...]
> |               or: (imported) --help [cmd1 cmd2 ...]
> |               or: (imported) --help-commands
> |               or: (imported) cmd --help
> |
> |            error: no commands supplied (line 30)

By default epydoc imports all the modules it is documenting. This may
give errors, if the Python path is not set correctly for dependent
imports to work, and it may cause side effects, if the modules have
code that executes on import.

The --parse-only switch tells epydoc to forgo the import and just
parse the input.

Kent

From joefazee at gmail.com  Sun Oct 19 06:59:19 2008
From: joefazee at gmail.com (Abah Joseph)
Date: Sun, 19 Oct 2008 06:59:19 +0200
Subject: [Tutor] Creating a single .exe file without py2exe and pyinstaller
Message-ID: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>

I have written a small application of about 40-45 lines which is about 4KB,
so I want to create a single .exe file from it, using py2exe it created
unnecessary files, that just increase the size of the program and also less
portable to me. What else can I use?
I am on windows XP.
Python 2.5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/ed26fe86/attachment.htm>

From kirby.urner at gmail.com  Sun Oct 19 07:22:24 2008
From: kirby.urner at gmail.com (kirby urner)
Date: Sat, 18 Oct 2008 22:22:24 -0700
Subject: [Tutor] [Edu-sig]  school physics/math courses
In-Reply-To: <e574f6eb0810181657n12d18991ob77424b662cf063@mail.gmail.com>
References: <4bcde3e10810160415j29aaf0f3t4f0de060ddb3652f@mail.gmail.com>
	<40ea4eb00810161555uf9e94deg81e78ebe7c2f0bb1@mail.gmail.com>
	<F8FFEEB6-6FC8-4BD8-B096-EF1707C4C548@cs.depaul.edu>
	<40ea4eb00810172130h2ebb4839ke02e188103e2b6fe@mail.gmail.com>
	<e574f6eb0810172203ib937a42h272a4711389f5806@mail.gmail.com>
	<48FA0996.7000800@gmail.com>
	<e574f6eb0810181657n12d18991ob77424b662cf063@mail.gmail.com>
Message-ID: <f604188c0810182222k327e55d0je410021e8c07f78c@mail.gmail.com>

On Sat, Oct 18, 2008 at 4:57 PM, Edward Cherlin <echerlin at gmail.com> wrote:
> On Sat, Oct 18, 2008 at 9:06 AM, bob gailer <bgailer at gmail.com> wrote:

<< SNIP >>

>> I'm glad to see Iverson amongst Babbage and Whitehead.
>
> Turing Award lecture, Notation as a Tool of Thought.
>
>> In 1974 I was
>> introduced to his invention: APL. That transformed how I thought about
>> problems and expressed algorithms. I still wish for some way to bring some
>> of that magic into Python.
>
> See NumPy and SciPy, which used APL for some design ideas. If we can
> get some people together on this idea, we can add more APL to Python.
>
> Perl6 will have some of this, but that's a knotty business that I am
> staying out of.
>
> I'm working on getting a GPLed APL for the OLPC XO. Arthur Whitney is
> writing one. I was the founder of I-APL, Ltd, and Managing Editor of
> APL News for Springer-Verlag. I have the copyrights on Iverson's
> textbooks for Arithmetic, Algebra, and Calculus, and intend to put
> them out under Creative Commons licenses.
>
> I need to recruit more people--mathematicians, teachers, APLers, and
> others--to work on these projects.
>

I see Python as a lot like APL, in terms of small, action-packed
units, e.g. data structures, with highly orthogonal (combinatorially
rich) behaviors.

I've worked with Iverson on J, admire Roger Hui's math teaching in
that language.  APL was a first love thought, showed me that not every
language is like FORTRAN, praise Allah.

http://www.4dsolutions.net/ocn/cp4e.html is mostly Python, but there's
some J there too.  In my model intro class, I envision Python and J as
a "dynamic duo" in that they give students a sense of the spectrum,
the broad range among computer languages -- not saying other dynamic
duos not up to the job, go for it etc.

Kirby

From jgowen at lorettotel.net  Sun Oct 19 15:52:48 2008
From: jgowen at lorettotel.net (Johnny)
Date: Sun, 19 Oct 2008 08:52:48 -0500
Subject: [Tutor] How to clear the screen
Message-ID: <48FB3BB0.1040107@lorettotel.net>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/f1afcd07/attachment.htm>

From drbloodmoney at gmail.com  Sun Oct 19 16:08:25 2008
From: drbloodmoney at gmail.com (DrBloodmoney)
Date: Sun, 19 Oct 2008 10:08:25 -0400
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
In-Reply-To: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
Message-ID: <ba5b5f050810190708o6e4943d2ne9989e18dd67126d@mail.gmail.com>

Pyinstaller:

http://pyinstaller.python-hosting.com/

On Sun, Oct 19, 2008 at 12:59 AM, Abah Joseph <joefazee at gmail.com> wrote:
>
> I have written a small application of about 40-45 lines which is about 4KB,
> so I want to create a single .exe file from it, using py2exe it created
> unnecessary files, that just increase the size of the program and also less
> portable to me. What else can I use?
>
> I am on windows XP.
> Python 2.5
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From bermanrl at embarqmail.com  Sun Oct 19 16:51:34 2008
From: bermanrl at embarqmail.com (Robert Berman)
Date: Sun, 19 Oct 2008 10:51:34 -0400
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
In-Reply-To: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
Message-ID: <48FB4976.1070203@embarqmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/6b6b4787/attachment.htm>

From marc.tompkins at gmail.com  Sun Oct 19 18:03:47 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 19 Oct 2008 09:03:47 -0700
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
In-Reply-To: <48FB4976.1070203@embarqmail.com>
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
	<48FB4976.1070203@embarqmail.com>
Message-ID: <40af687b0810190903m6b4d6560hb32a68694673fa89@mail.gmail.com>

On Sun, Oct 19, 2008 at 7:51 AM, Robert Berman <bermanrl at embarqmail.com>wrote:

>  If you want a real exe rewrite it in C or C++. Python is an interpretive
> language; my apologies to those who say it is 'semi-compilable'.
>

Let me re-word that a little bit.
When you write an application in Python, you are actually writing a "script"
that will be "interpreted" by Python at run-time (Python _must_ be installed
and running) - so Python is called a "scripting" or "interpreted" language.
This is different from writing it in a "compiled" language like C, C++, etc.
There are advantages and disadvantages to both approaches; Pythonistas tend
to find that the advantages of the Python way outweigh the disadvantages.

When you write a program in anything higher-level than machine code, you're
borrowing from millions and millions of man-hours of programming expertise.
I have no idea what your 40-45 line script does, but even in "Hello World"
there's a lot going on that you aren't aware of unless you're writing
machine code (even assembly language masks _some_ of the complexity):
-  Memory allocation
-  String manipulation
-  I/O
and a bunch of stuff I'm forgetting.  This stuff doesn't just happen -
computers don't automatically understand _anything_ - they have to be taught
very explicitly, and that requires a lot of code.  If you were writing in C
(for example), that code would be in the form of libraries which would
either be linked into your EXE (making it much bigger than you'd expect it
to be), or would have to be distributed alongside as DLLs.  In Python, it's
modules and the Python interpreter.  In either case, when you write even the
simplest program, it requires lots and lots of other people's code to run.

When you distribute your script to users, they can't run it unless they have
Python on their machines.  Pyinstaller gathers up your script and all of its
dependencies and makes an installable package out of them; Py2EXE bundles
that up with a minimal distribution of Python so your user only has to run
one installer.  That's what all of those "unnecessary files" are.


-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/66fbf666/attachment.htm>

From cfuller084 at thinkingplanet.net  Sun Oct 19 18:16:50 2008
From: cfuller084 at thinkingplanet.net (Chris Fuller)
Date: Sun, 19 Oct 2008 11:16:50 -0500
Subject: [Tutor] How to clear the screen
In-Reply-To: <48FB3BB0.1040107@lorettotel.net>
References: <48FB3BB0.1040107@lorettotel.net>
Message-ID: <200810191116.50440.cfuller084@thinkingplanet.net>


There are a couple of approaches here.  You could use a screen control library 
like slang or curses (curses is in the standard library), but that is usually 
overkill if you aren't creating a moderately complex interface.  If you just 
want to clear the screen, printing the control sequence ESC[2J is all you 
need.

>>> print chr(0x1b) + '[2J'

http://www.python.org/pyvault/SRPMS/repodata/repoview/python-newt-0-0.52.0-2.html
http://www.wanware.com/tsgdocs/snack.html
http://docs.python.org/library/curses.html
http://www.termsys.demon.co.uk/vtansi.htm

Cheers

From cfuller084 at thinkingplanet.net  Sun Oct 19 18:26:39 2008
From: cfuller084 at thinkingplanet.net (Chris Fuller)
Date: Sun, 19 Oct 2008 11:26:39 -0500
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
In-Reply-To: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
Message-ID: <200810191126.39568.cfuller084@thinkingplanet.net>


The freeze utillity, http://wiki.python.org/moin/Freeze, will do what you 
want, on unixlikes, at least.  It has its own set of caveats, of course.  You 
need a C compiler, and preferably the same one that was used to compile the 
Python interpreter.  I'm not sure if it works at all on Windoze.

Cheers

From tvbare at wildblue.net  Sun Oct 19 18:13:12 2008
From: tvbare at wildblue.net (-> Terry <-)
Date: Sun, 19 Oct 2008 11:13:12 -0500 (CDT)
Subject: [Tutor] How to clear the screen
In-Reply-To: <48FB3BB0.1040107@lorettotel.net>
References: <48FB3BB0.1040107@lorettotel.net>
Message-ID: <Pine.LNX.4.64.0810191110090.6619@elwood.hillbillyhaven.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Oct 19, 2008 at 8:52am, -Johnny- signaled in from cyberspace:

- ->Hey friends....
- ->I am a raw beginner that is going through my first tutorial book.
- ->As a personal project, I am trying to write a study program as I progress
- ->through my studies.
- ->
- ->In this program, it would be really neat if their was a way to clear the
- ->screen off.
- ->I have inserrted comments as to where I'd like the screen to be cleared.
- ->
- ->Here is the program.....
- ->And PLEASE,, don't laugh. LOL

Hi Johnny! Even the gurus on this list were beginners
at one time. Try this:

print "\n" * 40

- -- 
    Terry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFI+1yaOP+8GDe6jtYRAjhYAJ9rnhTCSfIoTtrjaREQrCB9gpF+qQCgze1u
GPZ1cgUomMjU8qJnY78AG1A=
=9662
-----END PGP SIGNATURE-----


From marc.tompkins at gmail.com  Sun Oct 19 18:52:10 2008
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 19 Oct 2008 09:52:10 -0700
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
In-Reply-To: <200810191126.39568.cfuller084@thinkingplanet.net>
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
	<200810191126.39568.cfuller084@thinkingplanet.net>
Message-ID: <40af687b0810190952u19f0a00bsf855f304ddec666e@mail.gmail.com>

On Sun, Oct 19, 2008 at 9:26 AM, Chris Fuller <cfuller084 at thinkingplanet.net
> wrote:

>
> The freeze utillity, http://wiki.python.org/moin/Freeze, will do what you
> want, on unixlikes, at least.  It has its own set of caveats, of course.
>  You
> need a C compiler, and preferably the same one that was used to compile the
> Python interpreter.  I'm not sure if it works at all on Windoze.
>

>From the very page you referenced:
See Also

   -

   Py2Exe <http://wiki.python.org/moin/Py2Exe> -- like Freeze, but makes
   Windows executables

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/bdca2e33/attachment.htm>

From rob.rstevenson at gmail.com  Sun Oct 19 23:53:03 2008
From: rob.rstevenson at gmail.com (Rob Stevenson)
Date: Sun, 19 Oct 2008 22:53:03 +0100
Subject: [Tutor] Can't start IDLE 2.6 on Mac
Message-ID: <3e12fcbf0810191453r5e28da87uf206f6d679be56d3@mail.gmail.com>

Hello,

A slightly different question.  I use python on vista but recently bought a
mac laptop running tiger so I could use garageband.

I decided to put 2.6 on it but even though it installs fine, when I go to
Applications / Python 2.6 and double click IDLE, nothing happens.

Am I doing something wrong?  Unfortunately I'm very new to Macs so although
I'd be happy to investigate logs, registry etc on Windows, I don't know
where to begin on OSX.

Other progs I've installed in this way work fine, btw,

Thanks
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081019/a12442a8/attachment.htm>

From WFERGUSON1 at SOCAL.RR.COM  Mon Oct 20 01:17:52 2008
From: WFERGUSON1 at SOCAL.RR.COM (WM)
Date: Sun, 19 Oct 2008 16:17:52 -0700
Subject: [Tutor] RUNNING A PROGRAM
Message-ID: <48FBC020.1020602@SOCAL.RR.COM>

a = "Futzenburgerstein"
b = ( 7 + 2 ) / 3
c = b / 2
print a, b, c

The above text was copied from a window named
"??futz.py-C:\Python26\futz.py"  The ?? is two red
script characters which I cannot read.  When I go
'F5' or Run > Run Module I get kicked back into IDLE.
Shouldn't 'F5' get me a window with a, b & c printed
all in a row?


From alan.gauld at btinternet.com  Mon Oct 20 10:02:06 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 09:02:06 +0100
Subject: [Tutor] Creating a single .exe file without py2exe and
	pyinstaller
References: <ea09b3700810182159j13660194g1c6b447d45d16050@mail.gmail.com>
Message-ID: <gdhdtr$1vj$1@ger.gmane.org>


"Abah Joseph" <joefazee at gmail.com> wrote

>I have written a small application of about 40-45 lines which is 
>about 4KB,
> so I want to create a single .exe file from it, using py2exe it 
> created
> unnecessary files, that just increase the size of the program and 
> also less
> portable to me.

What kind of extra files?
One of Py2exe's main jobs is to strip out all the unnecessary
files and only bundle up those that are needed.

Have you tried installing the exe without the extra files? Does it 
still
work on a PC without Python already installed?

Py2exe usually does a pretty good job and has been around for
such a long time I'm surprised its producing any extras.

Curious,

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



From alan.gauld at btinternet.com  Mon Oct 20 10:10:43 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 09:10:43 +0100
Subject: [Tutor] How to clear the screen
References: <48FB3BB0.1040107@lorettotel.net>
Message-ID: <gdhee0$53q$1@ger.gmane.org>


"Johnny" <jgowen at lorettotel.net> wrote

> In this program, it would be really neat if their was a way to clear 
> the screen off.
> I have inserrted comments as to where I'd like the screen to be 
> cleared.

Such a simple question. Such a complex answer :-)

It all depends on what OS and terminal setup you are using.

If its windows you can do several things:
1) call the DOS CLS command using os.system() or similar
2) send the ANSI clear screen control code to the DOS window
   (if ANSI.SYS is installed)
3) send a lot of \ns to the screeen (simplest and most portable but 
slower)
4) Use a  3rd party screen handling module

If its Linux/MacOS/*nix:
You can use similar but slightly different tricks
1) call the Unix clear command
2) Send the clear screen control codes as determined by termcap
3) Send a lot of \n to screen
4) use the curses module to control the screen

Personally I'd go for 3 and write something like:

def cls(n=50): print "\n" * n

HTH,

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



From alan.gauld at btinternet.com  Mon Oct 20 10:13:20 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 09:13:20 +0100
Subject: [Tutor] How to clear the screen
References: <48FB3BB0.1040107@lorettotel.net>
	<200810191116.50440.cfuller084@thinkingplanet.net>
Message-ID: <gdheit$5kv$1@ger.gmane.org>

"Chris Fuller" <cfuller084 at thinkingplanet.net> wrote

> want to clear the screen, printing the control sequence ESC[2J is 
> all you
> need.
>
>>>> print chr(0x1b) + '[2J'

Only on *nix with a VT100 compatible terminal.
Doesn't work for vanilla DOS window or Tektronix mode
terminals, 3270 etc.

Thats why screen control is such a messy topic.

Alan G.




From alan.gauld at btinternet.com  Mon Oct 20 11:55:05 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 10:55:05 +0100
Subject: [Tutor] Can't start IDLE 2.6 on Mac
References: <3e12fcbf0810191453r5e28da87uf206f6d679be56d3@mail.gmail.com>
Message-ID: <gdhkhn$q7t$1@ger.gmane.org>

"Rob Stevenson" <rob.rstevenson at gmail.com> wrote

> I decided to put 2.6 on it but even though it installs fine, when I 
> go to
> Applications / Python 2.6 and double click IDLE, nothing happens.

Does basic Python work?
If you open the Terminal application and type python at the prompt
does it come up? And is it the 2.6 uinstall or the pre-installed 
2.3(?)

> Am I doing something wrong?  Unfortunately I'm very new to Macs so 
> although
> I'd be happy to investigate logs, registry etc on Windows, I don't 
> know
> where to begin on OSX.

I would strongly recommend a copy of the OS X Missing Manual book.
And then, if you intend doing any coding type work on Mac,  the
Mac OS X Hacks book from O'Reilly.

Which version of Python did you install? Was it MacPython or
ActiveState's Mac distro?

You might also need to start X windows running first if you don't
have the Cocoa version of Tk installed. I can't remember which
distros have which Tk...

IDLE on Mac is somewhat disappointing in my experience!

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



From alan.gauld at btinternet.com  Mon Oct 20 11:58:01 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 10:58:01 +0100
Subject: [Tutor] RUNNING A PROGRAM
References: <48FBC020.1020602@SOCAL.RR.COM>
Message-ID: <gdhkn6$qo4$1@ger.gmane.org>


"WM" <WFERGUSON1 at SOCAL.RR.COM> wrote

>a = "Futzenburgerstein"
> b = ( 7 + 2 ) / 3
> c = b / 2
> print a, b, c
> 
> The above text was copied from a window named
> "??futz.py-C:\Python26\futz.py"  The ?? is two red
> script characters which I cannot read.  When I go
> 'F5' or Run > Run Module I get kicked back into IDLE.
> Shouldn't 'F5' get me a window with a, b & c printed
> all in a row?

The output should appear in the shell window.

Alan G


From kent37 at tds.net  Mon Oct 20 12:42:01 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 20 Oct 2008 06:42:01 -0400
Subject: [Tutor] Can't start IDLE 2.6 on Mac
In-Reply-To: <3e12fcbf0810191453r5e28da87uf206f6d679be56d3@mail.gmail.com>
References: <3e12fcbf0810191453r5e28da87uf206f6d679be56d3@mail.gmail.com>
Message-ID: <1c2a2c590810200342x5fc25b48yb1e6e9e0fb98b7c1@mail.gmail.com>

On Sun, Oct 19, 2008 at 5:53 PM, Rob Stevenson <rob.rstevenson at gmail.com> wrote:
> Hello,
>
> A slightly different question.  I use python on vista but recently bought a
> mac laptop running tiger so I could use garageband.
>
> I decided to put 2.6 on it but even though it installs fine, when I go to
> Applications / Python 2.6 and double click IDLE, nothing happens.

Unfortunately there is a problem with the Mac release of Python 2.6
and Tkinter (which IDLE uses) does not work correctly. The only fix at
this point is to use 2.5 or to build Python yourself.
http://bugs.python.org/issue4017

I hope there will be an official release that fixes this soon, it
seems like a serious problem to me.

Kent

From srilyk at gmail.com  Mon Oct 20 12:45:57 2008
From: srilyk at gmail.com (W W)
Date: Mon, 20 Oct 2008 05:45:57 -0500
Subject: [Tutor] How to clear the screen
In-Reply-To: <gdheit$5kv$1@ger.gmane.org>
References: <48FB3BB0.1040107@lorettotel.net>
	<200810191116.50440.cfuller084@thinkingplanet.net>
	<gdheit$5kv$1@ger.gmane.org>
Message-ID: <333efb450810200345u1526e739kb5cdb998f68c2b26@mail.gmail.com>

On Mon, Oct 20, 2008 at 3:13 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "Chris Fuller" <cfuller084 at thinkingplanet.net> wrote
>
>  want to clear the screen, printing the control sequence ESC[2J is all you
>> need.
>>
>>  print chr(0x1b) + '[2J'
>>>>>
>>>>
I don't know if this is the most graceful solution... but it seems to work:
import os

if os.system('cls') == 0:
    pass
elif os.system('clear') == 0:
    pass
else:
    print 'No clear command available'

That should take care of most of your OS' out there...

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/f904e9a5/attachment.htm>

From bgailer at gmail.com  Mon Oct 20 14:14:33 2008
From: bgailer at gmail.com (bob gailer)
Date: Mon, 20 Oct 2008 08:14:33 -0400
Subject: [Tutor] How to clear the screen
In-Reply-To: <333efb450810200345u1526e739kb5cdb998f68c2b26@mail.gmail.com>
References: <48FB3BB0.1040107@lorettotel.net>	<200810191116.50440.cfuller084@thinkingplanet.net>	<gdheit$5kv$1@ger.gmane.org>
	<333efb450810200345u1526e739kb5cdb998f68c2b26@mail.gmail.com>
Message-ID: <48FC7629.7080103@gmail.com>

W W wrote:
> On Mon, Oct 20, 2008 at 3:13 AM, Alan Gauld <alan.gauld at btinternet.com 
> <mailto:alan.gauld at btinternet.com>> wrote:
>
>     "Chris Fuller" <cfuller084 at thinkingplanet.net
>     <mailto:cfuller084 at thinkingplanet.net>> wrote
>
>
>         want to clear the screen, printing the control sequence ESC[2J
>         is all you
>         need.
>
>                     print chr(0x1b) + '[2J'
>
>
> I don't know if this is the most graceful solution... but it seems to 
> work:
>
> import os
>
> if os.system('cls') == 0:
>     pass
> elif os.system('clear') == 0:
>     pass
> else:
>     print 'No clear command available'
>
I'd prefer, for compactness and readability:

if not os.system('cls'):
  if not os.system('clear'):
   print 'No clear command available'


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From foobar8 at gmail.com  Mon Oct 20 16:39:59 2008
From: foobar8 at gmail.com (=?ISO-8859-1?Q?Siim_M=E4rtmaa?=)
Date: Mon, 20 Oct 2008 17:39:59 +0300
Subject: [Tutor] Printing concatenated unicode strings
Message-ID: <76f6cc7c0810200739o376bb1b8s691277dcf8a2ac3b@mail.gmail.com>

Hello

i would like to do this

>>> print u'\u30fa'
?

with a method like this

b = "30fa"
uni = u'\u' + b + '\''

but it prints this

UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in
position 0-1: end of string in escape sequence

so how to concatenate properly to print the character ?

I want to do this to print the characters in a loop so that b would change

From mail at timgolden.me.uk  Mon Oct 20 16:43:47 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Mon, 20 Oct 2008 15:43:47 +0100
Subject: [Tutor] Printing concatenated unicode strings
In-Reply-To: <76f6cc7c0810200739o376bb1b8s691277dcf8a2ac3b@mail.gmail.com>
References: <76f6cc7c0810200739o376bb1b8s691277dcf8a2ac3b@mail.gmail.com>
Message-ID: <48FC9923.30906@timgolden.me.uk>

Siim M?rtmaa wrote:
> i would like to do this
> 
>>>> print u'\u30fa'
> ?
> 
> with a method like this
> 
> b = "30fa"
> uni = u'\u' + b + '\''
> 
> but it prints this
> 
> UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in
> position 0-1: end of string in escape sequence
> 
> so how to concatenate properly to print the character ?
> 
> I want to do this to print the characters in a loop so that b would change


>>> help (unichr)
Help on built-in function unichr in module __builtin__:

unichr(...)
    unichr(i) -> Unicode character

    Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

>>>


TJG

From nephish at gmail.com  Mon Oct 20 17:47:43 2008
From: nephish at gmail.com (shawn bright)
Date: Mon, 20 Oct 2008 10:47:43 -0500
Subject: [Tutor] how to see a number as two bytes
Message-ID: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>

hey there all,
i have a script that needs to send a number as two bytes.
how would i be able to see a number expressed as a hi byte and a lo byte?

thanks
shawn

From rabidpoobear at gmail.com  Mon Oct 20 18:00:36 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 20 Oct 2008 11:00:36 -0500
Subject: [Tutor] Fwd:  how to see a number as two bytes
In-Reply-To: <dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
Message-ID: <dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>

---------- Forwarded message ----------
From: Luke Paireepinart <rabidpoobear at gmail.com>
Date: Mon, Oct 20, 2008 at 11:00 AM
Subject: Re: [Tutor] how to see a number as two bytes
To: shawn bright <nephish at gmail.com>


high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.

On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
> hey there all,
> i have a script that needs to send a number as two bytes.
> how would i be able to see a number expressed as a hi byte and a lo byte?
>
> thanks
> shawn
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From nephish at gmail.com  Mon Oct 20 18:04:06 2008
From: nephish at gmail.com (shawn bright)
Date: Mon, 20 Oct 2008 11:04:06 -0500
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
Message-ID: <384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>

so using this, if num ==6, then i should get 2 and 88 ?
thanks, just checking to make sure i get what you wrote.
shawn

On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
> ---------- Forwarded message ----------
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> Date: Mon, Oct 20, 2008 at 11:00 AM
> Subject: Re: [Tutor] how to see a number as two bytes
> To: shawn bright <nephish at gmail.com>
>
>
> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>
> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>> hey there all,
>> i have a script that needs to send a number as two bytes.
>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>
>> thanks
>> shawn
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From nephish at gmail.com  Mon Oct 20 18:20:11 2008
From: nephish at gmail.com (shawn bright)
Date: Mon, 20 Oct 2008 11:20:11 -0500
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <dfeb4470810200916p61c7a50fuc00132a127a49b17@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
	<384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
	<dfeb4470810200916p61c7a50fuc00132a127a49b17@mail.gmail.com>
Message-ID: <384c93600810200920h5e356fecn53ada15d098cd615@mail.gmail.com>

jeez, i screwed up, i ment num = 600, not 6
thanks

On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
> No, I'm not sure what you mean.
> Given this number
>
> 100101010101101011
>
> the operation will slice off bits on the left with the % 2**16 so that
> we only have 16 bits,
> 0101010101101011
> then it will shift this value to the right so that we only have the
> highest 8 bits
> 01010101
> that will be stored in high.
> Then it will slice off the bits on the left with the 2**8 so that we
> only have 8 bits left,
> 01101011
> and that is your low value.
>
> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <nephish at gmail.com> wrote:
>> so using this, if num ==6, then i should get 2 and 88 ?
>> thanks, just checking to make sure i get what you wrote.
>> shawn
>>
>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>> <rabidpoobear at gmail.com> wrote:
>>> ---------- Forwarded message ----------
>>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>>> Date: Mon, Oct 20, 2008 at 11:00 AM
>>> Subject: Re: [Tutor] how to see a number as two bytes
>>> To: shawn bright <nephish at gmail.com>
>>>
>>>
>>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>>
>>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>>>> hey there all,
>>>> i have a script that needs to send a number as two bytes.
>>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>>
>>>> thanks
>>>> shawn
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>

From nephish at gmail.com  Mon Oct 20 18:23:53 2008
From: nephish at gmail.com (shawn bright)
Date: Mon, 20 Oct 2008 11:23:53 -0500
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <dfeb4470810200923m4e2563ddvc20b342389c746d3@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
	<384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
	<dfeb4470810200916p61c7a50fuc00132a127a49b17@mail.gmail.com>
	<384c93600810200920h5e356fecn53ada15d098cd615@mail.gmail.com>
	<dfeb4470810200923m4e2563ddvc20b342389c746d3@mail.gmail.com>
Message-ID: <384c93600810200923t632e4270v5ee2f4136fe215ea@mail.gmail.com>

thanks, Luke,
got me started anyway.
shawn

On Mon, Oct 20, 2008 at 11:23 AM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
> I'm not sure if those values are correct;  I can check later tonight,
> but I'm doing some statechart diagrams for class right now.  They
> sound reasonable but I can't be sure.
>
> On Mon, Oct 20, 2008 at 11:20 AM, shawn bright <nephish at gmail.com> wrote:
>> jeez, i screwed up, i ment num = 600, not 6
>> thanks
>>
>> On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
>> <rabidpoobear at gmail.com> wrote:
>>> No, I'm not sure what you mean.
>>> Given this number
>>>
>>> 100101010101101011
>>>
>>> the operation will slice off bits on the left with the % 2**16 so that
>>> we only have 16 bits,
>>> 0101010101101011
>>> then it will shift this value to the right so that we only have the
>>> highest 8 bits
>>> 01010101
>>> that will be stored in high.
>>> Then it will slice off the bits on the left with the 2**8 so that we
>>> only have 8 bits left,
>>> 01101011
>>> and that is your low value.
>>>
>>> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <nephish at gmail.com> wrote:
>>>> so using this, if num ==6, then i should get 2 and 88 ?
>>>> thanks, just checking to make sure i get what you wrote.
>>>> shawn
>>>>
>>>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>>>> <rabidpoobear at gmail.com> wrote:
>>>>> ---------- Forwarded message ----------
>>>>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>>>>> Date: Mon, Oct 20, 2008 at 11:00 AM
>>>>> Subject: Re: [Tutor] how to see a number as two bytes
>>>>> To: shawn bright <nephish at gmail.com>
>>>>>
>>>>>
>>>>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>>>>
>>>>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>>>>>> hey there all,
>>>>>> i have a script that needs to send a number as two bytes.
>>>>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>>>>
>>>>>> thanks
>>>>>> shawn
>>>>>> _______________________________________________
>>>>>> Tutor maillist  -  Tutor at python.org
>>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>>
>>>>> _______________________________________________
>>>>> Tutor maillist  -  Tutor at python.org
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>
>>>
>>
>

From rabidpoobear at gmail.com  Mon Oct 20 18:16:55 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 20 Oct 2008 11:16:55 -0500
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
	<384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
Message-ID: <dfeb4470810200916p61c7a50fuc00132a127a49b17@mail.gmail.com>

No, I'm not sure what you mean.
Given this number

100101010101101011

the operation will slice off bits on the left with the % 2**16 so that
we only have 16 bits,
0101010101101011
then it will shift this value to the right so that we only have the
highest 8 bits
01010101
that will be stored in high.
Then it will slice off the bits on the left with the 2**8 so that we
only have 8 bits left,
01101011
and that is your low value.

On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <nephish at gmail.com> wrote:
> so using this, if num ==6, then i should get 2 and 88 ?
> thanks, just checking to make sure i get what you wrote.
> shawn
>
> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
> <rabidpoobear at gmail.com> wrote:
>> ---------- Forwarded message ----------
>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>> Date: Mon, Oct 20, 2008 at 11:00 AM
>> Subject: Re: [Tutor] how to see a number as two bytes
>> To: shawn bright <nephish at gmail.com>
>>
>>
>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>
>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>>> hey there all,
>>> i have a script that needs to send a number as two bytes.
>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>
>>> thanks
>>> shawn
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>

From rabidpoobear at gmail.com  Mon Oct 20 18:23:08 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 20 Oct 2008 11:23:08 -0500
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <384c93600810200920h5e356fecn53ada15d098cd615@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
	<384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
	<dfeb4470810200916p61c7a50fuc00132a127a49b17@mail.gmail.com>
	<384c93600810200920h5e356fecn53ada15d098cd615@mail.gmail.com>
Message-ID: <dfeb4470810200923m4e2563ddvc20b342389c746d3@mail.gmail.com>

I'm not sure if those values are correct;  I can check later tonight,
but I'm doing some statechart diagrams for class right now.  They
sound reasonable but I can't be sure.

On Mon, Oct 20, 2008 at 11:20 AM, shawn bright <nephish at gmail.com> wrote:
> jeez, i screwed up, i ment num = 600, not 6
> thanks
>
> On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
> <rabidpoobear at gmail.com> wrote:
>> No, I'm not sure what you mean.
>> Given this number
>>
>> 100101010101101011
>>
>> the operation will slice off bits on the left with the % 2**16 so that
>> we only have 16 bits,
>> 0101010101101011
>> then it will shift this value to the right so that we only have the
>> highest 8 bits
>> 01010101
>> that will be stored in high.
>> Then it will slice off the bits on the left with the 2**8 so that we
>> only have 8 bits left,
>> 01101011
>> and that is your low value.
>>
>> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <nephish at gmail.com> wrote:
>>> so using this, if num ==6, then i should get 2 and 88 ?
>>> thanks, just checking to make sure i get what you wrote.
>>> shawn
>>>
>>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>>> <rabidpoobear at gmail.com> wrote:
>>>> ---------- Forwarded message ----------
>>>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>>>> Date: Mon, Oct 20, 2008 at 11:00 AM
>>>> Subject: Re: [Tutor] how to see a number as two bytes
>>>> To: shawn bright <nephish at gmail.com>
>>>>
>>>>
>>>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>>>
>>>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>>>>> hey there all,
>>>>> i have a script that needs to send a number as two bytes.
>>>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>>>
>>>>> thanks
>>>>> shawn
>>>>> _______________________________________________
>>>>> Tutor maillist  -  Tutor at python.org
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>
>>
>

From alan.gauld at btinternet.com  Mon Oct 20 18:45:01 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 17:45:01 +0100
Subject: [Tutor] How to clear the screen
References: <48FB3BB0.1040107@lorettotel.net><200810191116.50440.cfuller084@thinkingplanet.net><gdheit$5kv$1@ger.gmane.org>
	<333efb450810200345u1526e739kb5cdb998f68c2b26@mail.gmail.com>
Message-ID: <gdicia$gl4$1@ger.gmane.org>


"W W" <srilyk at gmail.com> wrote 

> if os.system('cls') == 0:
>    pass
> elif os.system('clear') == 0:
>    pass
> else:
      print '\n' * 80

> That should take care of most of your OS' out there...

Why raise an error when you can just clear it by brute force?

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


From alan.gauld at btinternet.com  Mon Oct 20 18:52:30 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 20 Oct 2008 17:52:30 +0100
Subject: [Tutor] Can't start IDLE 2.6 on Mac
References: <3e12fcbf0810191453r5e28da87uf206f6d679be56d3@mail.gmail.com>
	<1c2a2c590810200342x5fc25b48yb1e6e9e0fb98b7c1@mail.gmail.com>
Message-ID: <gdid0c$i7f$1@ger.gmane.org>


"Kent Johnson" <kent37 at tds.net> wrote

> Unfortunately there is a problem with the Mac release of Python 2.6
> and Tkinter (which IDLE uses) does not work correctly. The only fix 
> at
> this point is to use 2.5 or to build Python yourself.
> http://bugs.python.org/issue4017
>
> I hope there will be an official release that fixes this soon, it
> seems like a serious problem to me.

Yep, this is why I almost never upgrade to new releases till they
have been out for several months!

But that looks like something that should have been caught in
earlier Release Candidates...

Alan G 



From wesbrooks at gmail.com  Mon Oct 20 22:30:06 2008
From: wesbrooks at gmail.com (Wesley Brooks)
Date: Mon, 20 Oct 2008 21:30:06 +0100
Subject: [Tutor] Which exceptions should I be catching?
Message-ID: <eec9f8ee0810201330w56d7efe4ibacffff661c08b8e@mail.gmail.com>

Dear Users,

I've got a program that passes messages to another program in the form of
empty files, whereby the title of the file is the command. I've been
speaking to this board about this before about doing this in the quickest
possible way. Even with the code layed out as follows the code still breaks
once in a blue moon. Unfortunately due to the nature of the program the
error has normally happened hours ago and the error message has disappeared
from the buffer of the command prompt.

This is the function:

def CommandFileWriter(self, command):
  name1 = os.path.join(self.commandsdir, command + '.temp')
  name2 = os.path.join(self.commandsdir, command)
  comfile = open(name1, 'w')
  comfile.close()
  if not os.path.exists(name2):
    os.rename(name1, name2)
  else:
    os.remove(name1)

This was the best way I could come up with doing the function. So the file
is written to the correct directory with a wrong name (so the other program
will ignore it) then it's name is changed to the correct name with
os.rename. Unfortunately I think in freak occations the other program can
read and delete the file (running on a multicore processor system) during
the rename operation. Can you suggest which errors I should be trying to
catch? I guess the last four lines could also be caught by try except as
well. Although the program is currently running on windows XP I would like
any soloution to be cross platform for testing and future-proofing reasons.

Thanks in advance of any suggestions,

Wesley Brooks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/9acbc30c/attachment-0001.htm>

From steve at alchemy.com  Mon Oct 20 22:51:22 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Mon, 20 Oct 2008 13:51:22 -0700
Subject: [Tutor] Fwd: how to see a number as two bytes
In-Reply-To: <384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<dfeb4470810200900u184bcc47xe2d40f94da8efc6d@mail.gmail.com>
	<dfeb4470810200900w3841f8a8mbeb2eded88e71c97@mail.gmail.com>
	<384c93600810200904x74e9c542qd4498eecf4e5f3ed@mail.gmail.com>
Message-ID: <20081020205122.GA69702@dragon.alchemy.com>

> > high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.

My take would be something like

high, low = (num >> 8) & 0xff , num & 0xff

In case you want another option.  This is probably more
efficient since you're not raising to powers or taking the
modulus, although for all I know Python may optimize that
in these special cases anyway.  

Also, unless Python is doing more than I think it does
to watch out for your safety behind the scenes, this
is more safe against sign extension errors.

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

From srilyk at gmail.com  Mon Oct 20 23:17:28 2008
From: srilyk at gmail.com (W W)
Date: Mon, 20 Oct 2008 16:17:28 -0500
Subject: [Tutor] Which exceptions should I be catching?
In-Reply-To: <eec9f8ee0810201330w56d7efe4ibacffff661c08b8e@mail.gmail.com>
References: <eec9f8ee0810201330w56d7efe4ibacffff661c08b8e@mail.gmail.com>
Message-ID: <333efb450810201417u17808b0eg225aaad6ade25ca7@mail.gmail.com>

On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <wesbrooks at gmail.com> wrote:

> Unfortunately due to the nature of the program the error has normally
> happened hours ago and the error message has disappeared from the buffer of
> the command prompt.
>

That's why you should write an error log ;)


>
> This is the function:
>
> def CommandFileWriter(self, command):
>   name1 = os.path.join(self.commandsdir, command + '.temp')
>   name2 = os.path.join(self.commandsdir, command)
>   comfile = open(name1, 'w')
>   comfile.close()
>   if not os.path.exists(name2):
>     os.rename(name1, name2)
>   else:
>     os.remove(name1)
>
> This was the best way I could come up with doing the function. So the file
> is written to the correct directory with a wrong name (so the other program
> will ignore it) then it's name is changed to the correct name with
> os.rename. Unfortunately I think in freak occations the other program can
> read and delete the file (running on a multicore processor system) during
> the rename operation. Can you suggest which errors I should be trying to
> catch?
>

I'm not sure what errors to catch, but it's always possible to use a general
catchall (I'm not sure if this is particularly pythonic)

try:
    put your function here
except:
    print 'oops! an error occurred!'

Or do something besides print an error (such as write a message to a
logfile. If you include the time stamp and some other info that might be
helpful that may give you some more insight as to where the problem is, and
if it's something you can fix.)

HTH,
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/703245ac/attachment.htm>

From jens.frid at gmail.com  Mon Oct 20 23:24:53 2008
From: jens.frid at gmail.com (Jens Frid)
Date: Mon, 20 Oct 2008 23:24:53 +0200
Subject: [Tutor] String and integer
Message-ID: <182c67860810201424j541aaa50wbb791afe1b461281@mail.gmail.com>

Hi,the code is:

def nr():
    nr1 = input('Enter value: ')
    print str(nr1).strip('nr0')

The user input is always on the form "nr08756" and i'd like to take out the
"nr0" and then print the result.
I can see that there is a problem with a variable looking like "pn0123"
because i get:
NameError: global name 'nr0123' is not defined.

What is the right way to do this?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/764a35f0/attachment.htm>

From sander.sweers at gmail.com  Mon Oct 20 23:33:53 2008
From: sander.sweers at gmail.com (Sander Sweers)
Date: Mon, 20 Oct 2008 23:33:53 +0200
Subject: [Tutor] Multiple lists from single list with nested lists
Message-ID: <b65fbb130810201433w416681dk97f27c63fd7dfdcc@mail.gmail.com>

Hi, I am learning myself python and I need to create 2, or more but
let's use 2 as an example, lists from a list with nested lists.

For example the below,

['Test1', 'Text2', ['1', '2'], 'Text3']

Should result in,

[['Test1', 'Text2', '1', 'Text3'],
['Test1', 'Text2', '2', 'Text3']

I though of using a temp list and looping over the list twice, something like,

somelist = ['Test1', 'Text2', ['1', '2'], 'Text3']
templist = []
for x in range(len(somelist[2])):
    templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]])
	
This works but to me looks ugly and would appreciate pointers and/or
someone pointing me to additional reading on this.

Much appreciated,
Sander

From wesbrooks at gmail.com  Mon Oct 20 23:36:08 2008
From: wesbrooks at gmail.com (Wesley Brooks)
Date: Mon, 20 Oct 2008 22:36:08 +0100
Subject: [Tutor] Which exceptions should I be catching?
In-Reply-To: <333efb450810201417u17808b0eg225aaad6ade25ca7@mail.gmail.com>
References: <eec9f8ee0810201330w56d7efe4ibacffff661c08b8e@mail.gmail.com>
	<333efb450810201417u17808b0eg225aaad6ade25ca7@mail.gmail.com>
Message-ID: <eec9f8ee0810201436y6ebbe249m6a9c59f88c2f7e5b@mail.gmail.com>

>
> That's why you should write an error log ;)


The error log is a valid point. Is there a way to capture the error messages
that go the the terminal window or command prompt rather than all my print
statements? Can this be set up as a global thing for the whole application
rather than inside each thread?

try:
>     put your function here
> except:
>     print 'oops! an error occurred!'
>

I'll probably resort to this and have done in a couple of other occasions,
but thought it was generally frowned upon! I Guess I could do that and print
out anything caught by the exception into a log and go more specific at a
later date.

Cheers,

Wesley Brooks



> On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <wesbrooks at gmail.com>wrote:
>
>> Unfortunately due to the nature of the program the error has normally
>> happened hours ago and the error message has disappeared from the buffer of
>> the command prompt.
>>
>
> That's why you should write an error log ;)
>
>
>>
>> This is the function:
>>
>> def CommandFileWriter(self, command):
>>   name1 = os.path.join(self.commandsdir, command + '.temp')
>>   name2 = os.path.join(self.commandsdir, command)
>>   comfile = open(name1, 'w')
>>   comfile.close()
>>   if not os.path.exists(name2):
>>     os.rename(name1, name2)
>>   else:
>>     os.remove(name1)
>>
>> This was the best way I could come up with doing the function. So the file
>> is written to the correct directory with a wrong name (so the other program
>> will ignore it) then it's name is changed to the correct name with
>> os.rename. Unfortunately I think in freak occations the other program can
>> read and delete the file (running on a multicore processor system) during
>> the rename operation. Can you suggest which errors I should be trying to
>> catch?
>>
>
> I'm not sure what errors to catch, but it's always possible to use a
> general catchall (I'm not sure if this is particularly pythonic)
>
> try:
>     put your function here
> except:
>     print 'oops! an error occurred!'
>
> Or do something besides print an error (such as write a message to a
> logfile. If you include the time stamp and some other info that might be
> helpful that may give you some more insight as to where the problem is, and
> if it's something you can fix.)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/9838bef3/attachment.htm>

From srini_iyyer_bio at yahoo.com  Tue Oct 21 00:19:37 2008
From: srini_iyyer_bio at yahoo.com (Srinivas Iyyer)
Date: Mon, 20 Oct 2008 15:19:37 -0700 (PDT)
Subject: [Tutor] finding numbers in range of of numbers
Message-ID: <19891.46630.qm@web38101.mail.mud.yahoo.com>

dear group, 
a simple question that often challenges me. 

I have 

I have a list of list:

[[10,45],[14,23],[39,73],[92,135]]

I want to identify if any of the items in this list are in range of [5,100]

These numbers are large in original data, I will be using xrange for memory issues. 

 thank you. 
srini

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

From srilyk at gmail.com  Tue Oct 21 00:40:29 2008
From: srilyk at gmail.com (W W)
Date: Mon, 20 Oct 2008 17:40:29 -0500
Subject: [Tutor] Which exceptions should I be catching?
In-Reply-To: <eec9f8ee0810201436y6ebbe249m6a9c59f88c2f7e5b@mail.gmail.com>
References: <eec9f8ee0810201330w56d7efe4ibacffff661c08b8e@mail.gmail.com>
	<333efb450810201417u17808b0eg225aaad6ade25ca7@mail.gmail.com>
	<eec9f8ee0810201436y6ebbe249m6a9c59f88c2f7e5b@mail.gmail.com>
Message-ID: <333efb450810201540r5f67a8c6if8cc676195732b99@mail.gmail.com>

On Mon, Oct 20, 2008 at 4:36 PM, Wesley Brooks <wesbrooks at gmail.com> wrote:

> That's why you should write an error log ;)
>
>
> The error log is a valid point. Is there a way to capture the error
> messages that go the the terminal window or command prompt rather than all
> my print statements? Can this be set up as a global thing for the whole
> application rather than inside each thread?
>
> try:
>>     put your function here
>> except:
>>     print 'oops! an error occurred!'
>>
>
> I'll probably resort to this and have done in a couple of other occasions,
> but thought it was generally frowned upon! I Guess I could do that and print
> out anything caught by the exception into a log and go more specific at a
> later date.
>
> Cheers,
>
> Wesley Brooks
>
>
>
>> On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <wesbrooks at gmail.com>wrote:
>>
>>> Unfortunately due to the nature of the program the error has normally
>>> happened hours ago and the error message has disappeared from the buffer of
>>> the command prompt.
>>>
>>
>> That's why you should write an error log ;)
>>
>>
>>>
>>> This is the function:
>>>
>>> def CommandFileWriter(self, command):
>>>   name1 = os.path.join(self.commandsdir, command + '.temp')
>>>   name2 = os.path.join(self.commandsdir, command)
>>>   comfile = open(name1, 'w')
>>>   comfile.close()
>>>   if not os.path.exists(name2):
>>>     os.rename(name1, name2)
>>>   else:
>>>     os.remove(name1)
>>>
>>> This was the best way I could come up with doing the function. So the
>>> file is written to the correct directory with a wrong name (so the other
>>> program will ignore it) then it's name is changed to the correct name with
>>> os.rename. Unfortunately I think in freak occations the other program can
>>> read and delete the file (running on a multicore processor system) during
>>> the rename operation. Can you suggest which errors I should be trying to
>>> catch?
>>>
>>
>> I'm not sure what errors to catch, but it's always possible to use a
>> general catchall (I'm not sure if this is particularly pythonic)
>>
>> try:
>>     put your function here
>> except:
>>     print 'oops! an error occurred!'
>>
>> Or do something besides print an error (such as write a message to a
>> logfile. If you include the time stamp and some other info that might be
>> helpful that may give you some more insight as to where the problem is, and
>> if it's something you can fix.)
>>
>
This might help:
http://www.python.org/doc/2.5.2/lib/module-logging.html

I don't really know though, it was just the first thing that came up when I
entered "python logging"
HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levihttp://
www.python.org/doc/2.5.2/lib/module-logging.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/7b689086/attachment.htm>

From srilyk at gmail.com  Tue Oct 21 00:42:11 2008
From: srilyk at gmail.com (W W)
Date: Mon, 20 Oct 2008 17:42:11 -0500
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <19891.46630.qm@web38101.mail.mud.yahoo.com>
References: <19891.46630.qm@web38101.mail.mud.yahoo.com>
Message-ID: <333efb450810201542v9f4ccb0h465b4ac977a44c77@mail.gmail.com>

On Mon, Oct 20, 2008 at 5:19 PM, Srinivas Iyyer
<srini_iyyer_bio at yahoo.com>wrote:

> dear group,
> a simple question that often challenges me.
>
> I have
>
> I have a list of list:
>
> [[10,45],[14,23],[39,73],[92,135]]
>
> I want to identify if any of the items in this list are in range of [5,100]
>
> These numbers are large in original data, I will be using xrange for memory
> issues.
>
>  thank you.
> srini


a simple comparison should do it for ya,
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081020/da62c175/attachment.htm>

From alan.gauld at btinternet.com  Tue Oct 21 01:06:40 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 21 Oct 2008 00:06:40 +0100
Subject: [Tutor] how to see a number as two bytes
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
Message-ID: <gdj2tu$iva$1@ger.gmane.org>

"shawn bright" <nephish at gmail.com> wrote

> i have a script that needs to send a number as two bytes.
> how would i be able to see a number expressed as a hi byte and a lo 
> byte?

One way is to use the struct module.
It has the advantage of allowing selection of big endian(>) or little
endian(<) representation etc. The H symbol can be used for a short
integer - ie 2 bytes...

eg

>>> import struct
>>> b = struct.pack(">H", 279)
>>> b
'\x01\x17'
>>> b = struct.pack("<H", 279)
>>> b
'\x17\x01'
>>>

Note that Python will print bytes with printable representations as
the character form but the data is still two bytes.

eg
>>> struct.pack("H", 33)
'!\x00'
>>> chr(33)
'!'


HTH,

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




From bgailer at gmail.com  Tue Oct 21 01:09:35 2008
From: bgailer at gmail.com (bob gailer)
Date: Mon, 20 Oct 2008 19:09:35 -0400
Subject: [Tutor] String and integer
In-Reply-To: <182c67860810201424j541aaa50wbb791afe1b461281@mail.gmail.com>
References: <182c67860810201424j541aaa50wbb791afe1b461281@mail.gmail.com>
Message-ID: <48FD0FAF.8040404@gmail.com>

Jens Frid wrote:
> Hi,
> the code is:
>
> def nr():
>     nr1 = input('Enter value: ')
>     print str(nr1).strip('nr0')
>
> The user input is always on the form "nr08756" and i'd like to take 
> out the "nr0" and then print the result.
> I can see that there is a problem with a variable looking like 
> "pn0123" because i get: 
> NameError: global name 'nr0123' is not defined.
>
> What is the right way to do this?

raw_input() rather than input(). input evaluate whatever is entered; 
raw_input returns as a string whatever is entered.

In Python 3 raw_input will be renamed input and the old input will go away.
>
> Thanks!
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From wescpy at gmail.com  Tue Oct 21 01:33:31 2008
From: wescpy at gmail.com (wesley chun)
Date: Mon, 20 Oct 2008 16:33:31 -0700
Subject: [Tutor] String and integer
In-Reply-To: <48FD0FAF.8040404@gmail.com>
References: <182c67860810201424j541aaa50wbb791afe1b461281@mail.gmail.com>
	<48FD0FAF.8040404@gmail.com>
Message-ID: <78b3a9580810201633r10f42200k784e7b66638a5f0f@mail.gmail.com>

>> def nr():
>>    nr1 = input('Enter value: ')
>>    print str(nr1).strip('nr0')
>>
>> The user input is always on the form "nr08756" and i'd like to take out
>> the "nr0" and then print the result.
>> I can see that there is a problem with a variable looking like "pn0123"
>> because i get: NameError: global name 'nr0123' is not defined.
>>
>> What is the right way to do this?
>
> raw_input() rather than input(). input evaluate whatever is entered;
> raw_input returns as a string whatever is entered.
>
> In Python 3 raw_input will be renamed input and the old input will go away.


everything that bob said... and more.  :-)

definitely never ever use input()... it is absolutely unnecessary and
a potential security hazard, hence the reason why its functionality
will be completely removed in 3.0. for now, as bob has suggested, use
raw_input() in the remaining 2.x releases then switch to input() for
3.x.

with regards to the rest of your query, if you are certain that the
first few chars of the input is 'nr0', you can just so nr1[3:] to get
the rest. if you want to play it safe, throw in a "if
nr1.startswith('nr0')" beforehand.

finally, be careful with strip(). you are not stripping just the "nr0"
with strip('nr0')... you are removing all 'n's, 'r's, and '0's from
your string, i.e.

>>> 'nr07890'.strip('nr0')
'789'

this is the reason why i suggested nr1[3:] instead... it chops off the
1st 3 chars and takes the remainer.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

From kent37 at tds.net  Tue Oct 21 01:36:47 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 20 Oct 2008 19:36:47 -0400
Subject: [Tutor] Multiple lists from single list with nested lists
In-Reply-To: <b65fbb130810201433w416681dk97f27c63fd7dfdcc@mail.gmail.com>
References: <b65fbb130810201433w416681dk97f27c63fd7dfdcc@mail.gmail.com>
Message-ID: <1c2a2c590810201636l474e2992qb8f57514fca44038@mail.gmail.com>

On Mon, Oct 20, 2008 at 5:33 PM, Sander Sweers <sander.sweers at gmail.com> wrote:
> Hi, I am learning myself python and I need to create 2, or more but
> let's use 2 as an example, lists from a list with nested lists.
>
> For example the below,
>
> ['Test1', 'Text2', ['1', '2'], 'Text3']
>
> Should result in,
>
> [['Test1', 'Text2', '1', 'Text3'],
> ['Test1', 'Text2', '2', 'Text3']
>
> I though of using a temp list and looping over the list twice, something like,
>
> somelist = ['Test1', 'Text2', ['1', '2'], 'Text3']
> templist = []
> for x in range(len(somelist[2])):
>    templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]])

Is it always just the third item that is a list? If so I think your
solution is not too bad. You could write it as
templist = []
for x in somelist[2]):
   templist.append(somelist[0:2] + [x] + somelist[3:])

or use a list comprehension:
templist = [ somelist[0:2] + [x] + somelist[3:] for x in somelist ]

Kent

From Brummert_Brandon at roberts.edu  Tue Oct 21 02:19:12 2008
From: Brummert_Brandon at roberts.edu (Brummert_Brandon)
Date: Mon, 20 Oct 2008 20:19:12 -0400
Subject: [Tutor] decision structures
In-Reply-To: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
Message-ID: <AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>



Hello.  I am working with python for computer science this semester.  I am having a difficult time on one of my lab assignments.  It is in the python programming book in chapter 7 under decision structures.  I am being asked to write a program in that accepts a date in the form month/date/year and outputs whether the date is valid.  For example, 5/24/1962 is valid but 9/31/2000 is not because September only has 30 days.  Thank you.


Brandon Brummert
brummert_brandon at roberts.edu

From bgailer at gmail.com  Tue Oct 21 03:01:17 2008
From: bgailer at gmail.com (bob gailer)
Date: Mon, 20 Oct 2008 21:01:17 -0400
Subject: [Tutor] decision structures
In-Reply-To: <AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>
Message-ID: <48FD29DD.9070006@gmail.com>

Brummert_Brandon wrote:
> Hello.  I am working with python for computer science this semester.  I am having a difficult time on one of my lab assignments.  It is in the python programming book in chapter 7 under decision structures.  I am being asked to write a program in that accepts a date in the form month/date/year and outputs whether the date is valid.  For example, 5/24/1962 is valid but 9/31/2000 is not because September only has 30 days.  
"the python programming book"? There are a lot of these. Which one do 
you refer to?

Regarding homework - we can offer specific help, when we see your 
efforts and where you are stuck. Have you written any Python code for 
this assignment? Or any program design?

Do you know how to do input and output? How to split a string? How to 
convert characters to numbers? How to compare numbers? How to create and 
use lists of numbers? Those are the skills you need for this problem. 
Give it a stab and report back and let's see what happens.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From xboxmuncher at gmail.com  Tue Oct 21 06:05:03 2008
From: xboxmuncher at gmail.com (xbmuncher)
Date: Tue, 21 Oct 2008 00:05:03 -0400
Subject: [Tutor] auto referer handler/opener for urlib2?
Message-ID: <df531c470810202105i7b497ba3r9bb5d31cb3c114bf@mail.gmail.com>

I was reading about urllib2 openers.. Can I make any kind of def or function
and make the urllib2 "urlopen" function run through this function first
before opening a url? For example, something like a reporthook function.
What I want to do is this:

def autoReferer(handle):
if handle.lastRequest.url != None:
handle.addheader('referer' : handle.lastRequest.url)


How can make this auto referer functionality with urllib2?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/b6ebe162/attachment.htm>

From bcl at brianlane.com  Tue Oct 21 08:08:45 2008
From: bcl at brianlane.com (Brian Lane)
Date: Mon, 20 Oct 2008 23:08:45 -0700
Subject: [Tutor] decision structures
In-Reply-To: <48FD29DD.9070006@gmail.com>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>
	<48FD29DD.9070006@gmail.com>
Message-ID: <48FD71ED.2040403@brianlane.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

bob gailer wrote:
> Brummert_Brandon wrote:
>> Hello.  I am working with python for computer science this semester.  I am having a difficult time on one of my lab assignments.  It is in the python programming book in chapter 7 under decision structures.  I am being asked to write a program in that accepts a date in the form month/date/year and outputs whether the date is valid.  For example, 5/24/1962 is valid but 9/31/2000 is not because September only has 30 days.  
> "the python programming book"? There are a lot of these. Which one do 
> you refer to?
> 
> Regarding homework - we can offer specific help, when we see your 
> efforts and where you are stuck. Have you written any Python code for 
> this assignment? Or any program design?
> 
> Do you know how to do input and output? How to split a string? How to 
> convert characters to numbers? How to compare numbers? How to create and 
> use lists of numbers? Those are the skills you need for this problem. 
> Give it a stab and report back and let's see what happens.
> 

I'd look into learning how to use the datetime module.

Brian

- --
- ---[Office 71.0F]--[Outside 39.9F]--[Server 104.6F]--[Coaster 72.0F]---
- ---[        CACHALOT (366764080) @ 47 29.9424 -122 28.8851        ]---
Software, Linux, Microcontrollers             http://www.brianlane.com
AIS Parser SDK                                http://www.aisparser.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFI/XHtIftj/pcSws0RAgeGAJ9zMSVrV7rbr1WrWEsZw1liPTGmEQCfQdMb
p2fUPyV3LXDnj1LRUxBJvyg=
=A7eC
-----END PGP SIGNATURE-----

From jens.frid at gmail.com  Tue Oct 21 09:01:17 2008
From: jens.frid at gmail.com (Jens Frid)
Date: Tue, 21 Oct 2008 09:01:17 +0200
Subject: [Tutor] String and integer
In-Reply-To: <78b3a9580810201633r10f42200k784e7b66638a5f0f@mail.gmail.com>
References: <182c67860810201424j541aaa50wbb791afe1b461281@mail.gmail.com>
	<48FD0FAF.8040404@gmail.com>
	<78b3a9580810201633r10f42200k784e7b66638a5f0f@mail.gmail.com>
Message-ID: <182c67860810210001u1101e1a8m3b8a1683685553d0@mail.gmail.com>

Thank you all!Very informative and much appreciated!

Regards,
Jens

On Tue, Oct 21, 2008 at 1:33 AM, wesley chun <wescpy at gmail.com> wrote:

> >> def nr():
> >>    nr1 = input('Enter value: ')
> >>    print str(nr1).strip('nr0')
> >>
> >> The user input is always on the form "nr08756" and i'd like to take out
> >> the "nr0" and then print the result.
> >> I can see that there is a problem with a variable looking like "pn0123"
> >> because i get: NameError: global name 'nr0123' is not defined.
> >>
> >> What is the right way to do this?
> >
> > raw_input() rather than input(). input evaluate whatever is entered;
> > raw_input returns as a string whatever is entered.
> >
> > In Python 3 raw_input will be renamed input and the old input will go
> away.
>
>
> everything that bob said... and more.  :-)
>
> definitely never ever use input()... it is absolutely unnecessary and
> a potential security hazard, hence the reason why its functionality
> will be completely removed in 3.0. for now, as bob has suggested, use
> raw_input() in the remaining 2.x releases then switch to input() for
> 3.x.
>
> with regards to the rest of your query, if you are certain that the
> first few chars of the input is 'nr0', you can just so nr1[3:] to get
> the rest. if you want to play it safe, throw in a "if
> nr1.startswith('nr0')" beforehand.
>
> finally, be careful with strip(). you are not stripping just the "nr0"
> with strip('nr0')... you are removing all 'n's, 'r's, and '0's from
> your string, i.e.
>
> >>> 'nr07890'.strip('nr0')
> '789'
>
> this is the reason why i suggested nr1[3:] instead... it chops off the
> 1st 3 chars and takes the remainer.
>
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
>    http://corepython.com
>
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/addb1612/attachment.htm>

From sekhar926 at gmail.com  Tue Oct 21 10:26:58 2008
From: sekhar926 at gmail.com (rajasekhar mamilla)
Date: Tue, 21 Oct 2008 13:56:58 +0530
Subject: [Tutor] How to compute performance of python program
Message-ID: <a9943a4e0810210126q72268ad9ifdbc27bba2ffca6d@mail.gmail.com>

Hi tutors,

Iam relatively new to python.

I  developed a project in python,now i want to know the performance of my
code.

Can i know how much time each python file takes or each program or each loop
takes to get executed.

Please help me if any such ways are available or any other  ways using which
i can find how efficient is my program.

thanks,
sekhar.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/c618c18b/attachment.htm>

From alan.gauld at btinternet.com  Tue Oct 21 11:10:47 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 21 Oct 2008 10:10:47 +0100
Subject: [Tutor] finding numbers in range of of numbers
References: <19891.46630.qm@web38101.mail.mud.yahoo.com>
Message-ID: <gdk6al$r3q$1@ger.gmane.org>

"Srinivas Iyyer" <srini_iyyer_bio at yahoo.com> wrote

> [[10,45],[14,23],[39,73],[92,135]]
>
> I want to identify if any of the items in this list are in range of 
> [5,100]

Sorry, I have no idea what you mean by that. Can you give
an example of passing and failing tests?

For example do any/all of the elements in your sample
list pass the test? If so why?

Often if you think carefullly and specifically about your
requirement the solution will become apparent. And if
you don't you are open to ambiguity and confusion.

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



From alan.gauld at btinternet.com  Tue Oct 21 11:16:16 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 21 Oct 2008 10:16:16 +0100
Subject: [Tutor] decision structures
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>
Message-ID: <gdk6l7$s6l$1@ger.gmane.org>

"Brummert_Brandon" <Brummert_Brandon at roberts.edu> wrote

> Hello.  I am working with python for computer science this semester.
> I am having a difficult time on one of my lab assignments

We won't do your homework for you but we can offer specific
help for specific queries. But you need to help us help you.

> .  It is in the python programming book in chapter 7

Which Python programming book - there are literally dozens?!

> I am being asked to write a program in that accepts a date
> in the form month/date/year and outputs whether the date
> is valid.  For example, 5/24/1962 is valid but 9/31/2000 is
> not because September only has 30 days.

Since the exercise is around decision structures I assume
that using the standard Python date handling modules is
not allowed/acceptable?


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



From alan.gauld at btinternet.com  Tue Oct 21 11:19:35 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 21 Oct 2008 10:19:35 +0100
Subject: [Tutor] How to compute performance of python program
References: <a9943a4e0810210126q72268ad9ifdbc27bba2ffca6d@mail.gmail.com>
Message-ID: <gdk6r4$srp$1@ger.gmane.org>


"rajasekhar mamilla" <sekhar926 at gmail.com> wrote in message 
news:a9943a4e0810210126q72268ad9ifdbc27bba2ffca6d at mail.gmail.com...
> Hi tutors,
>
> Iam relatively new to python.
>
> I  developed a project in python,now i want to know the performance 
> of my
> code.

Look at the timeit command and the profiling module.

Very simple profile example here:

http://effbot.org/librarybook/profile.htm

Between them they should give you all the information you need.

HTH


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



From kent37 at tds.net  Tue Oct 21 13:12:57 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 07:12:57 -0400
Subject: [Tutor] auto referer handler/opener for urlib2?
In-Reply-To: <df531c470810202105i7b497ba3r9bb5d31cb3c114bf@mail.gmail.com>
References: <df531c470810202105i7b497ba3r9bb5d31cb3c114bf@mail.gmail.com>
Message-ID: <1c2a2c590810210412n5394224dv6af01ab818e22a4@mail.gmail.com>

On Tue, Oct 21, 2008 at 12:05 AM, xbmuncher <xboxmuncher at gmail.com> wrote:
> I was reading about urllib2 openers.. Can I make any kind of def or function
> and make the urllib2 "urlopen" function run through this function first
> before opening a url? For example, something like a reporthook function.
> What I want to do is this:
>
> def autoReferer(handle):
> if handle.lastRequest.url != None:
> handle.addheader('referer' : handle.lastRequest.url)
>
>
> How can make this auto referer functionality with urllib2?

You can subclass BaseHandler with a class that has a
http_request(self, request) method. Add an instance of your handler to
the OpenerDirector. http_request() will be called with the request
object as its parameter and returns the request object as its result.
See the docs for BaseHandler.protocol_request (just after this link)
http://docs.python.org/library/urllib2.html#urllib2.BaseHandler.http_error_nnn

and look at the implementation of HTTPCookieProcessor for an example.

Note you must have an implementation of <protocol>_request() for each
protocol you wish to handle, e.g. http and https.

Kent

From roadierich at googlemail.com  Tue Oct 21 14:47:29 2008
From: roadierich at googlemail.com (Richard Lovely)
Date: Tue, 21 Oct 2008 13:47:29 +0100
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <19891.46630.qm@web38101.mail.mud.yahoo.com>
References: <19891.46630.qm@web38101.mail.mud.yahoo.com>
Message-ID: <f0b4202b0810210547s7b6bc976kd3104d9a893bce88@mail.gmail.com>

Guessing you mean [5,100] as the inclusive interval notation, so all
but the last element of the example pass?

if any(True for x, y in listoflists if 5 <= x and y <= 100):
   #do stuff

does this do it for you?

Or if you want to know if any elements of the lists within the larger
list are within the range, and the sublists always have two elements
you could do:

if any(True for x,y in listoflists if 5<= x <=100 and 5<= y <=100):
    #do stuff

otherwise, for a list of arbirtary length lists:

from itertools import chain
if any(True for x in chain(*listoflists) if 5<= x <=100):
    #do stuff

You can be slightly faster (but less readable) by changing the
if any(...):
to
if [...]:

This is probably more pythonic, as well.

(There might be a better way, but I like itertools).

Hope something in here was helpful...

On 20/10/2008, Srinivas Iyyer <srini_iyyer_bio at yahoo.com> wrote:
> dear group,
> a simple question that often challenges me.
>
> I have
>
> I have a list of list:
>
> [[10,45],[14,23],[39,73],[92,135]]
>
> I want to identify if any of the items in this list are in range of [5,100]
>
> These numbers are large in original data, I will be using xrange for memory issues.
>
>  thank you.
> srini
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com

From kent37 at tds.net  Tue Oct 21 15:35:38 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 09:35:38 -0400
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <f0b4202b0810210547s7b6bc976kd3104d9a893bce88@mail.gmail.com>
References: <19891.46630.qm@web38101.mail.mud.yahoo.com>
	<f0b4202b0810210547s7b6bc976kd3104d9a893bce88@mail.gmail.com>
Message-ID: <1c2a2c590810210635u5eb428a2i6059fc53ad179033@mail.gmail.com>

On Tue, Oct 21, 2008 at 8:47 AM, Richard Lovely
<roadierich at googlemail.com> wrote:
> Guessing you mean [5,100] as the inclusive interval notation, so all
> but the last element of the example pass?
>
> if any(True for x, y in listoflists if 5 <= x and y <= 100):
>   #do stuff

or
if any((5 <= x and y <= 100) for x, y in listoflists):

> You can be slightly faster (but less readable) by changing the
> if any(...):
> to
> if [...]:

Why faster? any() will short-circuit - it will stop processing as soon
as it finds a True item. It also avoids building the entire list. I
would expect it to be faster.

Of course, if you really care about speed you should test, not guess.

Kent

From srini_iyyer_bio at yahoo.com  Tue Oct 21 16:12:24 2008
From: srini_iyyer_bio at yahoo.com (Srinivas Iyyer)
Date: Tue, 21 Oct 2008 07:12:24 -0700 (PDT)
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <gdk6al$r3q$1@ger.gmane.org>
Message-ID: <233048.20017.qm@web38107.mail.mud.yahoo.com>

Dear Alan and tutors,

I apologize for careless description of my problem that lead to confusion. 
the problem arises due to large range of numbers and range has direction (both ascending and descending). 

I am giving an example from my real problem.

What I want to do:
 I want to check if a[.][1] and a[.][2] are 'within the range' of any element of b[.][1] or b[.][2]. (here '.' means any sub-element of list b.

a[.][1] and a[.][2] or b[.][1] b[.][2] can be either ascending or descending order
Ascending example from list a and b:
'xa','1511255', '1511279'
'xb','7516599','7516623'
'G1','1511200','1511325'
'G2','7516500','7516625'

descending order from list a and b:
'xc','98356290','98356266'
'G3','98356335','98356126'

a = [['xa','1511255', '1511279'],['xb','7516599','7516623'],['xc','98356290','98356266']]

b = [['G1','1511200','1511325'],['G2','7516500','7516625'],['G3','98356335','98356126']]

>>> for item1 in a:
...     i1st = int(item1[1])
...     i1en = int(item1[2])
...     for item2 in b:
...             i21 = int(item2[1])
...             i22 = int(item2[2])
...             if i1st and i1en in xrange(i21,i22):
...                     print "\t".join(item1)+'\t'+"\t".join(item2)
...             if i1st and i1en in xrange(i22,i21):
...                     print "\t".join(item1)+'\t'+"\t".join(item2)
...
xa      1511255 1511279 G1      1511200 1511325
xb      7516599 7516623 G2      7516500 7516625
xc      98356290        98356266        G3      98356335        98356126



Issue 1:  
a. Range of numbers is too high and xrange is also too slow.
   I used xrange instead of range - a slow process

Issue 2: 
Is this is a correct way to tackle this kind of problem. 


Issue 3: 
I have 200K elements in a anb b lists. this code has been running for last 18 hours and only 800 elements of 200K have been evaluated. 

Could tutors help me with 3 issues. 
Thank you. 


srini


--- On Tue, 10/21/08, Alan Gauld <alan.gauld at btinternet.com> wrote:

> From: Alan Gauld <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] finding numbers in range of of numbers
> To: tutor at python.org
> Date: Tuesday, October 21, 2008, 5:10 AM
> "Srinivas Iyyer" <srini_iyyer_bio at yahoo.com>
> wrote
> 
> > [[10,45],[14,23],[39,73],[92,135]]
> >
> > I want to identify if any of the items in this list
> are in range of 
> > [5,100]
> 
> Sorry, I have no idea what you mean by that. Can you give
> an example of passing and failing tests?
> 
> For example do any/all of the elements in your sample
> list pass the test? If so why?
> 
> Often if you think carefullly and specifically about your
> requirement the solution will become apparent. And if
> you don't you are open to ambiguity and confusion.
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


      

From bgailer at gmail.com  Tue Oct 21 16:25:25 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 21 Oct 2008 10:25:25 -0400
Subject: [Tutor] decision structures
In-Reply-To: <AAC098868E7A8C479AAEC93921640FC22D21A33BD4@emaildb5.roberts.edu>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>,
	<48FD29DD.9070006@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD2@emaildb5.roberts.edu>,
	<48FDC812.4060409@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD4@emaildb5.roberts.edu>
Message-ID: <48FDE655.6080707@gmail.com>

Please reply to the tutor list, not just to me. We all learn and many of 
us can help.

Brummert_Brandon wrote:
> This is what I have so far.  I am still confused by the string.split  setup.  Thank you.
>
>
> # dateCheck.py
> # A program that accepts a date in the form month/day/year and outputs whether date is valid.
> # Brandon Brummert, October 20, 2008
>
> import string
> def isLeapYear(leap):
>     if 0 == year % 400:
>         return True
>     elif 0 == year % 100:
>         return False
>     elif 0 == year % 4:
>         return True
>     else:
>         return False
>
> def daysInMonth (date):
>     if 1 or 3 or 5 or 7 or 8 or 10 or 12:
>         return 31
>     elif 4 or 6 or 9 or 11:
>         return 30
>     elif 2:
>         return leap
> def main():
>     currentdate= input ("What is the date (mm/dd/yyyy)?:")
>     month, date, year= string.split(currentdate)
>     print month/date/year
> main()
>
>
>
>   
Thank you. That is half of the input I'm seeking. The other half is: 
what happens when you run the program?
I'd expect you see a prompt:

What is the date (mm/dd/yyyy)?:

What do you enter at this prompt?

What happens next? You should see an exception (error). What is it? Why 
do you think it means and why did it happen?

Read the documentation for input().

As an aside - your program shows very little understanding of Python. 
Have you written other programs that ran the way you expected, or is 
this your first try?

Since it is homework we don't write the program for you. I'm trying to 
nudge you in the right direction, and would appreciate all you can give it.

Did you read the documentation for split?

month/date/year

is an expression. What does the / mean in an expression?

At the Python interpreter prompt >>> enter

if 1 or 3 or 5 or 7 or 8 or 10 or 12:
  print True

What happens? Why? Then try

if 1:
  print True

You are trying to compare date to numbers yet date does not appear in 
the if statement!

I have mentioned lists twice yet you have not said anything about them. 
Do you know what a list is and how it can be used?

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From bgailer at gmail.com  Tue Oct 21 16:43:51 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 21 Oct 2008 10:43:51 -0400
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <233048.20017.qm@web38107.mail.mud.yahoo.com>
References: <233048.20017.qm@web38107.mail.mud.yahoo.com>
Message-ID: <48FDEAA7.5050504@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/6eaa8774/attachment.htm>

From alan.gauld at btinternet.com  Tue Oct 21 16:42:38 2008
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Tue, 21 Oct 2008 14:42:38 +0000 (GMT)
Subject: [Tutor] finding numbers in range of of numbers
Message-ID: <947489.92324.qm@web86702.mail.ukl.yahoo.com>



a = [['xa','1511255', '1511279'],['xb','7516599','7516623'],['xc','98356290','98356266']]

b = [['G1','1511200','1511325'],['G2','7516500','7516625'],['G3','98356335','98356126']]

>>> for item1 in a:
...     i1st = int(item1[1])
...     i1en = int(item1[2])
...     for item2 in b:
...             i21 = int(item2[1])
...             i22 = int(item2[2])
...             if i1st and i1en in xrange(i21,i22):
...                     print "\t".join(item1)+'\t'+"\t".join(item2)
...             if i1st and i1en in xrange(i22,i21):
...                     print "\t".join(item1)+'\t'+"\t".join(item2)


I would rewrite the 4 lines above to remove the 'in' test - which is basically
iterating over the range.

if i1st:         # is this really the logic you want? it seems slightly suspicious to me
   if i21 < i1en < i22:
     # i21 is within the range.

That should save one iteration of the range for each inner loop. 
(One iteration is always of an empty list depending on which of i21,i22 is greater)

> Issue 1:  
> a. Range of numbers is too high and xrange is also too slow.
>    I used xrange instead of range - a slow process


My solution removes the use of xrange.

> Issue 2: 
> Is this is a correct way to tackle this kind of problem. 

If it works then in a sense its correct. But I think checking the range 
boundaries is easier and should be faster

> Issue 3: 
> I have 200K elements in a anb b lists. this code has been running for 
> last 18 hours and only 800 elements of 200K have been evaluated. 

Which is a repeat of issue 1... I don't know how much my proposed 
solution will make but it should be a bit faster.

Dunno if that will help,

Alan G

From kent37 at tds.net  Tue Oct 21 17:23:39 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 11:23:39 -0400
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <48FDEAA7.5050504@gmail.com>
References: <233048.20017.qm@web38107.mail.mud.yahoo.com>
	<48FDEAA7.5050504@gmail.com>
Message-ID: <1c2a2c590810210823r1d24115y320bb8c2b3016940@mail.gmail.com>

On Tue, Oct 21, 2008 at 10:43 AM, bob gailer <bgailer at gmail.com> wrote:

> I would make a copy of each list; take a pass thru each copy, convert the
> strings to integers and reverse the descending pairs.
>
> a1 = [['xa', 1511255, 1511279],['xb', 7516599, 7516623],['xc', 98356266,
> 98356290]]
>
> b1 = [['G1', 1511200, 1511325],['G2', 7516500, 7516625],['G3', 98356126,
> 98356335]]
>
> Then compare lower and upper limits (no need for range):
>
> for a2 in a1:
>   for b2 in b1:
>     if a2[1] >= b2[1] and a2[2] < b2[2]:
>         print the matched result
>         break
>   else:
>     print the unmatched result.

If you sort  b1 by the second value then you can cut down on the
amount of the list you have to search:
if a2[1] > b2[2]:
  break

Apparently the clever way to do this is to use an interval tree:
http://en.wikipedia.org/wiki/Interval_tree

The bx-python project http://bx-python.trac.bx.psu.edu/ seems to have
an implementation here:
http://bx-python.trac.bx.psu.edu/browser/trunk/lib/bx/intervals/operations/quicksect.py

Also this method that you could use fairly easily:
http://www.bx.psu.edu/projects/bx-python/apidocs/lib/bx.intervals.intersection.Intersecter-class.html

Kent

From tocb2003 at yahoo.co.uk  Tue Oct 21 15:52:59 2008
From: tocb2003 at yahoo.co.uk (Tim Brown)
Date: Tue, 21 Oct 2008 13:52:59 +0000 (GMT)
Subject: [Tutor] appending to a utf-16 encoded text file
Message-ID: <890000.57633.qm@web27805.mail.ukl.yahoo.com>

Hi,
I'm trying to create and append unicode strings to a utf-16 text file.
The best I could come up with was to use codecs.open() with an 
encoding of 'utf-16' but when I do an append I get another UTF16 BOM 
put into the file which other programs do not expect to see :-(
Is there some way to stop codecs from doing this or is there a better
way to create and add data to a utf-16 text file?

Thanks Tim.


Send instant messages to your online friends http://uk.messenger.yahoo.com 

From ironfroggy at gmail.com  Tue Oct 21 16:06:35 2008
From: ironfroggy at gmail.com (Calvin Spealman)
Date: Tue, 21 Oct 2008 10:06:35 -0400
Subject: [Tutor] Providing Solutions for all the Common Questions
Message-ID: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>

There was a discussion in the #python channel over at freenode about the
common questions we seem to field daily. These often revolve around problems
a lot of people need solutions for, and for which we have specific answers
to we always give. A lot of times this leads to teeth grinding as we try to
convince people about our advice. Why else are they asking if they then
argue with the answers they get? This takes a lot of time and energy, so a
number of us are starting a project to produce tutorials, guides,
and explanations to back up a lot of these solutions.
For example, a lot of people look to write an irc bot when they learn
Python, and often they either plan or are suggested to use Twisted. A
tutorial specifically for this need is being written.

We've decided to come here to organize this, as it seems to fit.

So there are some organizational issues to approach. I thought AppEngine
would be a good place to host everything, so I've already registered
pythonguides.appspot.com and plan to throw up a basic Wiki to start. Going
forward there are some things I want to implement there to support our
specific needs. For now, its just a free host.

One other initial need is to collect the problems we need to provide our
solutions for. So, what do we people ask over and over?

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing:
http://www.twitter.com/ironfroggy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/c0f09650/attachment.htm>

From mail at timgolden.me.uk  Tue Oct 21 17:37:38 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Tue, 21 Oct 2008 16:37:38 +0100
Subject: [Tutor] appending to a utf-16 encoded text file
In-Reply-To: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
References: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
Message-ID: <48FDF742.5080907@timgolden.me.uk>

Tim Brown wrote:
> Hi,
> I'm trying to create and append unicode strings to a utf-16 text file.
> The best I could come up with was to use codecs.open() with an 
> encoding of 'utf-16' but when I do an append I get another UTF16 BOM 
> put into the file which other programs do not expect to see :-(
> Is there some way to stop codecs from doing this or is there a better
> way to create and add data to a utf-16 text file?


Well, there's nothing to stop you opening it "raw", as it were,
and just appending unicode encoded as utf16.

<code>
s = u"The cat sat on the mat"
f = open ("utf16.txt", "wb")
for word in s.split ():
  f.write (word.encode ("utf16") + " ")

f.close ()

</code>

TJG

From dextrous85 at gmail.com  Tue Oct 21 17:37:34 2008
From: dextrous85 at gmail.com (vishwajeet singh)
Date: Tue, 21 Oct 2008 11:37:34 -0400
Subject: [Tutor] Providing Solutions for all the Common Questions
In-Reply-To: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
References: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
Message-ID: <5487b3060810210837l14840b10o631eba815b648fff@mail.gmail.com>

That seems to be nice idea.
we can look into mailing archives and pick problems from there.

Congratulations and thanks for nice initiative.

keep the good work

On Tue, Oct 21, 2008 at 10:06 AM, Calvin Spealman <ironfroggy at gmail.com>wrote:

> There was a discussion in the #python channel over at freenode about the
> common questions we seem to field daily. These often revolve around problems
> a lot of people need solutions for, and for which we have specific answers
> to we always give. A lot of times this leads to teeth grinding as we try to
> convince people about our advice. Why else are they asking if they then
> argue with the answers they get? This takes a lot of time and energy, so a
> number of us are starting a project to produce tutorials, guides,
> and explanations to back up a lot of these solutions.
> For example, a lot of people look to write an irc bot when they learn
> Python, and often they either plan or are suggested to use Twisted. A
> tutorial specifically for this need is being written.
>
> We've decided to come here to organize this, as it seems to fit.
>
> So there are some organizational issues to approach. I thought AppEngine
> would be a good place to host everything, so I've already registered
> pythonguides.appspot.com and plan to throw up a basic Wiki to start. Going
> forward there are some things I want to implement there to support our
> specific needs. For now, its just a free host.
>
> One other initial need is to collect the problems we need to provide our
> solutions for. So, what do we people ask over and over?
>
> --
> Read my blog! I depend on your acceptance of my opinion! I am interesting!
> http://techblog.ironfroggy.com/
> Follow me if you're into that sort of thing:
> http://www.twitter.com/ironfroggy
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/9ae60eb9/attachment.htm>

From Mike.Hansen at atmel.com  Tue Oct 21 17:38:29 2008
From: Mike.Hansen at atmel.com (Hansen, Mike)
Date: Tue, 21 Oct 2008 09:38:29 -0600
Subject: [Tutor] Providing Solutions for all the Common Questions
In-Reply-To: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
References: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
Message-ID: <7941B2693F32294AAF16C26B679A258D043D090C@csomb01.corp.atmel.com>

 

> -----Original Message-----
> From: tutor-bounces+mike.hansen=atmel.com at python.org 
> [mailto:tutor-bounces+mike.hansen=atmel.com at python.org] On 
> Behalf Of Calvin Spealman
> Sent: Tuesday, October 21, 2008 8:07 AM
> To: tutor at python.org
> Subject: [Tutor] Providing Solutions for all the Common Questions
> 
> There was a discussion in the #python channel over at 
> freenode about the common questions we seem to field daily. 
> These often revolve around problems a lot of people need 
> solutions for, and for which we have specific answers to we 
> always give. A lot of times this leads to teeth grinding as 
> we try to convince people about our advice. Why else are they 
> asking if they then argue with the answers they get? This 
> takes a lot of time and energy, so a number of us are 
> starting a project to produce tutorials, guides, and 
> explanations to back up a lot of these solutions.
> 
> For example, a lot of people look to write an irc bot when 
> they learn Python, and often they either plan or are 
> suggested to use Twisted. A tutorial specifically for this 
> need is being written.
> 
> We've decided to come here to organize this, as it seems to fit. 
> 
> 
> So there are some organizational issues to approach. I 
> thought AppEngine would be a good place to host everything, 
> so I've already registered pythonguides.appspot.com and plan 
> to throw up a basic Wiki to start. Going forward there are 
> some things I want to implement there to support our specific 
> needs. For now, its just a free host.
> 
> One other initial need is to collect the problems we need to 
> provide our solutions for. So, what do we people ask over and over?
> 
> -- 
> Read my blog! I depend on your acceptance of my opinion! I am 
> interesting!
> http://techblog.ironfroggy.com/
> Follow me if you're into that sort of thing: 
> http://www.twitter.com/ironfroggy

A long time ago in a Python galaxy far far away, a tutor FAQ was written. It has been bounced around. I found it at http://effbot.org/pyfaq/tutor-index.htm. Some of these entries could use some updating. A basic wiki for these FAQs would be great.

Mike 

From kent37 at tds.net  Tue Oct 21 17:41:03 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 11:41:03 -0400
Subject: [Tutor] appending to a utf-16 encoded text file
In-Reply-To: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
References: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
Message-ID: <1c2a2c590810210841x7677de15r923a1cfe2c2d7a2@mail.gmail.com>

On Tue, Oct 21, 2008 at 9:52 AM, Tim Brown <tocb2003 at yahoo.co.uk> wrote:
> Hi,
> I'm trying to create and append unicode strings to a utf-16 text file.
> The best I could come up with was to use codecs.open() with an
> encoding of 'utf-16' but when I do an append I get another UTF16 BOM
> put into the file which other programs do not expect to see :-(
> Is there some way to stop codecs from doing this or is there a better
> way to create and add data to a utf-16 text file?

IIRC the UTF-16BE and UTF-16LE codecs don't use BOMs.

You could also convert the unicode strings to str yourself and open
the file as plain text.

Kent

From kent37 at tds.net  Tue Oct 21 17:45:50 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 11:45:50 -0400
Subject: [Tutor] Providing Solutions for all the Common Questions
In-Reply-To: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
References: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
Message-ID: <1c2a2c590810210845ndb49bfdob1431c54b8ca471a@mail.gmail.com>

On Tue, Oct 21, 2008 at 10:06 AM, Calvin Spealman <ironfroggy at gmail.com> wrote:
> There was a discussion in the #python channel over at freenode about the
> common questions we seem to field daily.
> We've decided to come here to organize this, as it seems to fit.

Welcome. Please subscribe to the list if you want to use it as a
discussion forum!

> One other initial need is to collect the problems we need to provide our
> solutions for. So, what do we people ask over and over?

A previous effort on this list led to
http://effbot.org/pyfaq/tutor-index.htm

My own Kent's Korner articles are to some extent an attempt to write
up answers to questions that I am tired of answering:
http://personalpages.tds.net/~kent37/kk/index.html

Kent

From sirgnip at gmail.com  Tue Oct 21 18:10:47 2008
From: sirgnip at gmail.com (Scott Nelson)
Date: Tue, 21 Oct 2008 11:10:47 -0500
Subject: [Tutor] Providing Solutions for all the Common Questions
In-Reply-To: <1c2a2c590810210845ndb49bfdob1431c54b8ca471a@mail.gmail.com>
References: <76fd5acf0810210706g243ab4f1u75e40b8d35676435@mail.gmail.com>
	<1c2a2c590810210845ndb49bfdob1431c54b8ca471a@mail.gmail.com>
Message-ID: <2682ac9b0810210910h53d72959t39233f57ff471120@mail.gmail.com>

To throw out an idea...

http://www.showmedo.com/ is a site that believes that learning-by-watching
is a very effective way to teach people new skills.  So, they host lots of
(user-generated) screencasts (usually 5-10 minutes) that show people how to
do things.  Because the site is Python focused, there are 350+ videos on
learning Python (150+ beginner oriented vids).  Would it be helpful to take
the most common questions and create screencasts that demonstre the answers
to common questions, post them to ShowMeDo and get a collection of links
togeher?  Just a thought...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/6c3cdcfa/attachment.htm>

From john.ertl at navy.mil  Tue Oct 21 19:04:26 2008
From: john.ertl at navy.mil (Ertl, John C CIV 63134)
Date: Tue, 21 Oct 2008 10:04:26 -0700
Subject: [Tutor] Python 2.4 threading
Message-ID: <FFE18EA2-8356-4C85-BB19-84283AEC6186@mimectl>

Classification: UNCLASSIFIED 
Caveat (s): FOUO

All,

I have a program that basically loops through two loops and I wanted to speedup the stuff inside the second loop so I thought threading would be a good idea but I am having a hard time getting it to work.  All of the examples I have seen that use a Queu have had the threaded stuff inside its own class.  I have tired that but I am not getting it.

Could anyone give me some hints on how I might set this up.  Below is an outline of my current program.  What do I need to do to thread the inside loop.

Many of the functions depicted below inherit function from other modules.

class weather(a bunch of stuff)

     def 1

     def 2

     def3

     defetc


weax = weather()

.....stuff.....

for each in outsideloop:

        def1
        defn

        for each in insideloop:

                def1
                def2
                defn


I have tried to take the inside loop and make it a class but there are so many functions , some inherited that are used on the inside and outside loop that I am getting errors all over the place.  Is it possible to thread without it being its own class?  

Thanks for the ideas and help.


John Ertl
Meteorologist

FNMOC
7 Grace Hopper Ave.
Monterey, CA 93943
(831) 656-5704
john.ertl at navy.mil

Classification: UNCLASSIFIED 
Caveat (s): FOUO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/a9a6ec71/attachment.htm>

From malaclypse2 at gmail.com  Tue Oct 21 19:35:37 2008
From: malaclypse2 at gmail.com (Jerry Hill)
Date: Tue, 21 Oct 2008 13:35:37 -0400
Subject: [Tutor] appending to a utf-16 encoded text file
In-Reply-To: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
References: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
Message-ID: <16651e80810211035y49701c69ve7be02f623e12255@mail.gmail.com>

On Tue, Oct 21, 2008 at 9:52 AM, Tim Brown <tocb2003 at yahoo.co.uk> wrote:
> Hi,
> I'm trying to create and append unicode strings to a utf-16 text file.
> The best I could come up with was to use codecs.open() with an
> encoding of 'utf-16' but when I do an append I get another UTF16 BOM
> put into the file which other programs do not expect to see :-(
> Is there some way to stop codecs from doing this or is there a better
> way to create and add data to a utf-16 text file?

That appears to be bug 1701389 (http://bugs.python.org/issue1701389),
which was closed as "Won't Fix" last year.

You should be able to work around it by doing the encoding yourself, like this:

my_file = open("my_utf16_file.txt", "ab")
my_file.write(my_unicode_str.encode("utf16"))

-- 
Jerry

From roadierich at googlemail.com  Tue Oct 21 20:26:05 2008
From: roadierich at googlemail.com (Richard Lovely)
Date: Tue, 21 Oct 2008 19:26:05 +0100
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <1c2a2c590810210823r1d24115y320bb8c2b3016940@mail.gmail.com>
References: <233048.20017.qm@web38107.mail.mud.yahoo.com>
	<48FDEAA7.5050504@gmail.com>
	<1c2a2c590810210823r1d24115y320bb8c2b3016940@mail.gmail.com>
Message-ID: <f0b4202b0810211126s2ab478a8vb0b93b2e970ed2af@mail.gmail.com>

I felt I need to appolgise for my first post in this thread...

I don't have internet access, and I've yet to find a public computer
with Python, so I'm unable to test any code I write.  I'm going have
to discpline myself not to post to here unless its: a) a problem of my
own, or b) an answer that doesn't contain code...

I also have nothing like the experience of some of you guys, who I'm
pretty much in awe of...

If I'm tempted again, I might have to remove myself from the list.

I'm just glad my session timed out before I was able to send the
other, more useless message.  (it's done that twice now, and I suppose
I should count myself as lucky...)

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com

From kent37 at tds.net  Tue Oct 21 21:06:09 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 15:06:09 -0400
Subject: [Tutor] Python 2.4 threading
In-Reply-To: <FFE18EA2-8356-4C85-BB19-84283AEC6186@mimectl>
References: <FFE18EA2-8356-4C85-BB19-84283AEC6186@mimectl>
Message-ID: <1c2a2c590810211206w179ad95at3cf43315d94bd291@mail.gmail.com>

On Tue, Oct 21, 2008 at 1:04 PM, Ertl, John C CIV 63134
<john.ertl at navy.mil> wrote:
> Classification: UNCLASSIFIED
> Caveat (s): FOUO
>
> All,
>
> I have a program that basically loops through two loops and I wanted to
> speedup the stuff inside the second loop so I thought threading would be a
> good idea but I am having a hard time getting it to work.  All of the
> examples I have seen that use a Queu have had the threaded stuff inside its
> own class.  I have tired that but I am not getting it.

You don't need a class to use threading. This example uses ordinary functions:
http://blog.doughellmann.com/2007/04/pymotw-queue.html

However if your program is compute-bound threading won't help.

Kent

From kent37 at tds.net  Tue Oct 21 21:14:16 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 15:14:16 -0400
Subject: [Tutor] finding numbers in range of of numbers
In-Reply-To: <f0b4202b0810211126s2ab478a8vb0b93b2e970ed2af@mail.gmail.com>
References: <233048.20017.qm@web38107.mail.mud.yahoo.com>
	<48FDEAA7.5050504@gmail.com>
	<1c2a2c590810210823r1d24115y320bb8c2b3016940@mail.gmail.com>
	<f0b4202b0810211126s2ab478a8vb0b93b2e970ed2af@mail.gmail.com>
Message-ID: <1c2a2c590810211214w5a0dff52xa3d9fcd40b290444@mail.gmail.com>

On Tue, Oct 21, 2008 at 2:26 PM, Richard Lovely
<roadierich at googlemail.com> wrote:
> I felt I need to appolgise for my first post in this thread...

I don't know why...

> I don't have internet access, and I've yet to find a public computer
> with Python, so I'm unable to test any code I write.  I'm going have
> to discpline myself not to post to here unless its: a) a problem of my
> own, or b) an answer that doesn't contain code...
>
> I also have nothing like the experience of some of you guys, who I'm
> pretty much in awe of...

We all were beginners once. Doing your best to answer questions is a
good way to learn. Generally the really boneheaded answers are
corrected so you don't have to worry about making a mistake.

Kent

From malaclypse2 at gmail.com  Tue Oct 21 21:18:22 2008
From: malaclypse2 at gmail.com (Jerry Hill)
Date: Tue, 21 Oct 2008 15:18:22 -0400
Subject: [Tutor] Python in a web browser (was Re: finding numbers in range
	of of numbers)
Message-ID: <16651e80810211218y7f5dc1beu160f25081aad43b4@mail.gmail.com>

On Tue, Oct 21, 2008 at 2:26 PM, Richard Lovely
<roadierich at googlemail.com> wrote:
> I don't have internet access, and I've yet to find a public computer
> with Python, so I'm unable to test any code I write.  I'm going have
> to discpline myself not to post to here unless its: a) a problem of my
> own, or b) an answer that doesn't contain code...

There are some neat things you can do to get around this limitation,
at least a little bit.  There are at least two places you can bring up
an interactive python interpreted right inside a web browser.

http://try-python.mired.org/  Appears to be a python 2.5.2 interpreter
embedded in a web page.

http://www.voidspace.org.uk/ironpython/silverlight-console/console.html
This one is an IronPython interpreter (I don't know what version),
embedded via SilverLight.

I'm pretty sure that both of those are pretty limited in
functionality, but you can at least play with some basic functionality
without having python installed locally.

-- 
Jerry

From nephish at gmail.com  Tue Oct 21 22:34:23 2008
From: nephish at gmail.com (shawn bright)
Date: Tue, 21 Oct 2008 15:34:23 -0500
Subject: [Tutor] how to see a number as two bytes
In-Reply-To: <gdj2tu$iva$1@ger.gmane.org>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<gdj2tu$iva$1@ger.gmane.org>
Message-ID: <384c93600810211334qdc192ddw8fb419b731f96e9f@mail.gmail.com>

Thanks for all your help on this, gents.
found what works.
shawn

On Mon, Oct 20, 2008 at 6:06 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "shawn bright" <nephish at gmail.com> wrote
>
>  i have a script that needs to send a number as two bytes.
>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>
>
> One way is to use the struct module.
> It has the advantage of allowing selection of big endian(>) or little
> endian(<) representation etc. The H symbol can be used for a short
> integer - ie 2 bytes...
>
> eg
>
>  import struct
>>>> b = struct.pack(">H", 279)
>>>> b
>>>>
>>> '\x01\x17'
>
>> b = struct.pack("<H", 279)
>>>> b
>>>>
>>> '\x17\x01'
>
>>
>>>>
> Note that Python will print bytes with printable representations as
> the character form but the data is still two bytes.
>
> eg
>
>> struct.pack("H", 33)
>>>>
>>> '!\x00'
>
>> chr(33)
>>>>
>>> '!'
>
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/2981b1ba/attachment.htm>

From bgailer at gmail.com  Tue Oct 21 22:40:29 2008
From: bgailer at gmail.com (bob gailer)
Date: Tue, 21 Oct 2008 16:40:29 -0400
Subject: [Tutor] decision structures
In-Reply-To: <AAC098868E7A8C479AAEC93921640FC22D21A33BD6@emaildb5.roberts.edu>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>,
	<48FD29DD.9070006@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD2@emaildb5.roberts.edu>,
	<48FDC812.4060409@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD4@emaildb5.roberts.edu>,
	<48FDE655.6080707@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD6@emaildb5.roberts.edu>
Message-ID: <48FE3E3D.1070001@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/3d9f56df/attachment.htm>

From sander.sweers at gmail.com  Tue Oct 21 23:09:35 2008
From: sander.sweers at gmail.com (Sander Sweers)
Date: Tue, 21 Oct 2008 23:09:35 +0200
Subject: [Tutor] Multiple lists from single list with nested lists
In-Reply-To: <1c2a2c590810201636l474e2992qb8f57514fca44038@mail.gmail.com>
References: <b65fbb130810201433w416681dk97f27c63fd7dfdcc@mail.gmail.com>
	<1c2a2c590810201636l474e2992qb8f57514fca44038@mail.gmail.com>
Message-ID: <b65fbb130810211409o42b2433bvd6d03272a32d171e@mail.gmail.com>

On Tue, Oct 21, 2008 at 01:36, Kent Johnson <kent37 at tds.net> wrote:
>> somelist = ['Test1', 'Text2', ['1', '2'], 'Text3']
>> templist = []
>> for x in range(len(somelist[2])):
>>    templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]])
>
> Is it always just the third item that is a list? If so I think your
> solution is not too bad.

The actual list is 12 items long (python lenght) and the 6, 7 and 8th
item should be lists after I split them. A sanitized example:

['SOMENAME', '1234567890', '"TEXT1"', 'TEXT2', '59', '',
'10/03;10/15', '10/09;10/20', '1;70', '', '', '']

> or use a list comprehension:
> templist = [ somelist[0:2] + [x] + somelist[3:] for x in somelist ]

This did not work but the below did ;-)
templist = [ somelist[:1] + [x] + somelist[3:] for x in somelist[2] ]

It gave me some great pointers on how to handle this.

Thanks
Sander

From christopher.henk at allisontransmission.com  Tue Oct 21 23:18:23 2008
From: christopher.henk at allisontransmission.com (christopher.henk at allisontransmission.com)
Date: Tue, 21 Oct 2008 17:18:23 -0400
Subject: [Tutor] decision structures
In-Reply-To: <48FE3E3D.1070001@gmail.com>
Message-ID: <OF7B4703EB.47D1BB7C-ON852574E9.0072FF53-852574E9.00750A7B@gm.com>

> Perhaps someone else will help you. I won't offer anything more until 
you respond to a lot more of my questions and comments.
> 

Read what Bob has written back to you and try it or ask questions related 
to it if you don't understand something he said.

> AND PLEASE reply to tutor at python.org as well as whoever responds to you.
> 
> Brummert_Brandon wrote: 
> here is the one that I am still stuck on.  not much has changed since 
last time.
<snip>
> def main():
>     currentdate= input ("What is the date (mm/dd/yyyy)?:")

Try printing out the value of currentdate here and see what you get. Bob 
has mentioned that you may have some issues with your result and gave a 
suggestion on how to fix it.  It has also been mentioned several times in 
other current threads on the list, since it is a common point of 
confusion.

Also, one of the nice things about Python is you can use the interactive 
interpreter to see what you would get as a response to your code.
Try starting up Python and just typing in the line:
input ("Type something here:")

and then enter a date.

What do you get as an answer?
Is it what you expected?

try is again with typing different things in and see what answers you get.

What is different between what the user is typing in this program and your 
previous program and what you are doing with that input?

Once you get past this point we can address the rest of the program. 

The people on the list are very happy to help but will not do the work for 
you.  You need to read what the responses are and work with the tutors.

hope that helps get you started,

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/a4b4b09f/attachment-0001.htm>

From rabidpoobear at gmail.com  Tue Oct 21 23:57:02 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 21 Oct 2008 16:57:02 -0500
Subject: [Tutor] how to see a number as two bytes
In-Reply-To: <384c93600810211334qdc192ddw8fb419b731f96e9f@mail.gmail.com>
References: <384c93600810200847o6130e415o3a552d935d332505@mail.gmail.com>
	<gdj2tu$iva$1@ger.gmane.org>
	<384c93600810211334qdc192ddw8fb419b731f96e9f@mail.gmail.com>
Message-ID: <dfeb4470810211457v8fd2201s66fdd99421a79d0d@mail.gmail.com>

Nice mention of the struct module, Alan.  I had forgotten about it and
I just finished an app that really could've been simplified by it.  I
might retool it to use struct when I have to revisit it for the next
part of my class assignment.

On Tue, Oct 21, 2008 at 3:34 PM, shawn bright <nephish at gmail.com> wrote:
> Thanks for all your help on this, gents.
> found what works.
> shawn
>
> On Mon, Oct 20, 2008 at 6:06 PM, Alan Gauld <alan.gauld at btinternet.com>
> wrote:
>>
>> "shawn bright" <nephish at gmail.com> wrote
>>
>>> i have a script that needs to send a number as two bytes.
>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>
>> One way is to use the struct module.
>> It has the advantage of allowing selection of big endian(>) or little
>> endian(<) representation etc. The H symbol can be used for a short
>> integer - ie 2 bytes...
>>
>> eg
>>
>>>>> import struct
>>>>> b = struct.pack(">H", 279)
>>>>> b
>>
>> '\x01\x17'
>>>>>
>>>>> b = struct.pack("<H", 279)
>>>>> b
>>
>> '\x17\x01'
>>>>>
>>
>> Note that Python will print bytes with printable representations as
>> the character form but the data is still two bytes.
>>
>> eg
>>>>>
>>>>> struct.pack("H", 33)
>>
>> '!\x00'
>>>>>
>>>>> chr(33)
>>
>> '!'
>>
>>
>> HTH,
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.freenetpages.co.uk/hp/alan.gauld
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From kent37 at tds.net  Wed Oct 22 04:01:29 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 21 Oct 2008 22:01:29 -0400
Subject: [Tutor] Multiple lists from single list with nested lists
In-Reply-To: <b65fbb130810211409o42b2433bvd6d03272a32d171e@mail.gmail.com>
References: <b65fbb130810201433w416681dk97f27c63fd7dfdcc@mail.gmail.com>
	<1c2a2c590810201636l474e2992qb8f57514fca44038@mail.gmail.com>
	<b65fbb130810211409o42b2433bvd6d03272a32d171e@mail.gmail.com>
Message-ID: <1c2a2c590810211901p73b1b3ddtc716bbc9349ddd6c@mail.gmail.com>

On Tue, Oct 21, 2008 at 5:09 PM, Sander Sweers <sander.sweers at gmail.com> wrote:

> This did not work but the below did ;-)
> templist = [ somelist[:1] + [x] + somelist[3:] for x in somelist[2] ]

somelist[:1] doesn't include somelist[1] so I think you are missing
one element of your original list.

List slices like [0:2] or [:1] are up-to-but-not-including the second index.

Kent

From metolone+gmane at gmail.com  Wed Oct 22 04:05:44 2008
From: metolone+gmane at gmail.com (Mark Tolonen)
Date: Tue, 21 Oct 2008 19:05:44 -0700
Subject: [Tutor] appending to a utf-16 encoded text file
References: <890000.57633.qm@web27805.mail.ukl.yahoo.com>
	<48FDF742.5080907@timgolden.me.uk>
Message-ID: <gdm1pg$hcl$1@ger.gmane.org>


"Tim Golden" <mail at timgolden.me.uk> wrote in message 
news:48FDF742.5080907 at timgolden.me.uk...
> Tim Brown wrote:
>> Hi,
>> I'm trying to create and append unicode strings to a utf-16 text file.
>> The best I could come up with was to use codecs.open() with an encoding 
>> of 'utf-16' but when I do an append I get another UTF16 BOM put into the 
>> file which other programs do not expect to see :-(
>> Is there some way to stop codecs from doing this or is there a better
>> way to create and add data to a utf-16 text file?
>
>
> Well, there's nothing to stop you opening it "raw", as it were,
> and just appending unicode encoded as utf16.
>
> <code>
> s = u"The cat sat on the mat"
> f = open ("utf16.txt", "wb")
> for word in s.split ():
>  f.write (word.encode ("utf16") + " ")
>
> f.close ()
>
> </code>
>
> TJG

Result: The??????sat?????the?????

word.encode('utf16') adds a BOM every time, and the space wasn't encoded.

utf-16-le and utf-16-be don't add the BOM.  This works:

import codecs
s = u"The cat sat on the mat"
f = codecs.open("utf16.txt","wb","utf-16-le")
f.write(u'\ufeff') # if you want the BOM
for word in s.split ():
    f.write (word + u' ')
f.close()

-Mark



From amit.pureenergy at gmail.com  Wed Oct 22 04:21:39 2008
From: amit.pureenergy at gmail.com (amit sethi)
Date: Wed, 22 Oct 2008 07:51:39 +0530
Subject: [Tutor] (no subject)
Message-ID: <da81a0a80810211921q3bbcd884m3c04fcb17507a4dc@mail.gmail.com>

Hi can any body give me an example as to how i can use Incremental Parser in
xml.sax

-- 
A-M-I-T S|S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081022/abb90c39/attachment.htm>

From mail at timgolden.me.uk  Wed Oct 22 09:52:54 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Wed, 22 Oct 2008 08:52:54 +0100
Subject: [Tutor] appending to a utf-16 encoded text file
In-Reply-To: <gdm1pg$hcl$1@ger.gmane.org>
References: <890000.57633.qm@web27805.mail.ukl.yahoo.com>	<48FDF742.5080907@timgolden.me.uk>
	<gdm1pg$hcl$1@ger.gmane.org>
Message-ID: <48FEDBD6.1060907@timgolden.me.uk>

Mark Tolonen wrote:
> 
> "Tim Golden" <mail at timgolden.me.uk> wrote in message 
> news:48FDF742.5080907 at timgolden.me.uk...
>> Tim Brown wrote:
>>> Hi,
>>> I'm trying to create and append unicode strings to a utf-16 text file.
>>> The best I could come up with was to use codecs.open() with an 
>>> encoding of 'utf-16' but when I do an append I get another UTF16 BOM 
>>> put into the file which other programs do not expect to see :-(
>>> Is there some way to stop codecs from doing this or is there a better
>>> way to create and add data to a utf-16 text file?
>>
>>
>> Well, there's nothing to stop you opening it "raw", as it were,
>> and just appending unicode encoded as utf16.
>>
>> <code>
>> s = u"The cat sat on the mat"
>> f = open ("utf16.txt", "wb")
>> for word in s.split ():
>>  f.write (word.encode ("utf16") + " ")
>>
>> f.close ()
>>
>> </code>
>>
>> TJG
> 
> Result: The??????sat?????the?????
> 
> word.encode('utf16') adds a BOM every time, and the space wasn't encoded.
> 
> utf-16-le and utf-16-be don't add the BOM.  This works:
> 
> import codecs
> s = u"The cat sat on the mat"
> f = codecs.open("utf16.txt","wb","utf-16-le")
> f.write(u'\ufeff') # if you want the BOM
> for word in s.split ():
>    f.write (word + u' ')
> f.close()

My apologies. I did run the code before posting, but I did no
more than glance at the result in Notepad. Sorry. Should have
used le/be as you've done.

TJG

From alan.gauld at btinternet.com  Wed Oct 22 10:19:17 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 22 Oct 2008 09:19:17 +0100
Subject: [Tutor] XML parsing with SAX was Re: (no subject)
References: <da81a0a80810211921q3bbcd884m3c04fcb17507a4dc@mail.gmail.com>
Message-ID: <gdmnm5$6rv$1@ger.gmane.org>

"amit sethi" <amit.pureenergy at gmail.com> wrote

Please, always use a meaningful subject line when posting!
and do not reply to an existing thread, changing the subject.
These things mess up threaded reading tools such as gmane
and newsreaders. This reduces your chances of a reply.

> Hi can any body give me an example as to how i can use Incremental 
> Parser in
> xml.sax

If you look in the XML Topic Guide section of the Python web site 
there
is a full tutorial on using SAX. This is a good starting point:

http://pyxml.sourceforge.net/topics/docs.html

But frankly I'd strongly advise you to look at ElementTree if you are
parsing XML. Its much easier to use. The only time I'd use sax 
nowadays
is if I was porting code from some other sax based solution.

http://effbot.org/zone/element-index.htm

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



From amit.pureenergy at gmail.com  Wed Oct 22 15:07:39 2008
From: amit.pureenergy at gmail.com (amit sethi)
Date: Wed, 22 Oct 2008 18:37:39 +0530
Subject: [Tutor] XML parsing with SAX
Message-ID: <da81a0a80810220607h5c7c710aq8f6e6151ff37c6d8@mail.gmail.com>

Sorry , I didn't follow the format of posting to the group. Well I am new to
xml and python . What I basically want to do is to read elements from the
xml which is by the way large ~2GB and read the attributes and make a
decision as to whether i want to keep that element or not . I am told that
xml.sax is good for reading a large xml file because it can read from a
stream but what about writing the xml file back  Thank you for your help.

On Wed, Oct 22, 2008 at 1:49 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "amit sethi" <amit.pureenergy at gmail.com> wrote
>
> Please, always use a meaningful subject line when posting!
> and do not reply to an existing thread, changing the subject.
> These things mess up threaded reading tools such as gmane
> and newsreaders. This reduces your chances of a reply.
>
>  Hi can any body give me an example as to how i can use Incremental Parser
>> in
>> xml.sax
>>
>
> If you look in the XML Topic Guide section of the Python web site there
> is a full tutorial on using SAX. This is a good starting point:
>
> http://pyxml.sourceforge.net/topics/docs.html
>
> But frankly I'd strongly advise you to look at ElementTree if you are
> parsing XML. Its much easier to use. The only time I'd use sax nowadays
> is if I was porting code from some other sax based solution.
>
> http://effbot.org/zone/element-index.htm
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081022/e21b7a5b/attachment.htm>

From a.t.hofkamp at tue.nl  Wed Oct 22 15:17:30 2008
From: a.t.hofkamp at tue.nl (A.T.Hofkamp)
Date: Wed, 22 Oct 2008 15:17:30 +0200
Subject: [Tutor] XML parsing with SAX
In-Reply-To: <da81a0a80810220607h5c7c710aq8f6e6151ff37c6d8@mail.gmail.com>
References: <da81a0a80810220607h5c7c710aq8f6e6151ff37c6d8@mail.gmail.com>
Message-ID: <48FF27EA.1000708@tue.nl>

amit sethi wrote:
> Sorry , I didn't follow the format of posting to the group. Well I am new to
> xml and python . What I basically want to do is to read elements from the
> xml which is by the way large ~2GB and read the attributes and make a
> decision as to whether i want to keep that element or not . I am told that
> xml.sax is good for reading a large xml file because it can read from a
> stream but what about writing the xml file back  Thank you for your help.

In general, we help with Python problems rather writing applications for free.

You 'll either have to start paying somebody to do the work for you (in which 
case this is the wrong place to ask), or you'll have to make your hands dirty, 
and start reading/learning/coding/experimenting to solve your problem.


When you get stuck, you can ask how to overcome that obstacle (usually by 
scaling the problem down to a small example), and we will try to find an answer.


Sincerely,
Albert

From kent37 at tds.net  Wed Oct 22 16:25:14 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 22 Oct 2008 10:25:14 -0400
Subject: [Tutor] XML parsing with SAX
In-Reply-To: <da81a0a80810220607h5c7c710aq8f6e6151ff37c6d8@mail.gmail.com>
References: <da81a0a80810220607h5c7c710aq8f6e6151ff37c6d8@mail.gmail.com>
Message-ID: <1c2a2c590810220725v4bff9dfai7c7771dcc97179d7@mail.gmail.com>

On Wed, Oct 22, 2008 at 9:07 AM, amit sethi <amit.pureenergy at gmail.com> wrote:
> Sorry , I didn't follow the format of posting to the group. Well I am new to
> xml and python . What I basically want to do is to read elements from the
> xml which is by the way large ~2GB and read the attributes and make a
> decision as to whether i want to keep that element or not . I am told that
> xml.sax is good for reading a large xml file because it can read from a
> stream but what about writing the xml file back  Thank you for your help.

The iterparse() method of ElementTree might be useful, it allows you
to prune the parsed tree as it is built:
http://effbot.org/zone/element-iterparse.htm

The resulting tree can be written back to a file using the write() method:
http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm#elementtree.ElementTree.ElementTree.write-method

Kent

From john.ertl at navy.mil  Wed Oct 22 23:44:55 2008
From: john.ertl at navy.mil (Ertl, John C CIV 63134)
Date: Wed, 22 Oct 2008 14:44:55 -0700
Subject: [Tutor] threading not working how about fork?
In-Reply-To: <1c2a2c590810211206w179ad95at3cf43315d94bd291@mail.gmail.com>
References: <FFE18EA2-8356-4C85-BB19-84283AEC6186@mimectl>,
	<1c2a2c590810211206w179ad95at3cf43315d94bd291@mail.gmail.com>
Message-ID: <A1BCCAE1-42DB-45DF-88D5-88134FED90F1@mimectl>

Classification: UNCLASSIFIED 
Caveat (s): FOUO

Thanks for the help and I am looking into the pyprocessing but threading is causing too many headaches (I may have to rewrite things).  Lets say I have something as simple as below:

def takeTime(a):
     print "Started %s" % a
     time.sleep(10)
     print "Ended %s" % a

for each in [1,2,3,4,5]:
   pid = os.fork()
   takeTime(each)

Each time the function is called it waits 10 seconds.  And if I run it as above it does the first and waits 10 seconds then the second and waits ten seconds...etc.

Wow could I get it to run through all 5 "forks" without waiting for the previous one to complete?  That was all five would be done in about 10 seconds.

This is simpler than my real problem but I can not even figure this one out. 

Thanks for the help.

John Ertl
Meteorologist

FNMOC
7 Grace Hopper Ave.
Monterey, CA 93943
(831) 656-5704
john.ertl at navy.mil

Classification: UNCLASSIFIED 
Caveat (s): FOUO

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081022/fbb2512a/attachment.htm>

From kent37 at tds.net  Thu Oct 23 00:32:01 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 22 Oct 2008 18:32:01 -0400
Subject: [Tutor] threading not working how about fork?
In-Reply-To: <A1BCCAE1-42DB-45DF-88D5-88134FED90F1@mimectl>
References: <FFE18EA2-8356-4C85-BB19-84283AEC6186@mimectl>
	<1c2a2c590810211206w179ad95at3cf43315d94bd291@mail.gmail.com>
	<A1BCCAE1-42DB-45DF-88D5-88134FED90F1@mimectl>
Message-ID: <1c2a2c590810221532j52a1058re7af230e4b7978d3@mail.gmail.com>

On Wed, Oct 22, 2008 at 5:44 PM, Ertl, John C CIV 63134
<john.ertl at navy.mil> wrote:
> Classification: UNCLASSIFIED
> Caveat (s): FOUO

??

> Thanks for the help and I am looking into the pyprocessing but threading is
> causing too many headaches (I may have to rewrite things).  Lets say I have
> something as simple as below:
>
> def takeTime(a):
>      print "Started %s" % a
>      time.sleep(10)
>      print "Ended %s" % a
>
> for each in [1,2,3,4,5]:
>    pid = os.fork()
>    takeTime(each)
>
> Each time the function is called it waits 10 seconds.  And if I run it as
> above it does the first and waits 10 seconds then the second and waits ten
> seconds...etc.

You are calling takeTime() from both the parent and child process, and
you are spawning additional processes from the child process as well.
Try
if os.fork():
  takeTime(each)
  break

Kent

From bgailer at gmail.com  Thu Oct 23 03:41:28 2008
From: bgailer at gmail.com (bob gailer)
Date: Wed, 22 Oct 2008 21:41:28 -0400
Subject: [Tutor] decision structures
In-Reply-To: <48FE3E3D.1070001@gmail.com>
References: <AAC098868E7A8C479AAEC93921640FC22D21A33BD0@emaildb5.roberts.edu>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD1@emaildb5.roberts.edu>,
	<48FD29DD.9070006@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD2@emaildb5.roberts.edu>,
	<48FDC812.4060409@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD4@emaildb5.roberts.edu>,
	<48FDE655.6080707@gmail.com>
	<AAC098868E7A8C479AAEC93921640FC22D21A33BD6@emaildb5.roberts.edu>
	<48FE3E3D.1070001@gmail.com>
Message-ID: <48FFD648.3050708@gmail.com>

I hope we did not scare you away. Do you still want help?

If you get a solution elsewhere would you share it with us so we can see 
and celebrate your progress?

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From iaidas4 at gmail.com  Thu Oct 23 12:12:04 2008
From: iaidas4 at gmail.com (i i)
Date: Thu, 23 Oct 2008 15:12:04 +0500
Subject: [Tutor] random equation generator
Message-ID: <6fb034600810230312id60ca61x12d8591ac0388d58@mail.gmail.com>

hi, can u tell me any good tutorial site for pygtk, any that contains detail
explanation of pygtk.
i want to develop a game,that will randomly generate the operands,and the
answer,a user have to chosse from the operators(+,-,*,/).
which function should i use to randomly generate equation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081023/06280898/attachment.htm>

From monte at milanuk.net  Thu Oct 23 06:09:26 2008
From: monte at milanuk.net (Monte Milanuk)
Date: Wed, 22 Oct 2008 21:09:26 -0700 (PDT)
Subject: [Tutor] Need help w/ a for loop
Message-ID: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>

Hello all,

New guy here, so go easy on me ;)

I'm starting to work my way through Python Programming by Zelle, and have hit a bit of a wall on one of the programming exercises in Chapter 3 (#15 if anyone has the book handy).  

What the question ask is:  Write a program that approimates the value of pi by summing the terms of this series: 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11+...  The program should ask the user for 'n', the number of terms to sum, and then output the sum of the first 'n' terms of this series.

Where I am running into problems is how to do the '-' & '+', depending on the value of 'n'.  i.e. if 'n' = 3, it's going to be a - & an +, if 'n' =5 its going to be -, +, -, +, etc.  How to make that work in terms of an algorithm is making my head hurt (and its so early in the book yet... ;) )

Here's what I have thus far:

#   approximate_pi.py
#   Approximates the value of 'pi' by summing the terms of a series.
#

import math

def main():
    print "This program will approximate the value of pi"
    print "to a degree determined by the user. "
    print

    #  get the value of n from the user
    n = input("How many terms do you want me to sum?  ")
    print

    #  create a loop from 1 to n+1, odd)
    for i in range(1,n + 1,2):
        #  each term is '4/i' as it steps thru the loop starting with 1
        x = 4 / i
        #  not sure where to go from here

        
    print
    #  output the sum - convert it to a float just in case
    print "The sum of the numbers you entered is", (float(sum))

    #  calculate the difference between our approximation and Python's pi
    diff = sum - math.pi

    #  output the difference
    print
    print "The difference between your 'pi' & Python's pi is", diff, "."

    

main()


Any assistance or nudges in the right direction would be most appreciated.

Thanks,

Monte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081022/fc3e79c5/attachment.htm>

From srilyk at gmail.com  Thu Oct 23 12:46:20 2008
From: srilyk at gmail.com (W W)
Date: Thu, 23 Oct 2008 05:46:20 -0500
Subject: [Tutor] random equation generator
In-Reply-To: <6fb034600810230312id60ca61x12d8591ac0388d58@mail.gmail.com>
References: <6fb034600810230312id60ca61x12d8591ac0388d58@mail.gmail.com>
Message-ID: <333efb450810230346s33db8c18o5af88d392d447b26@mail.gmail.com>

www.google.com/search?q=pygtk+tutorial
www.google.com/search?q=python+random+generator
www.google.com/search?q=python+dict

If you would like to develop the game, you should first try to develop the
game, and then ask when you get stuck.

If you can't figure out how to get a user to guess between operands '+',
'-', '*', '/' then my guess is you are very new to programming, and this
question shows you are very new to the tutor list. We're happy to help you
find a solution when you get stuck, but we won't write your program for you.
If you're stuck at the planning phase it seems that you may be trying to
tackle a subject that's a little too deep, and you'll find a lot of
difficulty in learning pyGTK.

Here are some assignments for you. Successfully completing these will not
only show that you're willing to learn and take advice, but they will also
help you in your quest to write your game.

tip: search google for the functions you should use, if you don't already
know them. Using the keyword "python" before the functionality will help
narrow your results.

1) Write a progam that will generate 10 random numbers in a /range/ of 0-3,
and print each one out.
After you do this, allow the user to /input/ the number of numbers (i.e. 5
instead of 10)
sample output:
Random Numbers:
0
3
1
2
0
0
2
1
3
1

Please enter a number: 4
0
1
3
1

2) Write a program that allows the user to input a number 0-3, and
determines which operand to print.
Sample output:

Enter a number: 0
Operand: +

Enter a number: 1
Operand: -

Enter a number: 3
Operand: /

Enter a number: 2
Operand: *

Do these things and you'll be well on your way to writing your program!
(also, feel free to use http://pastebin.com to post your code to report on
your progress)

Good luck!
HTH,
Wayne

If and only if you get stuck should you read this!

Seriously! Stop reading here! :)

Tip: Once you have searched google and the python docs for raw_input, while
loop, dict, list, if else, random and read all the documentation you can
find, if you cannot figure out the solution, only then should you ask
another question, and only about the topic on which you can't figure out on
your own!

On Thu, Oct 23, 2008 at 5:12 AM, i i <iaidas4 at gmail.com> wrote:

> hi, can u tell me any good tutorial site for pygtk, any that contains
> detail explanation of pygtk.
> i want to develop a game,that will randomly generate the operands,and the
> answer,a user have to chosse from the operators(+,-,*,/).
> which function should i use to randomly generate equation.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081023/18839384/attachment.htm>

From srilyk at gmail.com  Thu Oct 23 12:56:43 2008
From: srilyk at gmail.com (W W)
Date: Thu, 23 Oct 2008 05:56:43 -0500
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
References: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
Message-ID: <333efb450810230356m24ecfa41xa3406c4d47bd5ed0@mail.gmail.com>

On Wed, Oct 22, 2008 at 11:09 PM, Monte Milanuk <monte at milanuk.net> wrote:

> Hello all,
>
> New guy here, so go easy on me ;)
>

Welcome to python and the tutor list!


> I'm starting to work my way through Python Programming by Zelle, and have
> hit a bit of a wall on one of the programming exercises in Chapter 3 (#15 if
> anyone has the book handy).
>
> What the question ask is:  Write a program that approimates the value of pi
> by summing the terms of this series: 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11+...
> The program should ask the user for 'n', the number of terms to sum, and
> then output the sum of the first 'n' terms of this series.
>
> Where I am running into problems is how to do the '-' & '+', depending on
> the value of 'n'.  i.e. if 'n' = 3, it's going to be a - & an +, if 'n' =5
> its going to be -, +, -, +, etc.  How to make that work in terms of an
> algorithm is making my head hurt (and its so early in the book yet... ;) )
>

Here's a suggestion: look at only the value of the denominator (as the top
is obviously constant at 4, for the sake of pattern searching you only need
to worry about the variable) -

1 - 3 + 5 - 7 + 9 - 11 + ...

Do you notice a pattern? (if it doesn't pop out, read on...)





1+2 = ?
1+4 = ?
1+6 = ?
1+8 = ?
1+10 = ?

If you want a fairly easy way to figure out whether it should be + or -,
take another look at the pattern.

If you need a hint, read past my name.

HTH,
Wayne

Hint: Think of the pattern in terms of relation to 2


WAIT!
Don't read beyond here if you want to discover the solution yourself!




2/2 = 1
4/2 = 2
6/2 = 3
8/2 = 4
etc.


> Here's what I have thus far:
>
> #   approximate_pi.py
> #   Approximates the value of 'pi' by summing the terms of a series.
> #
>
> import math
>
> def main():
>     print "This program will approximate the value of pi"
>     print "to a degree determined by the user. "
>     print
>
>     #  get the value of n from the user
>     n = input("How many terms do you want me to sum?  ")
>     print
>
>     #  create a loop from 1 to n+1, odd)
>     for i in range(1,n + 1,2):
>         #  each term is '4/i' as it steps thru the loop starting with 1
>         x = 4 / i
>         #  not sure where to go from here
>
>
>     print
>     #  output the sum - convert it to a float just in case
>     print "The sum of the numbers you entered is", (float(sum))
>
>     #  calculate the difference between our approximation and Python's pi
>     diff = sum - math.pi
>
>     #  output the difference
>     print
>     print "The difference between your 'pi' & Python's pi is", diff, "."
>
>
>
> main()
>
>
> Any assistance or nudges in the right direction would be most appreciated.
>
> Thanks,
>
> Monte
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081023/d6b7f501/attachment-0001.htm>

From kent37 at tds.net  Thu Oct 23 13:21:43 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 23 Oct 2008 07:21:43 -0400
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
References: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
Message-ID: <1c2a2c590810230421w6a5ec6fep48ac1aacc595e25b@mail.gmail.com>

On Thu, Oct 23, 2008 at 12:09 AM, Monte Milanuk <monte at milanuk.net> wrote:

> def main():
>     print "This program will approximate the value of pi"
>     print "to a degree determined by the user. "
>     print
>
>     #  get the value of n from the user
>     n = input("How many terms do you want me to sum?  ")
>     print
>
>     #  create a loop from 1 to n+1, odd)

Here you should initialize a variable to hold the sum. 'sum' is not a
good name because it is the name of a built-in function. 'total' is
better.

>     for i in range(1,n + 1,2):

Note that this loop has n/2 steps, not n.
>         #  each term is '4/i' as it steps thru the loop starting with 1
>         x = 4 / i

Do you know about integer vs float division? What is the difference
between 4/9 and 4.0/9?

>     #  output the sum - convert it to a float just in case

If it isn't already a float you won't have a very good estimate of pi.

Kent

From bgailer at gmail.com  Thu Oct 23 16:20:01 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 23 Oct 2008 10:20:01 -0400
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
References: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
Message-ID: <49008811.3000808@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081023/fbd746f7/attachment.htm>

From roadierich at googlemail.com  Thu Oct 23 18:40:53 2008
From: roadierich at googlemail.com (Richard Lovely)
Date: Thu, 23 Oct 2008 17:40:53 +0100
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <49008811.3000808@gmail.com>
References: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
	<49008811.3000808@gmail.com>
Message-ID: <f0b4202b0810230940m2b2ad95cp2b8ce83dfb3516d9@mail.gmail.com>

Why not throw in itertools.cycle while you're at it? ;-)

pi = sum(4. / (1+x) * itertools.cycle((1,-1)).next() for x in range(0,
4 * n, 2))

I'd also be so tempted just to call the file 'approximate' (read it
with extension...)

Let's also not forget about integer division...

2008/10/23 bob gailer <bgailer at gmail.com>:
> Monte Milanuk wrote:
>
> Hello all,
>
> New guy here, so go easy on me ;)
>
> We save the whips and chains for the more hardened questers. Newcomers get
> the feathers.
>
>
> I'm starting to work my way through Python Programming by Zelle, and have
> hit a bit of a wall on one of the programming exercises in Chapter 3 (#15 if
> anyone has the book handy).
>
> What the question ask is:  Write a program that approimates the value of pi
> by summing the terms of this series: 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11+...
> The program should ask the user for 'n', the number of terms to sum, and
> then output the sum of the first 'n' terms of this series.
>
> Where I am running into problems is how to do the '-' & '+', depending on
> the value of 'n'.  i.e. if 'n' = 3, it's going to be a - & an +, if 'n' =5
> its going to be -, +, -, +, etc.  How to make that work in terms of an
> algorithm is making my head hurt (and its so early in the book yet... ;) )
>
> There are many ways to handle this. Others have given some hints.
>
> The simplest IMHO is to set the range stride to 4 instead of 2 and then use
> x += 4.0/i - 4.0/(i + 2).
>
> You could also use a multiplier (let's call it m) that alternates between 1
> and -1. Roughly:
>
> x = 0
> m = 1
> for in in range...
>   x += 4.0/i*m
>   m =  -m
>
> For more generality and anticipating more complex algorithms:
>
> import operator
> ops = (operator.add, operator.sub)
> x = 0
> m = 0
> for in in range...
>   x = ops[m](x, 4.0/i)
>   m =  1-m
>
> And just for the heck of it you could write 2 for loops, each with a stride
> of 4. The first would just add all the fractions to be added and the second
> would add all the fractions to be subtracted, then combine them. Throwing in
> the sum function and generator expressions:
> pi = sum(4.0/i for i in range(1, n*2, 4)) - sum(4.0/i for i in range(3, n*2,
> 4))
>
> Applying sum and generator expressions to my original solution you get:
> pi = sum(4.0/i - 4.0/(i + 2) for i in range(1, 4*n, 4))
>
> Ah I can go on can't I? A lot more than you asked for!
>
> --
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
> When we take the time to be aware of our feelings and
> needs we have more satisfying interatctions with others.
> Nonviolent Communication provides tools for this awareness.
> As a coach and trainer I can assist you in learning this process.
> What is YOUR biggest relationship challenge?
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com

From kent37 at tds.net  Thu Oct 23 18:30:21 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 23 Oct 2008 12:30:21 -0400
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <49008811.3000808@gmail.com>
References: <834628.81345.qm@web601.biz.mail.mud.yahoo.com>
	<49008811.3000808@gmail.com>
Message-ID: <1c2a2c590810230930k5a69152ct1e51a248af6179da@mail.gmail.com>

On Thu, Oct 23, 2008 at 10:20 AM, bob gailer <bgailer at gmail.com> wrote:

> import operator
> ops = (operator.add, operator.sub)
> x = 0
> m = 0
> for in in range...
>   x = ops[m](x, 4.0/i)
>   m =  1-m

itertools.cycle(ops) is handy here. Hmm, there is a cute one-line
solution (excluding import and input) that uses itertools.cycle() and
zip()...not sure if this is a homework problem so I won't post it
yet...

Kent

From monte at milanuk.net  Fri Oct 24 05:29:33 2008
From: monte at milanuk.net (Monte Milanuk)
Date: Thu, 23 Oct 2008 20:29:33 -0700 (PDT)
Subject: [Tutor] Need help w/ a for loop
Message-ID: <562371.59459.qm@web601.biz.mail.mud.yahoo.com>

Hello again, and thanks to all of you who extended your help!

Wayne,

Thanks for your examples.  They did end up helping in with finding a pattern to do the odd numbers with.  Maybe I'm not clever enough, but I didn't see how either example could be used for doing the addition/subtraction determination.  Or rather, I found a different way after reading someone else's examples.

Kent,

Thanks for the hint about 'sum', as well as the reminder about float vs. integer math.  Whoops!  As far as whether this is homework or not... not in the traditional sense.  Yes, the book 'Python Programming' is intended as a first-semester comp-sci text, so the questions that I'm working through are probably going to seem an awful lot like homework.  For better or worse, though, the only person assigning 'homework' or grading anything is me.  I am taking some online classes towards an AA degree; sadly, the local community college does not offer (or count) any computer classes online (and with my work schedule, thats the only way that can work for me).  So yes, I do appreciate not being completely spoon-fed as I need to learn this stuff, but no, I'm not 'cheating' on homework for a class per se.

Bob,

Your post was most helpful, in an indirect sort of way.  The examples didn't work directly, or at least they didn't give the right answer (as far as I could tell).  In them was the key (at least, the one I used) to get things working.  The 'x += ...' tidbit was really neat (probably old hat to you) but I couldn't find it in the documentation anywhere - I finally broke down and just started messing with it in the IDLE shell window.  Slick!

Kent, Richard, etc.

While I imagine there are a wide array of ways to do this, especially using more advanced functions or modules... I am trying to work thru this one using the basic tools covered up so far in the book - for loops are about as complex as has been gone into yet.  As such...  I got to beat my head on the screen for a while trying to figure out why some versions did (or didn't) work... including making some very dumb mistakes that kept me working on this for probably a good half-hour to an hour (off and on) longer than I needed to.  Aaarrrgh.

Anyway, here's what I worked out.  Let me know what you think I did right, and what needs tweaked:

IDLE 2.6      
>>> (4.0/1)-(4.0/3)+(4.0/5)-(4.0/7)+(4.0/9)
3.3396825396825403
>>> (4.0/1)-(4.0/3)+(4.0/5)-(4.0/7)+(4.0/9)-(4.0/11)
2.9760461760461765
>>> (4.0/1)-(4.0/3)+(4.0/5)-(4.0/7)+(4.0/9)-(4.0/11)+(4.0/13)
3.2837384837384844
>>> (4.0/1)-(4.0/3)+(4.0/5)-(4.0/7)+(4.0/9)-(4.0/11)+(4.0/13)-(4.0/15)
3.0170718170718178
>>> 

So using the python shell as a calculator, there are what I work out as the right answers for 5, 6, 7, & 8 iterations.  And here is the program that I worked out that seems to come up with the right answers:

#   approximate_pi.py
#   Approximates the value of 'pi' by summing the terms of a series.
#

import math

def main():
    print "This program will approximate the value of pi"
    print "to a degree determined by the user. "
    print

    #  get the value of 'n' from the user
    n = input("How many terms do you want me to sum?  ")
    print

    #  initialize variables
    x = 0
    m = 1

    #  loop thru n times, summing each pass and switching the sign
    #  on m each time, and printing x every time through.
    for i in range(n):
        x = x + m*(4.0/(i*2+1))
        m = -m
        print x

    #  assigning x to pi    
    pi = x
    
    print
    #  output the sum
    print "The sum of the numbers you entered is", pi

    #  calculate the difference between our approximation and Python's pi
    pi_diff = math.pi - pi

    #  output the difference (final portion of the problem in the book)
    print
    print "The difference between your 'pi' & Python's pi is", pi_diff, "."

main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081023/b0c03b79/attachment.htm>

From srilyk at gmail.com  Fri Oct 24 12:51:54 2008
From: srilyk at gmail.com (W W)
Date: Fri, 24 Oct 2008 05:51:54 -0500
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <562371.59459.qm@web601.biz.mail.mud.yahoo.com>
References: <562371.59459.qm@web601.biz.mail.mud.yahoo.com>
Message-ID: <333efb450810240351w1c9078efl2ea889a899ea0c31@mail.gmail.com>

On Thu, Oct 23, 2008 at 10:29 PM, Monte Milanuk <monte at milanuk.net> wrote:

> Hello again, and thanks to all of you who extended your help!
> <snip>Maybe I'm not clever enough, but I didn't see how either example
> could be used for doing the addition/subtraction determination.  Or rather,
> I found a different way after reading someone else's examples.
>
<snip>
>
#  loop thru n times, summing each pass and switching the sign
>     #  on m each time, and printing x every time through.
>     for i in range(n):
>         x = x + m*(4.0/(i*2+1))
>         m = -m
>

That's probably just as elegant as the way I would have done it; mod
division! :)

 In [50]: for x in range(1, 10):
   ....:     print "%d %% 2 = " % (x, ), x % 2
   ....:
   ....:
1 % 2 =  1
2 % 2 =  0
3 % 2 =  1
4 % 2 =  0
5 % 2 =  1
6 % 2 =  0
7 % 2 =  1
8 % 2 =  0
9 % 2 =  1

Thus, to adapt it to what you had, declare:
m = -1

And the terms of the loop:
for i in range(1, n+1):
    x = x + (m * (i % 2)) * (4.0/(i*2))

At least I'm pretty sure that's syntactically correct. It's 5:47 am and I'm
getting ready for school, so you never know for sure ;)

The great thing about using mod division is that it's /always/ applicable
when you're looking for even/odd status of a number:

In [52]: for x in xrange(-3,3):
   ....:     print "%d %% 2 = " % (x, ), x % 2
   ....:
   ....:
-3 % 2 =  1
-2 % 2 =  0
-1 % 2 =  1
0 % 2 =  0
1 % 2 =  1
2 % 2 =  0

Yay for mod division! :)

Glad my advice helped!
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081024/488b9394/attachment.htm>

From kent37 at tds.net  Fri Oct 24 13:44:01 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 24 Oct 2008 07:44:01 -0400
Subject: [Tutor] Need help w/ a for loop
In-Reply-To: <333efb450810240351w1c9078efl2ea889a899ea0c31@mail.gmail.com>
References: <562371.59459.qm@web601.biz.mail.mud.yahoo.com>
	<333efb450810240351w1c9078efl2ea889a899ea0c31@mail.gmail.com>
Message-ID: <1c2a2c590810240444q56429f11md9b4690ca08501ca@mail.gmail.com>

On Fri, Oct 24, 2008 at 6:51 AM, W W <srilyk at gmail.com> wrote:

> for i in range(1, n+1):
>     x = x + (m * (i % 2)) * (4.0/(i*2))

This will omit every other term (when i%2 ==0) and it divides by the
even numbers, not odd ones.

Kent

From aivars868 at gmail.com  Fri Oct 24 16:25:21 2008
From: aivars868 at gmail.com (aivars)
Date: Fri, 24 Oct 2008 17:25:21 +0300
Subject: [Tutor] please help with simple python CGI script
Message-ID: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>

Hello,

I am learning python.

I start the python CGI server like this:

python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
Python Programming chapter 20.5)

The server starts in command prompt on windows XP by answering:
Serving HTTP on 0.0.0.0 port 8000...

Next I want to run this simple CGI script (from Deitel Python How to
Program chapter 6). it is supposed to print out current date and time
in a browser

#!C:\python25\python.exe
import time

def printHeader(title):
    print """Content-type: text/html


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>%s</title></head>

<body>""" % title

printHeader("Current date and time")
print time.ctime(time.time())
print "</body></html>"


And The server prints the script text in the browser. It does not run
the script.
The server response is 200.
The script itself runs OK if being run from python/command line

I also could not run the script from wesley chun's book. I think also
because it seems the python cgi web server does not understand that it
should run the script and not to print it out in web browser

I am using python 2.5 on windows XP.

What I am missing?

Thanks
Aivars

From kent37 at tds.net  Fri Oct 24 16:48:55 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 24 Oct 2008 10:48:55 -0400
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
Message-ID: <1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>

On Fri, Oct 24, 2008 at 10:25 AM, aivars <aivars868 at gmail.com> wrote:
> Hello,
>
> I am learning python.
>
> I start the python CGI server like this:
>
> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
> Python Programming chapter 20.5)
>
> The server starts in command prompt on windows XP by answering:
> Serving HTTP on 0.0.0.0 port 8000...
>
> Next I want to run this simple CGI script (from Deitel Python How to
> Program chapter 6). it is supposed to print out current date and time
> in a browser

The CGI script should me in a /cgi-bin subdirectory of the dir where
you run the script. The URL to run the CGI will then be something like
http:://localhost:8000/cgi-bin/myscript.py

Kent

From dineshbvadhia at hotmail.com  Fri Oct 24 17:54:00 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Fri, 24 Oct 2008 08:54:00 -0700
Subject: [Tutor] XML to text
Message-ID: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>

I have a large number of xml files that I want to convert into text format.  What is the best and easiest way to do this?  Thanks!

Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081024/8989f05c/attachment.htm>

From aivars868 at gmail.com  Fri Oct 24 17:55:09 2008
From: aivars868 at gmail.com (aivars)
Date: Fri, 24 Oct 2008 18:55:09 +0300
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
Message-ID: <c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>

Thanks very much, Kent,

So it seems that directory /cgi-bin should be a subdirectory to that
directory from which the web server was started/is running. That
worked and Deitel's script - getting time displayed finally worked.

still banging mu head with Wesley Chun's simple example -

#!C:\python25\python.exe

import cgi

reshtml = '''Content-Type: text/html\n
<HTML><HEAD><TITLE>
Friends CGI Demo (dynamic screen)
</TITLE></HEAD>
<BODY><H3>Friends list for: <I>%s</I></H3>
Your name is: <B>%s</B><P>
You have <B>%s</B> friends.
</BODY></HTML>'''

form = cgi.FieldStorage()
who = form['person'].value
howmany = form['howmany'].value
print reshtml % (who, who, howmany)

It gives me the following error:
Traceback (most recent call last):
  File "C:\Cgi-bin\friends1.py", line 15, in <module>
    who = form['person'].value
  File "C:\Python25\lib\cgi.py", line 567, in __getitem__
    raise KeyError, key
KeyError: 'person'

I understand python is saying that there is no such a key in a directory.

The HTML form looks like this. it is displayed correctly both in FF and IE


<HTML><HEAD><TITLE>
Friends CGI Demo (static screen)
   </TITLE></HEAD>
  <BODY><H3>Friends list for: <I>NEW USER</I></H3>
   <FORM ACTION="/cgi-bin/friends1.py">
  <B>Enter your Name:</B>
  <INPUT TYPE="text" NAME="person" VALUE="NEW USER" SIZE=15>
   <P><B>How many friends do you have?</B>
   <INPUT TYPE="radio" NAME="howmany" VALUE="0" CHECKED> 0
  <INPUT TYPE=radio NAME="howmany" VALUE="10"> 10
  <INPUT TYPE="radio" NAME="howmany" VALUE="25"> 25
  <INPUT TYPE="radio" NAME="howmany" VALUE="50"> 50
  <INPUT TYPE="radio" NAME="howmany" VALUE="100"> 100
  <P><INPUT TYPE="submit"></FORM></BODY></HTML>

Thanks again,

Aivars






2008/10/24 Kent Johnson <kent37 at tds.net>:
> On Fri, Oct 24, 2008 at 10:25 AM, aivars <aivars868 at gmail.com> wrote:
>> Hello,
>>
>> I am learning python.
>>
>> I start the python CGI server like this:
>>
>> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
>> Python Programming chapter 20.5)
>>
>> The server starts in command prompt on windows XP by answering:
>> Serving HTTP on 0.0.0.0 port 8000...
>>
>> Next I want to run this simple CGI script (from Deitel Python How to
>> Program chapter 6). it is supposed to print out current date and time
>> in a browser
>
> The CGI script should me in a /cgi-bin subdirectory of the dir where
> you run the script. The URL to run the CGI will then be something like
> http:://localhost:8000/cgi-bin/myscript.py
>
> Kent
>

From walch at swipp.de  Fri Oct 24 18:19:24 2008
From: walch at swipp.de (Thomas Walch)
Date: Fri, 24 Oct 2008 18:19:24 +0200
Subject: [Tutor] XML to text
In-Reply-To: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
References: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
Message-ID: <4901F58C.10205@swipp.de>

This might be helpful:

http://www.boddie.org.uk/python/XML_intro.html

Have fun!

Thomas

Dinesh B Vadhia schrieb:
> I have a large number of xml files that I want to convert into text 
> format.  What is the best and easiest way to do this?  Thanks!
>  
> Dinesh
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

From ah_tornado at hotmail.com  Fri Oct 24 19:18:06 2008
From: ah_tornado at hotmail.com (A .K Hachem)
Date: Fri, 24 Oct 2008 10:18:06 -0700
Subject: [Tutor] Python HELP
In-Reply-To: <da8d39610810232226r6acbc088lcd1b1ce526b40d64@mail.gmail.com>
References: <BAY130-W35001239A98C1065E86C40F42B0@phx.gbl>
	<da8d39610810232226r6acbc088lcd1b1ce526b40d64@mail.gmail.com>
Message-ID: <BAY130-W5551671C93294C0D469CD4F42B0@phx.gbl>

hey there, if anyone can help me with an assignment im stuck in for a fee i will be grateful 

*******************************************
Regards.
A K. Hachem


 EMAILING FOR THE GREATER GOOD
Join me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081024/d8e7dc7c/attachment.htm>

From kent37 at tds.net  Fri Oct 24 19:59:28 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 24 Oct 2008 13:59:28 -0400
Subject: [Tutor] XML to text
In-Reply-To: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
References: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
Message-ID: <1c2a2c590810241059l1e3e6a55j8f60b0611d726ffe@mail.gmail.com>

On Fri, Oct 24, 2008 at 11:54 AM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> I have a large number of xml files that I want to convert into text format.
> What is the best and easiest way to do this?  Thanks!

If by "convert into text format" you mean, strip all the xml markup
and leave just the text, then either of these recipes should work:
http://code.activestate.com/recipes/65128/
http://code.activestate.com/recipes/498286/

Kent

From kent37 at tds.net  Fri Oct 24 20:00:28 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 24 Oct 2008 14:00:28 -0400
Subject: [Tutor] Python HELP
In-Reply-To: <BAY130-W5551671C93294C0D469CD4F42B0@phx.gbl>
References: <BAY130-W35001239A98C1065E86C40F42B0@phx.gbl>
	<da8d39610810232226r6acbc088lcd1b1ce526b40d64@mail.gmail.com>
	<BAY130-W5551671C93294C0D469CD4F42B0@phx.gbl>
Message-ID: <1c2a2c590810241100l47c970e2wc520fe1c35a5d843@mail.gmail.com>

On Fri, Oct 24, 2008 at 1:18 PM, A .K Hachem <ah_tornado at hotmail.com> wrote:
> hey there, if anyone can help me with an assignment im stuck in for a fee i
> will be grateful

We will help for free if you show us what you have done and ask
specific questions. We won't do your homework for you.

Kent

From dineshbvadhia at hotmail.com  Fri Oct 24 20:09:14 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Fri, 24 Oct 2008 11:09:14 -0700
Subject: [Tutor] XML to text
In-Reply-To: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
	<1c2a2c590810241059l1e3e6a55j8f60b0611d726ffe@mail.gmail.com>
References: <COL103-DS11A42FA805123117584D44A32B0@phx.gbl>
	<1c2a2c590810241059l1e3e6a55j8f60b0611d726ffe@mail.gmail.com>
Message-ID: <COL103-DS238B0ED377584C776047E4A32B0@phx.gbl>

Yes, that's exactly what I was looking for.  Brilliant!




From: Kent Johnson 
Sent: Friday, October 24, 2008 10:59 AM
To: Dinesh B Vadhia 
Cc: tutor at python.org 
Subject: Re: [Tutor] XML to text


On Fri, Oct 24, 2008 at 11:54 AM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> I have a large number of xml files that I want to convert into text format.
> What is the best and easiest way to do this?  Thanks!

If by "convert into text format" you mean, strip all the xml markup
and leave just the text, then either of these recipes should work:
http://code.activestate.com/recipes/65128/
http://code.activestate.com/recipes/498286/

Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081024/2e56198f/attachment.htm>

From fast_primes at hotmail.com  Sat Oct 25 13:56:53 2008
From: fast_primes at hotmail.com (Fast Primes)
Date: Sat, 25 Oct 2008 07:56:53 -0400
Subject: [Tutor] [tutor] run a program and direct it's print file to a file?
In-Reply-To: <mailman.49.1224928818.24916.tutor@python.org>
References: <mailman.49.1224928818.24916.tutor@python.org>
Message-ID: <BLU131-W1012E43DE113EBD816F913802A0@phx.gbl>


Hi,

I'm very rusty. From a linux box, I want to run a program X.py after or while setting it's list output to a file L.txt. How do I do that please?

Thanks.

FP
_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008

From kent37 at tds.net  Sat Oct 25 15:28:24 2008
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 25 Oct 2008 09:28:24 -0400
Subject: [Tutor] [tutor] run a program and direct it's print file to a
	file?
In-Reply-To: <BLU131-W1012E43DE113EBD816F913802A0@phx.gbl>
References: <mailman.49.1224928818.24916.tutor@python.org>
	<BLU131-W1012E43DE113EBD816F913802A0@phx.gbl>
Message-ID: <1c2a2c590810250628i25acc314o96e14e72d822b60f@mail.gmail.com>

On Sat, Oct 25, 2008 at 7:56 AM, Fast Primes <fast_primes at hotmail.com> wrote:
>
> Hi,
>
> I'm very rusty. From a linux box, I want to run a program X.py after or while setting it's list output to a file L.txt.

python X.py > L.txt

or if X.py is executable and has the correct shebang line
X.py > L.txt

Kent

From alan.gauld at btinternet.com  Sat Oct 25 17:47:16 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 25 Oct 2008 16:47:16 +0100
Subject: [Tutor] [tutor] run a program and direct it's print file to a
	file?
References: <mailman.49.1224928818.24916.tutor@python.org>
	<BLU131-W1012E43DE113EBD816F913802A0@phx.gbl>
Message-ID: <gdvf25$758$1@ger.gmane.org>


"Fast Primes" <fast_primes at hotmail.com> wrote in 

> I'm very rusty. From a linux box, I want to run a program X.py 
> after or while setting it's list output to a file L.txt. 
> How do I do that please?

$ python X.py > L.txt

Should do it.

HTH,


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


From aivars868 at gmail.com  Sat Oct 25 20:33:34 2008
From: aivars868 at gmail.com (aivars)
Date: Sat, 25 Oct 2008 21:33:34 +0300
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <1224958926.9667.2.camel@voruta>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
	<1224958926.9667.2.camel@voruta>
Message-ID: <c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>

It does not work neither as script or from command line. I will try to
find the guy Wesley Chun and ask him

2008/10/25 John Pomni <jpomni at googlemail.com>:
> Hi,
>
> The script does not work from command line but I guess you do not have
> any problems running it as CGI?
>
> I like cgitb modules for debugging purposes very much.
>
> http://www.python.org/doc/2.5.2/lib/node566.html
>
> Jan
>
> On Fri, 2008-10-24 at 18:55 +0300, aivars wrote:
>> Thanks very much, Kent,
>>
>> So it seems that directory /cgi-bin should be a subdirectory to that
>> directory from which the web server was started/is running. That
>> worked and Deitel's script - getting time displayed finally worked.
>>
>> still banging mu head with Wesley Chun's simple example -
>>
>> #!C:\python25\python.exe
>>
>> import cgi
>>
>> reshtml = '''Content-Type: text/html\n
>> <HTML><HEAD><TITLE>
>> Friends CGI Demo (dynamic screen)
>> </TITLE></HEAD>
>> <BODY><H3>Friends list for: <I>%s</I></H3>
>> Your name is: <B>%s</B><P>
>> You have <B>%s</B> friends.
>> </BODY></HTML>'''
>>
>> form = cgi.FieldStorage()
>> who = form['person'].value
>> howmany = form['howmany'].value
>> print reshtml % (who, who, howmany)
>>
>> It gives me the following error:
>> Traceback (most recent call last):
>>   File "C:\Cgi-bin\friends1.py", line 15, in <module>
>>     who = form['person'].value
>>   File "C:\Python25\lib\cgi.py", line 567, in __getitem__
>>     raise KeyError, key
>> KeyError: 'person'
>>
>> I understand python is saying that there is no such a key in a directory.
>>
>> The HTML form looks like this. it is displayed correctly both in FF and IE
>>
>>
>> <HTML><HEAD><TITLE>
>> Friends CGI Demo (static screen)
>>    </TITLE></HEAD>
>>   <BODY><H3>Friends list for: <I>NEW USER</I></H3>
>>    <FORM ACTION="/cgi-bin/friends1.py">
>>   <B>Enter your Name:</B>
>>   <INPUT TYPE="text" NAME="person" VALUE="NEW USER" SIZE=15>
>>    <P><B>How many friends do you have?</B>
>>    <INPUT TYPE="radio" NAME="howmany" VALUE="0" CHECKED> 0
>>   <INPUT TYPE=radio NAME="howmany" VALUE="10"> 10
>>   <INPUT TYPE="radio" NAME="howmany" VALUE="25"> 25
>>   <INPUT TYPE="radio" NAME="howmany" VALUE="50"> 50
>>   <INPUT TYPE="radio" NAME="howmany" VALUE="100"> 100
>>   <P><INPUT TYPE="submit"></FORM></BODY></HTML>
>>
>> Thanks again,
>>
>> Aivars
>>
>>
>>
>>
>>
>>
>> 2008/10/24 Kent Johnson <kent37 at tds.net>:
>> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <aivars868 at gmail.com> wrote:
>> >> Hello,
>> >>
>> >> I am learning python.
>> >>
>> >> I start the python CGI server like this:
>> >>
>> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
>> >> Python Programming chapter 20.5)
>> >>
>> >> The server starts in command prompt on windows XP by answering:
>> >> Serving HTTP on 0.0.0.0 port 8000...
>> >>
>> >> Next I want to run this simple CGI script (from Deitel Python How to
>> >> Program chapter 6). it is supposed to print out current date and time
>> >> in a browser
>> >
>> > The CGI script should me in a /cgi-bin subdirectory of the dir where
>> > you run the script. The URL to run the CGI will then be something like
>> > http:://localhost:8000/cgi-bin/myscript.py
>> >
>> > Kent
>> >
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>

From lie.1296 at gmail.com  Sat Oct 25 22:58:04 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Sat, 25 Oct 2008 20:58:04 +0000 (UTC)
Subject: [Tutor] [tutor] run a program and direct it's print file to a
	file?
References: <mailman.49.1224928818.24916.tutor@python.org>
	<BLU131-W1012E43DE113EBD816F913802A0@phx.gbl>
Message-ID: <ge018s$14p$3@ger.gmane.org>

On Sat, 25 Oct 2008 07:56:53 -0400, Fast Primes wrote:

> Hi,
> 
> I'm very rusty. From a linux box, I want to run a program X.py after or
> while setting it's list output to a file L.txt. How do I do that please?

I think this is a linux question more than python question. In Linux, 
it's easy to do stdin-stdout-stderr redirection.

python script.py > output.txt

If you're trying to redirect the output programmatically from inside the 
python program, instead of using the shell service for I/O redirection, 
do something like this:

import sys
sys.stdout = open('output.txt', 'w')


From alan.gauld at btinternet.com  Sun Oct 26 01:51:49 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 26 Oct 2008 00:51:49 +0100
Subject: [Tutor] please help with simple python CGI script
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com><1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
Message-ID: <ge0bem$naj$1@ger.gmane.org>


"aivars" <aivars868 at gmail.com> wrote 


> still banging mu head with Wesley Chun's simple example -

I'm not sure if this is significant but....

> It gives me the following error:
> Traceback (most recent call last):
>  File "C:\Cgi-bin\friends1.py", line 15, in <module>

Notice that the file path has Cgi not cgi
Case may be significant...

>   <FORM ACTION="/cgi-bin/friends1.py">

The action expects cgi

Just a thought.


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


From aivars868 at gmail.com  Sun Oct 26 07:53:52 2008
From: aivars868 at gmail.com (aivars)
Date: Sun, 26 Oct 2008 08:53:52 +0200
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <1224968487.16963.4.camel@voruta>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
	<1224958926.9667.2.camel@voruta>
	<c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>
	<1224968487.16963.4.camel@voruta>
Message-ID: <c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>

Thanks John and Alan

I get the following error when I run the script from IDLE:

Traceback (most recent call last):
  File "C:\Cgi-bin\friends1.py", line 15, in <module>
    who = form['person'].value
  File "C:\Python25\lib\cgi.py", line 567, in __getitem__
    raise KeyError, key
KeyError: 'person'


Aivars
Windows XP, python 2.5

2008/10/26 John Pomni <jpomni at googlemail.com>:
> what error do you get? It works without any changes on my Linux machine
> with python 2.5
>
> John
>
> On Sat, 2008-10-25 at 21:33 +0300, aivars wrote:
>> It does not work neither as script or from command line. I will try to
>> find the guy Wesley Chun and ask him
>>
>> 2008/10/25 John Pomni <jpomni at googlemail.com>:
>> > Hi,
>> >
>> > The script does not work from command line but I guess you do not have
>> > any problems running it as CGI?
>> >
>> > I like cgitb modules for debugging purposes very much.
>> >
>> > http://www.python.org/doc/2.5.2/lib/node566.html
>> >
>> > Jan
>> >
>> > On Fri, 2008-10-24 at 18:55 +0300, aivars wrote:
>> >> Thanks very much, Kent,
>> >>
>> >> So it seems that directory /cgi-bin should be a subdirectory to that
>> >> directory from which the web server was started/is running. That
>> >> worked and Deitel's script - getting time displayed finally worked.
>> >>
>> >> still banging mu head with Wesley Chun's simple example -
>> >>
>> >> #!C:\python25\python.exe
>> >>
>> >> import cgi
>> >>
>> >> reshtml = '''Content-Type: text/html\n
>> >> <HTML><HEAD><TITLE>
>> >> Friends CGI Demo (dynamic screen)
>> >> </TITLE></HEAD>
>> >> <BODY><H3>Friends list for: <I>%s</I></H3>
>> >> Your name is: <B>%s</B><P>
>> >> You have <B>%s</B> friends.
>> >> </BODY></HTML>'''
>> >>
>> >> form = cgi.FieldStorage()
>> >> who = form['person'].value
>> >> howmany = form['howmany'].value
>> >> print reshtml % (who, who, howmany)
>> >>
>> >> It gives me the following error:
>> >> Traceback (most recent call last):
>> >>   File "C:\Cgi-bin\friends1.py", line 15, in <module>
>> >>     who = form['person'].value
>> >>   File "C:\Python25\lib\cgi.py", line 567, in __getitem__
>> >>     raise KeyError, key
>> >> KeyError: 'person'
>> >>
>> >> I understand python is saying that there is no such a key in a directory.
>> >>
>> >> The HTML form looks like this. it is displayed correctly both in FF and IE
>> >>
>> >>
>> >> <HTML><HEAD><TITLE>
>> >> Friends CGI Demo (static screen)
>> >>    </TITLE></HEAD>
>> >>   <BODY><H3>Friends list for: <I>NEW USER</I></H3>
>> >>    <FORM ACTION="/cgi-bin/friends1.py">
>> >>   <B>Enter your Name:</B>
>> >>   <INPUT TYPE="text" NAME="person" VALUE="NEW USER" SIZE=15>
>> >>    <P><B>How many friends do you have?</B>
>> >>    <INPUT TYPE="radio" NAME="howmany" VALUE="0" CHECKED> 0
>> >>   <INPUT TYPE=radio NAME="howmany" VALUE="10"> 10
>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="25"> 25
>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="50"> 50
>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="100"> 100
>> >>   <P><INPUT TYPE="submit"></FORM></BODY></HTML>
>> >>
>> >> Thanks again,
>> >>
>> >> Aivars
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> 2008/10/24 Kent Johnson <kent37 at tds.net>:
>> >> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <aivars868 at gmail.com> wrote:
>> >> >> Hello,
>> >> >>
>> >> >> I am learning python.
>> >> >>
>> >> >> I start the python CGI server like this:
>> >> >>
>> >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
>> >> >> Python Programming chapter 20.5)
>> >> >>
>> >> >> The server starts in command prompt on windows XP by answering:
>> >> >> Serving HTTP on 0.0.0.0 port 8000...
>> >> >>
>> >> >> Next I want to run this simple CGI script (from Deitel Python How to
>> >> >> Program chapter 6). it is supposed to print out current date and time
>> >> >> in a browser
>> >> >
>> >> > The CGI script should me in a /cgi-bin subdirectory of the dir where
>> >> > you run the script. The URL to run the CGI will then be something like
>> >> > http:://localhost:8000/cgi-bin/myscript.py
>> >> >
>> >> > Kent
>> >> >
>> >> _______________________________________________
>> >> Tutor maillist  -  Tutor at python.org
>> >> http://mail.python.org/mailman/listinfo/tutor
>> >
>> >
>
>

From aivars868 at gmail.com  Sun Oct 26 08:45:23 2008
From: aivars868 at gmail.com (aivars)
Date: Sun, 26 Oct 2008 09:45:23 +0200
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
	<1224958926.9667.2.camel@voruta>
	<c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>
	<1224968487.16963.4.camel@voruta>
	<c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>
Message-ID: <c5ad28970810260045r61e5bbe4h1bbb3dffbe598619@mail.gmail.com>

I finally get the script working!

I renamed the script directory from Cgi-bin to cgi-bin just as Alan told.

Many thanks to all you who responded

Aivars


2008/10/26 aivars <aivars868 at gmail.com>:
> Thanks John and Alan
>
> I get the following error when I run the script from IDLE:
>
> Traceback (most recent call last):
>  File "C:\Cgi-bin\friends1.py", line 15, in <module>
>    who = form['person'].value
>  File "C:\Python25\lib\cgi.py", line 567, in __getitem__
>    raise KeyError, key
> KeyError: 'person'
>
>
> Aivars
> Windows XP, python 2.5
>
> 2008/10/26 John Pomni <jpomni at googlemail.com>:
>> what error do you get? It works without any changes on my Linux machine
>> with python 2.5
>>
>> John
>>
>> On Sat, 2008-10-25 at 21:33 +0300, aivars wrote:
>>> It does not work neither as script or from command line. I will try to
>>> find the guy Wesley Chun and ask him
>>>
>>> 2008/10/25 John Pomni <jpomni at googlemail.com>:
>>> > Hi,
>>> >
>>> > The script does not work from command line but I guess you do not have
>>> > any problems running it as CGI?
>>> >
>>> > I like cgitb modules for debugging purposes very much.
>>> >
>>> > http://www.python.org/doc/2.5.2/lib/node566.html
>>> >
>>> > Jan
>>> >
>>> > On Fri, 2008-10-24 at 18:55 +0300, aivars wrote:
>>> >> Thanks very much, Kent,
>>> >>
>>> >> So it seems that directory /cgi-bin should be a subdirectory to that
>>> >> directory from which the web server was started/is running. That
>>> >> worked and Deitel's script - getting time displayed finally worked.
>>> >>
>>> >> still banging mu head with Wesley Chun's simple example -
>>> >>
>>> >> #!C:\python25\python.exe
>>> >>
>>> >> import cgi
>>> >>
>>> >> reshtml = '''Content-Type: text/html\n
>>> >> <HTML><HEAD><TITLE>
>>> >> Friends CGI Demo (dynamic screen)
>>> >> </TITLE></HEAD>
>>> >> <BODY><H3>Friends list for: <I>%s</I></H3>
>>> >> Your name is: <B>%s</B><P>
>>> >> You have <B>%s</B> friends.
>>> >> </BODY></HTML>'''
>>> >>
>>> >> form = cgi.FieldStorage()
>>> >> who = form['person'].value
>>> >> howmany = form['howmany'].value
>>> >> print reshtml % (who, who, howmany)
>>> >>
>>> >> It gives me the following error:
>>> >> Traceback (most recent call last):
>>> >>   File "C:\Cgi-bin\friends1.py", line 15, in <module>
>>> >>     who = form['person'].value
>>> >>   File "C:\Python25\lib\cgi.py", line 567, in __getitem__
>>> >>     raise KeyError, key
>>> >> KeyError: 'person'
>>> >>
>>> >> I understand python is saying that there is no such a key in a directory.
>>> >>
>>> >> The HTML form looks like this. it is displayed correctly both in FF and IE
>>> >>
>>> >>
>>> >> <HTML><HEAD><TITLE>
>>> >> Friends CGI Demo (static screen)
>>> >>    </TITLE></HEAD>
>>> >>   <BODY><H3>Friends list for: <I>NEW USER</I></H3>
>>> >>    <FORM ACTION="/cgi-bin/friends1.py">
>>> >>   <B>Enter your Name:</B>
>>> >>   <INPUT TYPE="text" NAME="person" VALUE="NEW USER" SIZE=15>
>>> >>    <P><B>How many friends do you have?</B>
>>> >>    <INPUT TYPE="radio" NAME="howmany" VALUE="0" CHECKED> 0
>>> >>   <INPUT TYPE=radio NAME="howmany" VALUE="10"> 10
>>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="25"> 25
>>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="50"> 50
>>> >>   <INPUT TYPE="radio" NAME="howmany" VALUE="100"> 100
>>> >>   <P><INPUT TYPE="submit"></FORM></BODY></HTML>
>>> >>
>>> >> Thanks again,
>>> >>
>>> >> Aivars
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> 2008/10/24 Kent Johnson <kent37 at tds.net>:
>>> >> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <aivars868 at gmail.com> wrote:
>>> >> >> Hello,
>>> >> >>
>>> >> >> I am learning python.
>>> >> >>
>>> >> >> I start the python CGI server like this:
>>> >> >>
>>> >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
>>> >> >> Python Programming chapter 20.5)
>>> >> >>
>>> >> >> The server starts in command prompt on windows XP by answering:
>>> >> >> Serving HTTP on 0.0.0.0 port 8000...
>>> >> >>
>>> >> >> Next I want to run this simple CGI script (from Deitel Python How to
>>> >> >> Program chapter 6). it is supposed to print out current date and time
>>> >> >> in a browser
>>> >> >
>>> >> > The CGI script should me in a /cgi-bin subdirectory of the dir where
>>> >> > you run the script. The URL to run the CGI will then be something like
>>> >> > http:://localhost:8000/cgi-bin/myscript.py
>>> >> >
>>> >> > Kent
>>> >> >
>>> >> _______________________________________________
>>> >> Tutor maillist  -  Tutor at python.org
>>> >> http://mail.python.org/mailman/listinfo/tutor
>>> >
>>> >
>>
>>
>

From alan.gauld at btinternet.com  Sun Oct 26 09:32:52 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 26 Oct 2008 08:32:52 -0000
Subject: [Tutor] please help with simple python CGI script
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com><1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com><c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com><1224958926.9667.2.camel@voruta><c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com><1224968487.16963.4.camel@voruta><c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>
	<c5ad28970810260045r61e5bbe4h1bbb3dffbe598619@mail.gmail.com>
Message-ID: <ge19vm$gsi$1@ger.gmane.org>


"aivars" <aivars868 at gmail.com> wrote in message 
news:c5ad28970810260045r61e5bbe4h1bbb3dffbe598619 at mail.gmail.com...
>I finally get the script working!
>
> I renamed the script directory from Cgi-bin to cgi-bin just as Alan 
> told.

I'm glad it worked but I confess I'm not sure why it worked.
The interpreter was apparently finding your script OK but it
was the environment that was messed up. I don't fully
understand the interaction going on  there. But in things
web related I've learned that consistency throughout is
usually helpul!

Alan G.




From lie.1296 at gmail.com  Sun Oct 26 13:35:44 2008
From: lie.1296 at gmail.com (Lie Ryan)
Date: Sun, 26 Oct 2008 12:35:44 +0000 (UTC)
Subject: [Tutor] please help with simple python CGI script
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
	<1224958926.9667.2.camel@voruta>
	<c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>
	<1224968487.16963.4.camel@voruta>
	<c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>
	<c5ad28970810260045r61e5bbe4h1bbb3dffbe598619@mail.gmail.com>
	<ge19vm$gsi$1@ger.gmane.org>
Message-ID: <ge1o70$2qk$5@ger.gmane.org>

On Sun, 26 Oct 2008 08:32:52 +0000, Alan Gauld wrote:

> "aivars" <aivars868 at gmail.com> wrote in message
> news:c5ad28970810260045r61e5bbe4h1bbb3dffbe598619 at mail.gmail.com...
>>I finally get the script working!
>>
>> I renamed the script directory from Cgi-bin to cgi-bin just as Alan
>> told.
> 
> I'm glad it worked but I confess I'm not sure why it worked. The
> interpreter was apparently finding your script OK but it was the
> environment that was messed up. I don't fully understand the interaction
> going on  there. But in things web related I've learned that consistency
> throughout is usually helpul!
> 
> Alan G.
> 

I wouldn't have thought it could work, since Windows is case insensitive 
and web server is required understand URL as case insensitive. Why that 
Cgi-bin and cgi-bin differs on a windows-based server is beyond me.


From aivars868 at gmail.com  Sun Oct 26 13:58:10 2008
From: aivars868 at gmail.com (aivars)
Date: Sun, 26 Oct 2008 14:58:10 +0200
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <ge1o70$2qk$5@ger.gmane.org>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>
	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>
	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>
	<1224958926.9667.2.camel@voruta>
	<c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>
	<1224968487.16963.4.camel@voruta>
	<c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>
	<c5ad28970810260045r61e5bbe4h1bbb3dffbe598619@mail.gmail.com>
	<ge19vm$gsi$1@ger.gmane.org> <ge1o70$2qk$5@ger.gmane.org>
Message-ID: <c5ad28970810260558n2b53d7bas983d0c6f811963ff@mail.gmail.com>

Hello, Lie,
I renamed the directory back to Cgi-bin and the scripts are NOT
working. Going back to cgi-bin it works. I also do not understand why.

Aivars

2008/10/26 Lie Ryan <lie.1296 at gmail.com>:
> On Sun, 26 Oct 2008 08:32:52 +0000, Alan Gauld wrote:
>
>> "aivars" <aivars868 at gmail.com> wrote in message
>> news:c5ad28970810260045r61e5bbe4h1bbb3dffbe598619 at mail.gmail.com...
>>>I finally get the script working!
>>>
>>> I renamed the script directory from Cgi-bin to cgi-bin just as Alan
>>> told.
>>
>> I'm glad it worked but I confess I'm not sure why it worked. The
>> interpreter was apparently finding your script OK but it was the
>> environment that was messed up. I don't fully understand the interaction
>> going on  there. But in things web related I've learned that consistency
>> throughout is usually helpul!
>>
>> Alan G.
>>
>
> I wouldn't have thought it could work, since Windows is case insensitive
> and web server is required understand URL as case insensitive. Why that
> Cgi-bin and cgi-bin differs on a windows-based server is beyond me.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From steve at alchemy.com  Sun Oct 26 19:06:11 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Sun, 26 Oct 2008 12:06:11 -0600
Subject: [Tutor] please help with simple python CGI script
In-Reply-To: <c5ad28970810260558n2b53d7bas983d0c6f811963ff@mail.gmail.com>
References: <c5ad28970810240725k2ff9dd23q1894d651ffda569@mail.gmail.com>	<1c2a2c590810240748g47342653sfffc15b6f1dc342f@mail.gmail.com>	<c5ad28970810240855o2605fda6m87f57001620eb69d@mail.gmail.com>	<1224958926.9667.2.camel@voruta>	<c5ad28970810251133h5b1988ecm1918f211553498cc@mail.gmail.com>	<1224968487.16963.4.camel@voruta>	<c5ad28970810252353n17934bc5s9886ce2d832ad27@mail.gmail.com>	<c5ad28970810260045r61e5bbe4h1bbb3dffbe598619@mail.gmail.com>	<ge19vm$gsi$1@ger.gmane.org>
	<ge1o70$2qk$5@ger.gmane.org>
	<c5ad28970810260558n2b53d7bas983d0c6f811963ff@mail.gmail.com>
Message-ID: <4904B193.4080903@alchemy.com>

aivars wrote:
> Hello, Lie,
> I renamed the directory back to Cgi-bin and the scripts are NOT
> working. Going back to cgi-bin it works. I also do not understand why.
> 
> Aivars
> 
> 2008/10/26 Lie Ryan <lie.1296 at gmail.com>:
>> On Sun, 26 Oct 2008 08:32:52 +0000, Alan Gauld wrote:
>>
>>> "aivars" <aivars868 at gmail.com> wrote in message
>>> news:c5ad28970810260045r61e5bbe4h1bbb3dffbe598619 at mail.gmail.com...
>>>> I finally get the script working!
>>>>
>>>> I renamed the script directory from Cgi-bin to cgi-bin just as Alan
>>>> told.
>>> I'm glad it worked but I confess I'm not sure why it worked. The
>>> interpreter was apparently finding your script OK but it was the
>>> environment that was messed up. I don't fully understand the interaction
>>> going on  there. But in things web related I've learned that consistency
>>> throughout is usually helpul!
>>>
>>> Alan G.
>>>
>> I wouldn't have thought it could work, since Windows is case insensitive
>> and web server is required understand URL as case insensitive. Why that
>> Cgi-bin and cgi-bin differs on a windows-based server is beyond me.

Why do you think web servers are required to understand URLs as case
insensitive?  This is not the case (other than the domain name itself).



From mikem at blazenetme.net  Mon Oct 27 03:37:42 2008
From: mikem at blazenetme.net (Mike Meisner)
Date: Sun, 26 Oct 2008 22:37:42 -0400
Subject: [Tutor] Immediately committing changes to shelve files
Message-ID: <969CB96AEF0648E093881A4913DE6E17@MikePC>

I'm running a number of test cases and saving their results in a shelve file.

A full run of the test cases takes about 36 hours.  During that time, if something interrupts the run (e.g., a power outage, which has happened), I find that none of the completed test cases have been committed to the shelve file even though, after each run, I make sure that the results are written to the in-memory database (i.e., db = shelve.open(filename) at the beginning of the test run; and db[key] = results after each test case).

Is there a way to force the results for a single test case to be written back to the shelve file?  Other than opening/closing the shelve after each test case run?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081026/96cfccb8/attachment.htm>

From mikem at blazenetme.net  Mon Oct 27 03:20:49 2008
From: mikem at blazenetme.net (Mike Meisner)
Date: Sun, 26 Oct 2008 22:20:49 -0400
Subject: [Tutor] Scaling a Tkinter canvas widget
Message-ID: <60CEA88037894889A3FD3F7C23BEE134@MikePC>

I would like to plot various datasets on a Tkinter canvas widget.

The problem is that each of my datasets have different x,y extremes.  For instance, one dataset may have xmin = 0, xmax = 300, ymin = 0, ymax = 300;  whereas the next dataset may have xmin = -200, xmax = 1200, ymin = 2000, ymax = 5000.  I need the whole canvas area to be available for plotting each dataset consecutively - i.e., plot one dataset, capture the image, clear the canvas and plot the next dataset with a new scale, etc.

As best I can tell the Tkinter canvas widget uses two coordinate systems:  1) the canvas coordinate system in pixels that runs from (0, 0) to (xmaxpixel, ymaxpixel), and 2) a window coordinate system that allows a wider range to enable scrolling the canvas within the window coordinate system.

What I'd like to do is simply scale the canvas coordinate system to fit the x,y extents of a dataset.  I can write a function to do this but it would be costly time-wise for plotting a large dataset (to say nothing of multiple large datasets).

My documentation for Tkinter is pretty sketchy.  I was hoping there was a canvas method I could use to re-scale the canvas widget before I plot each dataset, but there's nothing apparent in my documentation.

Is there someone familiar with Tkinter that would know how to re-scale a canvas?  Or, could tell me that there is no efficient way to do this other than writing a function to re-scale for each data point?

I'm sure that there are Python add-ins that would do what I want, but this is a quick one-time project and it's not worth the time to muck around with them compared to writing a scaling function.

Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081026/fa29196e/attachment.htm>

From kent37 at tds.net  Mon Oct 27 12:11:46 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 27 Oct 2008 07:11:46 -0400
Subject: [Tutor] Scaling a Tkinter canvas widget
In-Reply-To: <60CEA88037894889A3FD3F7C23BEE134@MikePC>
References: <60CEA88037894889A3FD3F7C23BEE134@MikePC>
Message-ID: <1c2a2c590810270411v1b433e7en79b2061aa5aa78d@mail.gmail.com>

On Sun, Oct 26, 2008 at 10:20 PM, Mike Meisner <mikem at blazenetme.net> wrote:
> I would like to plot various datasets on a Tkinter canvas widget.
>
> The problem is that each of my datasets have different x,y extremes.  For
> instance, one dataset may have xmin = 0, xmax = 300, ymin = 0, ymax = 300;
> whereas the next dataset may have xmin = -200, xmax = 1200, ymin = 2000,
> ymax = 5000.  I need the whole canvas area to be available for plotting each
> dataset consecutively - i.e., plot one dataset, capture the image, clear the
> canvas and plot the next dataset with a new scale, etc.
>
> What I'd like to do is simply scale the canvas coordinate system to fit the
> x,y extents of a dataset.  I can write a function to do this but it would be
> costly time-wise for plotting a large dataset (to say nothing of multiple
> large datasets).

I don't know if there is a Tkinter function for this but it will have
to do the scaling itself; ultimately the points have to be converted
to window coordinates to be drawn.

You might want to look at matplotlib, it is pretty simple to make line
and scatter plots with it.

Kent

From kent37 at tds.net  Mon Oct 27 12:18:16 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 27 Oct 2008 07:18:16 -0400
Subject: [Tutor] Immediately committing changes to shelve files
In-Reply-To: <969CB96AEF0648E093881A4913DE6E17@MikePC>
References: <969CB96AEF0648E093881A4913DE6E17@MikePC>
Message-ID: <1c2a2c590810270418y43641e1aw8f026d5e6d6c8556@mail.gmail.com>

On Sun, Oct 26, 2008 at 10:37 PM, Mike Meisner <mikem at blazenetme.net> wrote:
> I'm running a number of test cases and saving their results in a shelve
> file.
>
> A full run of the test cases takes about 36 hours.  During that time, if
> something interrupts the run (e.g., a power outage, which has happened), I
> find that none of the completed test cases have been committed to the shelve
> file even though, after each run, I make sure that the results are written
> to the in-memory database (i.e., db = shelve.open(filename) at the beginning
> of the test run; and db[key] = results after each test case).
>
> Is there a way to force the results for a single test case to be written
> back to the shelve file?  Other than opening/closing the shelve after each
> test case run?

I think the sync() method might do this, depending on which
implementation of dbm your shelf is using.

Kent

From python at kapitalisten.no  Mon Oct 27 21:03:19 2008
From: python at kapitalisten.no (=?iso-8859-1?Q?=D8yvind?=)
Date: Mon, 27 Oct 2008 21:03:19 +0100 (CET)
Subject: [Tutor] Read same instance twice
Message-ID: <1755.193.217.96.49.1225137799.squirrel@mail.sporck.net>

Hello.

I am trying to gather some information from a webpage:

side = urlopen("http://www.website.no")
rawstr = r"""spy.target="_top">(.*?)$"""
rawstr2 = r"""spy.target2="_top">(.*?)$"""

compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
| re.UNICODE)
compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
re.VERBOSE | re.UNICODE)

liste = self.compile_obj.findall(side.read())

liste = self.compile_obj2.findall(side.read())

It works like a dream getting the first info, but the second doesn't work.
The instance is empty.

I have tried
side2 = side
side2 = side[:]
side2 = deepcopy(side)
side2 = copy(side)
and even side2 = cStringIO.StringIO(side)

But nothing works.

How can I easiest pick up more information from the site without opening
it more than once?

Thanks


-- 
This email has been scanned for viruses & spam by Domenebutikken - www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - www.domenebutikken.no


From bcl at brianlane.com  Mon Oct 27 22:17:08 2008
From: bcl at brianlane.com (Brian C. Lane)
Date: Mon, 27 Oct 2008 14:17:08 -0700
Subject: [Tutor] Read same instance twice
In-Reply-To: <1755.193.217.96.49.1225137799.squirrel@mail.sporck.net>
References: <1755.193.217.96.49.1225137799.squirrel@mail.sporck.net>
Message-ID: <49062FD4.8040805@brianlane.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

?yvind wrote:
> Hello.
> 
> I am trying to gather some information from a webpage:
> 
> side = urlopen("http://www.website.no")
> rawstr = r"""spy.target="_top">(.*?)$"""
> rawstr2 = r"""spy.target2="_top">(.*?)$"""
> 
> compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
> | re.UNICODE)
> compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
> re.VERBOSE | re.UNICODE)
> 
> liste = self.compile_obj.findall(side.read())
> 
> liste = self.compile_obj2.findall(side.read())
> 
> It works like a dream getting the first info, but the second doesn't work.
> The instance is empty.
> 

That's because you read all of it and passed it to the first regex.

Change to:

side = urlopen("http://www.website.no").read()

then:

liste = compile_obj.findall(side)
liste = compile_obj2.findall(side)

That reads the site's contents once, then you can do whatever you want
with it in your program. I'm not sure why you had the self. reference to
compile_obj, so mix to fit your circumstances :)

Brian

- --
- ---[Office 68.6F]--[Outside 54.2F]--[Server 100.6F]--[Coaster 69.6F]---
- ---[       LADY MARY (367013060) @ 47 36.3071 -122 23.1817        ]---
Software, Linux, Microcontrollers             http://www.brianlane.com
AIS Parser SDK                                http://www.aisparser.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFJBi/UIftj/pcSws0RAjtiAJ45Sp++yj8jUhir6lwehLqRzBJswwCfREh7
J83jy1sN1xf8Gi+dWZs9GNM=
=8YQT
-----END PGP SIGNATURE-----

From kent37 at tds.net  Mon Oct 27 22:36:49 2008
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 27 Oct 2008 17:36:49 -0400
Subject: [Tutor] Read same instance twice
In-Reply-To: <1755.193.217.96.49.1225137799.squirrel@mail.sporck.net>
References: <1755.193.217.96.49.1225137799.squirrel@mail.sporck.net>
Message-ID: <1c2a2c590810271436i71524da3obfecff87999ce07a@mail.gmail.com>

On Mon, Oct 27, 2008 at 4:03 PM, ?yvind <python at kapitalisten.no> wrote:
> Hello.
>
> I am trying to gather some information from a webpage:
>
> side = urlopen("http://www.website.no")
> rawstr = r"""spy.target="_top">(.*?)$"""
> rawstr2 = r"""spy.target2="_top">(.*?)$"""
>
> compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
> | re.UNICODE)
> compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
> re.VERBOSE | re.UNICODE)
>
> liste = self.compile_obj.findall(side.read())
>
> liste = self.compile_obj2.findall(side.read())
>
> It works like a dream getting the first info, but the second doesn't work.
> The instance is empty.

> How can I easiest pick up more information from the site without opening
> it more than once?

Just remember the data. It's like reading a file, you can't read the
same file twice without re-opening, but you can remember the (string)
data from the file and use it however you want to:
data = side.read()
liste = self.compile_obj.findall(data)
liste2 = self.compile_obj2.findall(data)

Kent

From o.lenstra at gmail.com  Tue Oct 28 11:11:50 2008
From: o.lenstra at gmail.com (Olrik Lenstra)
Date: Tue, 28 Oct 2008 11:11:50 +0100
Subject: [Tutor] Tkinter / WxPython Question.
Message-ID: <3c8f6fd70810280311j6ce9ee49l6d1ba48b6de7686a@mail.gmail.com>

Dear Mailing list,

a while ago a few of you helped me solve an issue I had with a GUI / scan
program that I made.
The problem was that when I tried to move the frame it would hang until the
scan was finished.
To solve this I had to add "wx.SafeYield(self, True)" to the scan and the
GUI wouldn't hang any more.
Now I have redone the program and have written it with Tkinter instead of
WxPython.

So is there a similar command for Tkinter as there is for WxPython?

Thanks in advance.
Regards,
Olrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081028/b9ed569c/attachment.htm>

From flagel at iastate.edu  Tue Oct 28 04:40:45 2008
From: flagel at iastate.edu (Lex Flagel)
Date: Mon, 27 Oct 2008 22:40:45 -0500
Subject: [Tutor] pickling and unpickling custom classes
Message-ID: <289671bc0810272040j51092af1t282c15ed57d82cad@mail.gmail.com>

I'm using a simple class called Hash, which I picked up from the following site:
http://mail.python.org/pipermail/python-list/2007-August/453716.html

I like using this Hash object for its convenience, but it won't
unpickle.  Is there fix to the code example below (either the pickler
or the Hash object) that will get it to unpickle (pickle.loads)?  From
reading the documentation it seems that classes defined at the top
level of a module can be pickled, but I'm stymied here.  Thanks a
bunch!
Lex

Example:

###begin###
#define Hash
from collections import defaultdict
class Hash(defaultdict):
    def __init__(self):
        defaultdict.__init__(self, Hash)

#build a Hash object
a = Hash()
a[3][4][5] = 6
a['x']['y'] = 'nil'

#now test try to pickle
import pickle
pk = pickle.dumps(a)  #OK
new_a = pickle.loads(pk) #dies!
###end###

The pk object won't load, giving this error on my machine:
>>> new_a = pickle.loads(pk) #dies!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python25\lib\pickle.py", line 1374, in loads
    return Unpickler(file).load()
  File "C:\Python25\lib\pickle.py", line 858, in load
    dispatch[key](self)
  File "C:\Python25\lib\pickle.py", line 1133, in load_reduce
    value = func(*args)
TypeError: __init__() takes exactly 1 argument (2 given)

From kent37 at tds.net  Tue Oct 28 12:29:06 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 28 Oct 2008 07:29:06 -0400
Subject: [Tutor] pickling and unpickling custom classes
In-Reply-To: <289671bc0810272040j51092af1t282c15ed57d82cad@mail.gmail.com>
References: <289671bc0810272040j51092af1t282c15ed57d82cad@mail.gmail.com>
Message-ID: <1c2a2c590810280429y4fd2f804wf9b4998f1fd9fb80@mail.gmail.com>

On Mon, Oct 27, 2008 at 11:40 PM, Lex Flagel <flagel at iastate.edu> wrote:
> I'm using a simple class called Hash, which I picked up from the following site:
> http://mail.python.org/pipermail/python-list/2007-August/453716.html
>
> I like using this Hash object for its convenience, but it won't
> unpickle.  Is there fix to the code example below (either the pickler
> or the Hash object) that will get it to unpickle (pickle.loads)?

You have to override Hash.__reduce__(), the values returned by
defaultdict.__reduce__() are not correct.
http://docs.python.org/library/pickle.html#pickling-and-unpickling-extension-types

This works. The result of calling __reduce__() is a tuple, hence the
awkward code to build a new value:
class Hash(defaultdict):
   def __init__(self):
       defaultdict.__init__(self, Hash)
   def __reduce__(self):
      r = defaultdict.__reduce__(self)
      # override __init__ args
      return (r[0], (), r[2], r[3], r[4])

Kent

From tk at eutechnyx.com  Tue Oct 28 12:27:17 2008
From: tk at eutechnyx.com (Tim Kelsey)
Date: Tue, 28 Oct 2008 11:27:17 -0000
Subject: [Tutor] Multi-threading IO and the GIL
Message-ID: <002201c938f0$22911610$07010a0a@eutechnyx.com>

eutechnyx 
Hello All, 

Im not sure if this is the correct list to post this sort of thing but I have a question about python threading and the GIL. I have a multi-threaded application that is hitting a MySQL database for some info from within the various threads. When increase the size of my thread pool I see little or no improvement in the application performance but the CPU usage is not maxed. This suggests to me that the app is IO bound on the database, surly more threads should help in this case. 



Is it possible that the GIL is not being release by a thread during the time its blocking on the DB connection? Im using MySQLdb module and the application is purely written in python.



Thanks for any information,



Tim Kelsey



This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. No communication sent by e-mail to or from Eutechnyx is intended to give rise to contractual or other legal liability, apart from liability which cannot be excluded under English law. 

This email has been scanned for all known viruses by the Email Protection Agency.


www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081028/ea533cc5/attachment.htm>

From kent37 at tds.net  Tue Oct 28 13:45:26 2008
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 28 Oct 2008 08:45:26 -0400
Subject: [Tutor] Multi-threading IO and the GIL
In-Reply-To: <002201c938f0$22911610$07010a0a@eutechnyx.com>
References: <002201c938f0$22911610$07010a0a@eutechnyx.com>
Message-ID: <1c2a2c590810280545n57222374vec143406b8651371@mail.gmail.com>

On Tue, Oct 28, 2008 at 7:27 AM, Tim Kelsey <tk at eutechnyx.com> wrote:

> Im not sure if this is the correct list to post this sort of thing

We'll try to answer pretty much any Python question.

> but I
> have a question about python threading and the GIL. I have a multi-threaded
> application that is hitting a MySQL database for some info from within the
> various threads. When increase the size of my thread pool I see little or no
> improvement in the application performance but the CPU usage is not maxed.
> This suggests to me that the app is IO bound on the database, surly more
> threads should help in this case.

I can think of a few other possibilities...

Does the app actually create more threads? If you only create two
threads, the size of the thread pool doesn't much matter.

It's possible that all the threads are blocking on the database, for
example if they are all trying to modify the same row. Or the app
could truly be I/O bound, if it is reading large amounts of data from
the DB then more threads trying to read more data from the same source
may not help.

> Is it possible that the GIL is not being release by a thread during the time
> its blocking on the DB connection? Im using MySQLdb module and the
> application is purely written in python.

I don't know but it seems unlikely. Is there a MySQLdb list where you could ask?

Kent

From tk at eutechnyx.com  Tue Oct 28 15:43:54 2008
From: tk at eutechnyx.com (Tim Kelsey)
Date: Tue, 28 Oct 2008 14:43:54 -0000
Subject: [Tutor] Multi-threading IO and the GIL
References: <002201c938f0$22911610$07010a0a@eutechnyx.com>
	<1c2a2c590810280545n57222374vec143406b8651371@mail.gmail.com>
Message-ID: <008301c9390b$99bf62d0$07010a0a@eutechnyx.com>





----- Original Message ----- 
From: "Kent Johnson" <kent37 at tds.net>
To: "Tim Kelsey" <tk at eutechnyx.com>
Cc: <tutor at python.org>
Sent: Tuesday, October 28, 2008 12:45 PM
Subject: Re: [Tutor] Multi-threading IO and the GIL


> On Tue, Oct 28, 2008 at 7:27 AM, Tim Kelsey <tk at eutechnyx.com> wrote:
>
>> Im not sure if this is the correct list to post this sort of thing
>
> We'll try to answer pretty much any Python question.
Thanks very much for your response, im very confused by this and greatfull 
for the input.


>
>> but I
>> have a question about python threading and the GIL. I have a 
>> multi-threaded
>> application that is hitting a MySQL database for some info from within 
>> the
>> various threads. When increase the size of my thread pool I see little or 
>> no
>> improvement in the application performance but the CPU usage is not 
>> maxed.
>> This suggests to me that the app is IO bound on the database, surly more
>> threads should help in this case.
>
> I can think of a few other possibilities...
>
> Does the app actually create more threads? If you only create two
> threads, the size of the thread pool doesn't much matter.
>

The app was tested with 5 to 20 threads in the pool, this is running on a 
Linux box and 'top -H' shows the threads using CPU time. The odd behaviour 
is that adding more threads has little impact on performance, suggesting 
that the app is processor bound. However, the total CPU time is less than 
100% ( ~60 - 80% ) seemingly indicating that IO is the bottleneck.

> It's possible that all the threads are blocking on the database, for
> example if they are all trying to modify the same row. Or the app
> could truly be I/O bound, if it is reading large amounts of data from
> the DB then more threads trying to read more data from the same source
> may not help.
>

The SQL in this case is simply a very SELECT opperations returning only a 
few K of data each time. The database is not under stress ( aprox 30-50% CPU 
use )


>> Is it possible that the GIL is not being release by a thread during the 
>> time
>> its blocking on the DB connection? Im using MySQLdb module and the
>> application is purely written in python.
>
> I don't know but it seems unlikely. Is there a MySQLdb list where you 
> could ask?
>

Ill ask about and see what I can find

> Kent
>
> This email has been scanned for all known viruses by the Email Protection 
> Agency.
>

Many thanks,
Tim Kelsey





This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. No communication sent by e-mail to or from Eutechnyx is intended to give rise to contractual or other legal liability, apart from liability which cannot be excluded under English law. 

This email has been scanned for all known viruses by the Email Protection Agency.


www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322


From srilyk at gmail.com  Wed Oct 29 12:30:22 2008
From: srilyk at gmail.com (W W)
Date: Wed, 29 Oct 2008 05:30:22 -0600
Subject: [Tutor] Iterate over multiple objects
Message-ID: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>

Hi,
I'm trying to compare two strings because I want to find the difference.

i.e.
string1 = "foobar"
string2 = "foobzr"

is there a simple way to do this with a for loop? This is the method I
tried, but it gives me an error:

In [14]: for x, y in bar[0], bar[1]:
   ....:     print x, y
   ....:
   ....:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

D:\Documents and Settings\Wayne\<ipython console> in <module>()

ValueError: too many values to unpack

I suppose I could do:

for x in xrange(0, len(bar[0])):
    print bar[0][x], bar[1][x]    #yes I realize there's no comparison here,
I know how to do that - this is just a placeholder

Would that be the "best"/most pythonic solution?

Thanks,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081029/d0a333e9/attachment.htm>

From srilyk at gmail.com  Wed Oct 29 12:40:56 2008
From: srilyk at gmail.com (W W)
Date: Wed, 29 Oct 2008 05:40:56 -0600
Subject: [Tutor] Iterate over multiple objects
In-Reply-To: <49084B37.1060806@tue.nl>
References: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>
	<49084B37.1060806@tue.nl>
Message-ID: <333efb450810290440g77e294c6qdb80915ad71dac06@mail.gmail.com>

On Wed, Oct 29, 2008 at 5:38 AM, A.T.Hofkamp <a.t.hofkamp at tue.nl> wrote:

> <snip>
> With the zip() function you can merge two sequences into one:
>
> for x, y in zip(string1, string2):
>    print x, y
>

Ah! I *knew* there was a way - I just couldn't remember what it was.

Thanks!
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081029/4005ebd8/attachment.htm>

From a.t.hofkamp at tue.nl  Wed Oct 29 12:38:31 2008
From: a.t.hofkamp at tue.nl (A.T.Hofkamp)
Date: Wed, 29 Oct 2008 12:38:31 +0100
Subject: [Tutor] Iterate over multiple objects
In-Reply-To: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>
References: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>
Message-ID: <49084B37.1060806@tue.nl>

W W wrote:
> Hi,
> I'm trying to compare two strings because I want to find the difference.
> 
> i.e.
> string1 = "foobar"
> string2 = "foobzr"
> 
> is there a simple way to do this with a for loop? This is the method I
> tried, but it gives me an error:
> 
> In [14]: for x, y in bar[0], bar[1]:
>    ....:     print x, y

With the zip() function you can merge two sequences into one:

for x, y in zip(string1, string2):
     print x, y

will print something like

f f
o o
o o
b b
a z
r r


> for x in xrange(0, len(bar[0])):
>     print bar[0][x], bar[1][x]    #yes I realize there's no comparison here,
> I know how to do that - this is just a placeholder

Not entirely valid in this case, but the pythonic way to have a value as well 
as its index is by using the enumerate() function:

for idx, val in ['A', 'B', 'C']:
     print idx, val

will print something like

0 A
1 B
2 C


Good luck,
Albert


From malaclypse2 at gmail.com  Wed Oct 29 15:35:42 2008
From: malaclypse2 at gmail.com (Jerry Hill)
Date: Wed, 29 Oct 2008 10:35:42 -0400
Subject: [Tutor] Iterate over multiple objects
In-Reply-To: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>
References: <333efb450810290430x6acfc7fema66e228218b91a4a@mail.gmail.com>
Message-ID: <16651e80810290735v67732e01vf38ae4131abc7a26@mail.gmail.com>

On Wed, Oct 29, 2008 at 7:30 AM, W W <srilyk at gmail.com> wrote:
> I'm trying to compare two strings because I want to find the difference.

Albert pointed you to zip so that you can iterate through the two
strings in lockstep.  You may also want to investigate the python
difflib module in the standard library.  It has a lot of powerful
tools for comparing texts that go beyond the simple case of comparing
two strings for single-character differences.

-- 
Jerry

From qsqgeekyogdty at tiscali.co.uk  Wed Oct 29 15:53:50 2008
From: qsqgeekyogdty at tiscali.co.uk (qsqgeekyogdty at tiscali.co.uk)
Date: Wed, 29 Oct 2008 15:53:50 +0100 (GMT+01:00)
Subject: [Tutor] csv manipulation
Message-ID: <14073297.1225292030644.JavaMail.root@ps30>

hello,
i have the follwoing csv file:

"Berat","Berat","Ku?ov?","Skrapar"
"Dib?r","Bulqiz?","Dib?r","Mat"
"Durr?s","Durr?s","Kruj?"
"Elbasan","Elbasan","Gramsh","Librazhd","Peqin"
"Fier","Fier","Lushnj?","Mallakast?r"
"Gjirokast?r","Gjirokast?r","P?rmet","Tepelen?"
"Kor??","Devoll","Kolonj?","Kor??","Pogradec"
"Kuk?s","Has","Kuk?s","Tropoj?"
"Lezh?","Kurbin","Lezh?","Mirdit?"
"Shkod?r","Mal?si e Madhe","Puk?","Shkod?r"
"Tirana","Kavaj?","Tirana"
"Vlor?","Delvin?","Sarand?","Vlor?"

where thee first column contains the regions and the subsequent the 
districts.

what is the best way to return a file like:

"Berat","Ku?ov?"
"Berat","Skrapar"
"Dib?r","Bulqiz?"
"Dib?r","Dib?r"
"Dib?r","Mat"

etc...

and to write it out as a new file.

thanks




________________________________________________

Escape to the sun - http://www.tiscali.co.uk/travel/

________________________________________________


From a.t.hofkamp at tue.nl  Wed Oct 29 16:08:36 2008
From: a.t.hofkamp at tue.nl (A.T.Hofkamp)
Date: Wed, 29 Oct 2008 16:08:36 +0100
Subject: [Tutor] csv manipulation
In-Reply-To: <14073297.1225292030644.JavaMail.root@ps30>
References: <14073297.1225292030644.JavaMail.root@ps30>
Message-ID: <49087C74.60402@tue.nl>

qsqgeekyogdty at tiscali.co.uk wrote:
> hello,
> i have the follwoing csv file:
> 
> "Berat","Berat","Ku?ov?","Skrapar"
> "Dib?r","Bulqiz?","Dib?r","Mat"
> "Durr?s","Durr?s","Kruj?"
> "Elbasan","Elbasan","Gramsh","Librazhd","Peqin"
> "Fier","Fier","Lushnj?","Mallakast?r"
> "Gjirokast?r","Gjirokast?r","P?rmet","Tepelen?"
> "Kor??","Devoll","Kolonj?","Kor??","Pogradec"
> "Kuk?s","Has","Kuk?s","Tropoj?"
> "Lezh?","Kurbin","Lezh?","Mirdit?"
> "Shkod?r","Mal?si e Madhe","Puk?","Shkod?r"
> "Tirana","Kavaj?","Tirana"
> "Vlor?","Delvin?","Sarand?","Vlor?"
> 
> where thee first column contains the regions and the subsequent the 
> districts.
> 
> what is the best way to return a file like:
> 
> "Berat","Ku?ov?"
> "Berat","Skrapar"
> "Dib?r","Bulqiz?"
> "Dib?r","Dib?r"
> "Dib?r","Mat"
> 
> etc...
> 
> and to write it out as a new file.

Python has a 'csv' library, which handles your kind of files.
I have never used it however, so I cannot give you more details.


Good luck,
Albert

From gslindstrom at gmail.com  Wed Oct 29 13:59:37 2008
From: gslindstrom at gmail.com (Greg Lindstrom)
Date: Wed, 29 Oct 2008 07:59:37 -0500
Subject: [Tutor] PyCon 2009 - Call for tutorials nearing the end
Message-ID: <a9f39a410810290559x78c1a950kd080863e30e9575f@mail.gmail.com>

The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
"pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more (there was particular interest in "Intermediate" level
classes).  Class size varied from 10 to over 60 students. The extended time
spent in class allows teachers to cover a lot of material while
allowing forinteraction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at <
http://us.pycon.org/2009/tutorials/proposals/>.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact pycon-tutorials at python.org.

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081029/360551e2/attachment-0001.htm>

From bgailer at gmail.com  Wed Oct 29 16:28:46 2008
From: bgailer at gmail.com (bob gailer)
Date: Wed, 29 Oct 2008 11:28:46 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <14073297.1225292030644.JavaMail.root@ps30>
References: <14073297.1225292030644.JavaMail.root@ps30>
Message-ID: <4908812E.4000708@gmail.com>

qsqgeekyogdty at tiscali.co.uk wrote:
> hello,
> i have the follwoing csv file:
>
> "Berat","Berat","Ku?ov?","Skrapar"
> "Dib?r","Bulqiz?","Dib?r","Mat"
> "Durr?s","Durr?s","Kruj?"
> "Elbasan","Elbasan","Gramsh","Librazhd","Peqin"
> "Fier","Fier","Lushnj?","Mallakast?r"
> "Gjirokast?r","Gjirokast?r","P?rmet","Tepelen?"
> "Kor??","Devoll","Kolonj?","Kor??","Pogradec"
> "Kuk?s","Has","Kuk?s","Tropoj?"
> "Lezh?","Kurbin","Lezh?","Mirdit?"
> "Shkod?r","Mal?si e Madhe","Puk?","Shkod?r"
> "Tirana","Kavaj?","Tirana"
> "Vlor?","Delvin?","Sarand?","Vlor?"
>
> where thee first column contains the regions and the subsequent the 
> districts.
>
> what is the best way to return a file like:
>
> "Berat","Ku?ov?"
> "Berat","Skrapar"
> "Dib?r","Bulqiz?"
> "Dib?r","Dib?r"
> "Dib?r","Mat"
>
> etc...
>
> and to write it out as a new file.
>
>   
There is a csv module, but for something this simple the following will 
suffice:

input = open(path-to-the-input-file, 'r')
output = open(path-to-the-output-file, 'w')

for line in input:
  line = line.split(",") # ["Berat", "Berat", "Ku?ov?", "Skrapar"]
  region = line [0]
  for district in line[1:]:
    output.write(region + "," + district + "\n")
input.close()
output.close()

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From bgailer at gmail.com  Wed Oct 29 17:11:45 2008
From: bgailer at gmail.com (bob gailer)
Date: Wed, 29 Oct 2008 12:11:45 -0400
Subject: [Tutor] csv manipulation OOPS
In-Reply-To: <4908812E.4000708@gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
Message-ID: <49088B41.5080603@gmail.com>

I goofed - overrode input. So I changed my filenames
> [snip]
> inputFile = open(path-to-the-input-file, 'r')
> outputFile = open(path-to-the-output-file, 'w')
>
> for line in inputFile :
>  line = line.split(",") # ["Berat", "Berat", "Ku?ov?", "Skrapar"]
>  region = line [0]
>  for district in line[1:]:
>    outputFile .write(region + "," + district + "\n")
> inputFile .close()
> outputFile .close()
>


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From kent37 at tds.net  Wed Oct 29 18:31:00 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 29 Oct 2008 13:31:00 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <4908812E.4000708@gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
Message-ID: <1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>

On Wed, Oct 29, 2008 at 11:28 AM, bob gailer <bgailer at gmail.com> wrote:
> qsqgeekyogdty at tiscali.co.uk wrote:
>>
>> hello,
>> i have the follwoing csv file:
>>
>> "Berat","Berat","Ku?ov?","Skrapar"

> There is a csv module, but for something this simple the following will
> suffice:

as long as none of the data fields include a comma...given that the
equivalent program using csv is barely longer than your example, and
more robust, it seems worth using to me. For example (untested):

import csv

inputFile= open(path-to-the-input-file, 'rb')
reader = csv.reader(inputFile)
outputFile = open(path-to-the-output-file, 'wb')
writer = csv.writer(outputFile)

for line in reader:
 region = line [0]
 for district in line[1:]:
  writer.write((region, district))
inputFile.close()
outputFile.close()

Kent

From denis.spir at free.fr  Thu Oct 30 12:27:57 2008
From: denis.spir at free.fr (spir)
Date: Thu, 30 Oct 2008 12:27:57 +0100
Subject: [Tutor] class/type methods/functions
Message-ID: <49099A3D.9020003@free.fr>

Hello,

New to the list. I'm a self-taught, amateur programmer. Also, non-native 
english speaker -- so, don't be surprised with weird expression.

Q: Is there a way to write /type/ (class) functions, meaning methods not 
bound to an instance, in python?

Context: I'm developping an application that should be able to 
read/write wiki source text and matching xhtml docs (and more...). 
Actually, a first version worked, but I'm refactoring it for several 
reasons. To do that, I use a core set of 'symbol' types:
wiki lang1
wiki lang2 ==> config ==> symbol types <== xhtml subset
wiki lang3
Each type holds relevant config data and is defines methods used to cope 
with r/w processes. Each symbol holds relevant data, read from 
(whichever) source text, and is able to write itself into (any) target 
language. A sequence of symbols thus builds a kind of abstract 
representation of a source text:
wiki text  <==>  symbol sequence  <==>  xhtml doc
[I'm aware that there are more efficient and professional methods -- 
it's not the point here. And I like this model ;-).]
Example of a symbol type:
class Format(Symbol):
    ''' block format symbol '''
    # import relevant config data
    from_codes = config.formats.from_codes
    to_codes = config.formats.to_codes
    names = config.formats.names
    [...methods...]
Now, I want to let the user change the wiki config at runtime in order 
to 'transcode' a wiki text into another wiki language.
To achieve that, I intended to put config import instructions in a 
/type/ method, thus callable at runtime ():
class Format(Symbol):
    ''' block format symbol '''
    # import relevant config data
    def config():
        Format.from_codes = config.formats.from_codes
        Format.to_codes = config.formats.to_codes
        Format.names = config.formats.names
    [...methods...]
[...more classes...]
def config()
    config.build_config(config_file_name)
    for symbol_type in Symbol.types:
       symbol_type.config()

Problem:
I can't find any way to write a non_bound_to_an_instance method, a type 
specific method. I get of course the following:
"TypeError: unbound method config() must be called with Format instance 
as first argument (got nothing instead)"
While the Format's config() function is not intended to be a instance 
method at all. It is a type specific attribute.

Exploration:
As types (classes) are supposed to be objects, they should have their 
own attributes like any instance. Both functional (callable, methods) 
and non_functional (data, properties). Data attributes work well for a 
type, e.g.
MyType.attr = x
print MyType.attr
But strangely I can't find the way to do that for callable things:
MyType.f() launches the previous error message.
Actually, does python syntax give a way to distinguish type attributes 
from instance attributes, in the case of methods? I don't know. One can 
write:
attr            --> type property r/w (1)
MyType.attr     --> type property r/w (1)
self.attr       --> instance property r/w
???             --> type method def/call
f(self,args)    --> instance method definition
self.f(args)    --> instance method call
(1) Inside the type's definition, at upper level, the owner of the 
attribute needs not beeing specified: it is the type. Elsewhere, the 
attribute must be prefixed.
The problem may reside in the difference of syntax between properties 
and methods. To identify instance attributes, self.x is used for 
properties in both definition (write) and use (read) cases, while for 
methods the definition has to be written f(self,args) instead of 
self.f(args). Imagine that the syntax would be consistent. One could 
then write:
class T(instance):
    ''' type with type method '''
    a = 1
    def f():
        print "I'm a type method. 'a' is:", T.a
    def self.g():
       print "I'm an instance method. 'b' is:", self.b
    def self.__init__(b):
       self.b = b
T.f()
z = T(2)
z.g()
Note that this or that syntax is just a convention. And that "def 
self.g()" does not seem to conflict with present syntax rules. In fact, 
it more consistent with the rules for non-callable attributes, and 
reflects the method call syntax. At least, that's what I currently think.
Actually no syntax reflect the 'real' background process of instance 
method call, which in that case would be (note that both type and 
instance are passed as arguments):
T.__dict__['g'].__get__(z, T)
see 
[http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html]:

Workaround:
I presently plan to 'externalise' type config functions at module level.
def format_config():
    Format.from_codes = config.formats.from_codes
    Format.to_codes = config.formats.to_codes
    Format.names = config.formats.names
[...more pseudo type-specific config functions...]
def config()
    config.build_config(config_file_name)
    format_config()
    [...more calls to type config functions...]
But I'm not happy with that at all... Type specific features should 
definitely lie inside the type's definition!

What do you think of that? Maybe an obvious python feature hasn't 
reached my mind yet...
Denis




From bgailer at gmail.com  Thu Oct 30 12:54:00 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 30 Oct 2008 07:54:00 -0400
Subject: [Tutor] class/type methods/functions
In-Reply-To: <49099A3D.9020003@free.fr>
References: <49099A3D.9020003@free.fr>
Message-ID: <4909A058.40605@gmail.com>

spir wrote:
> Hello,
>
> New to the list. I'm a self-taught, amateur programmer. Also, 
> non-native english speaker -- so, don't be surprised with weird 
> expression.
>
> Q: Is there a way to write /type/ (class) functions, meaning methods 
> not bound to an instance, in python?

Take a look at the built-in functions classmethod and staticmethod
>
> Context: I'm developping an application that should be able to 
> read/write wiki source text and matching xhtml docs (and more...). 
> Actually, a first version worked, but I'm refactoring it for several 
> reasons. To do that, I use a core set of 'symbol' types:
> wiki lang1
> wiki lang2 ==> config ==> symbol types <== xhtml subset
> wiki lang3
> Each type holds relevant config data and is defines methods used to 
> cope with r/w processes. Each symbol holds relevant data, read from 
> (whichever) source text, and is able to write itself into (any) target 
> language. A sequence of symbols thus builds a kind of abstract 
> representation of a source text:
> wiki text  <==>  symbol sequence  <==>  xhtml doc
> [I'm aware that there are more efficient and professional methods -- 
> it's not the point here. And I like this model ;-).]
> Example of a symbol type:
> class Format(Symbol):
>    ''' block format symbol '''
>    # import relevant config data
>    from_codes = config.formats.from_codes
>    to_codes = config.formats.to_codes
>    names = config.formats.names
>    [...methods...]
> Now, I want to let the user change the wiki config at runtime in order 
> to 'transcode' a wiki text into another wiki language.
> To achieve that, I intended to put config import instructions in a 
> /type/ method, thus callable at runtime ():
> class Format(Symbol):
>    ''' block format symbol '''
>    # import relevant config data
>    def config():
>        Format.from_codes = config.formats.from_codes
>        Format.to_codes = config.formats.to_codes
>        Format.names = config.formats.names
>    [...methods...]
> [...more classes...]
> def config()
>    config.build_config(config_file_name)
>    for symbol_type in Symbol.types:
>       symbol_type.config()
>
> Problem:
> I can't find any way to write a non_bound_to_an_instance method, a 
> type specific method. I get of course the following:
> "TypeError: unbound method config() must be called with Format 
> instance as first argument (got nothing instead)"
> While the Format's config() function is not intended to be a instance 
> method at all. It is a type specific attribute.
>
> Exploration:
> As types (classes) are supposed to be objects, they should have their 
> own attributes like any instance. Both functional (callable, methods) 
> and non_functional (data, properties). Data attributes work well for a 
> type, e.g.
> MyType.attr = x
> print MyType.attr
> But strangely I can't find the way to do that for callable things:
> MyType.f() launches the previous error message.
> Actually, does python syntax give a way to distinguish type attributes 
> from instance attributes, in the case of methods? I don't know. One 
> can write:
> attr            --> type property r/w (1)
> MyType.attr     --> type property r/w (1)
> self.attr       --> instance property r/w
> ???             --> type method def/call
> f(self,args)    --> instance method definition
> self.f(args)    --> instance method call
> (1) Inside the type's definition, at upper level, the owner of the 
> attribute needs not beeing specified: it is the type. Elsewhere, the 
> attribute must be prefixed.
> The problem may reside in the difference of syntax between properties 
> and methods. To identify instance attributes, self.x is used for 
> properties in both definition (write) and use (read) cases, while for 
> methods the definition has to be written f(self,args) instead of 
> self.f(args). Imagine that the syntax would be consistent. One could 
> then write:
> class T(instance):
>    ''' type with type method '''
>    a = 1
>    def f():
>        print "I'm a type method. 'a' is:", T.a
>    def self.g():
>       print "I'm an instance method. 'b' is:", self.b
>    def self.__init__(b):
>       self.b = b
> T.f()
> z = T(2)
> z.g()
> Note that this or that syntax is just a convention. And that "def 
> self.g()" does not seem to conflict with present syntax rules. In 
> fact, it more consistent with the rules for non-callable attributes, 
> and reflects the method call syntax. At least, that's what I currently 
> think.
> Actually no syntax reflect the 'real' background process of instance 
> method call, which in that case would be (note that both type and 
> instance are passed as arguments):
> T.__dict__['g'].__get__(z, T)
> see 
> [http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html]: 
>
>
> Workaround:
> I presently plan to 'externalise' type config functions at module level.
> def format_config():
>    Format.from_codes = config.formats.from_codes
>    Format.to_codes = config.formats.to_codes
>    Format.names = config.formats.names
> [...more pseudo type-specific config functions...]
> def config()
>    config.build_config(config_file_name)
>    format_config()
>    [...more calls to type config functions...]
> But I'm not happy with that at all... Type specific features should 
> definitely lie inside the type's definition!
>
> What do you think of that? Maybe an obvious python feature hasn't 
> reached my mind yet...
> Denis
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From a.t.hofkamp at tue.nl  Thu Oct 30 13:30:56 2008
From: a.t.hofkamp at tue.nl (A.T.Hofkamp)
Date: Thu, 30 Oct 2008 13:30:56 +0100
Subject: [Tutor] class/type methods/functions
In-Reply-To: <49099A3D.9020003@free.fr>
References: <49099A3D.9020003@free.fr>
Message-ID: <4909A900.8030204@tue.nl>

spir wrote:
> Q: Is there a way to write /type/ (class) functions, meaning methods not 
> bound to an instance, in python?

As Bob Gailer already said, staticmethod seems to do what you want.

After reading your mail, I cannot help wondering that something crucial seems 
to be missing in your class structure. (I get the impression that you are 
trying to squeeze object information and object meta information together in 
one class definition.)

The examples you give are however too fragmented for me, to understand the 
underlying problem you are trying to solve.


Have you considered using the factory pattern? (ie make an object that 
represents the type, and another one for the data) In that way you can nicely 
seperate both kinds of information.


Sincerely,
Albert

From roadierich at googlemail.com  Thu Oct 30 16:50:58 2008
From: roadierich at googlemail.com (Richard Lovely)
Date: Thu, 30 Oct 2008 15:50:58 +0000
Subject: [Tutor] Problems with Calculator Program
Message-ID: <f0b4202b0810300850m217b7f25o30f4bc06868c5bbd@mail.gmail.com>

Hi,  I'm trying to teach myself Tkinter by making a desktop calculator.

I've got the Tkinter bit working, but getting the output to work how I
want it to is causing serious brainfreeze...

The buttons 0 through 9 and '.' all append to a queue, which
makeNumber(queue) returns as an actual python number.  That all works.

Pressing one of the operators (+, -, /, *, or =) calls the following function:

def evaluate(op):
    """Evaluate a queue of button presses:
    eg: [1, 2, 3, '+', 3, 2, 1] => 123 + 321 = 444"""

    global last_op, total

    initial_total = total
    try:
        operand = makeNumber(queue)
    except ValueError:
        operand = ''

    if last_op == 'add':
        disp_op = '+'
        total += operand if operand != '' else 0

    elif last_op == 'sub':
        disp_op = '-'
        total -= operand if operand != '' else 0

    elif last_op == 'div':
        disp_op = '/'
        total /= float(operand) if operand != '' else 1

    elif last_op == 'mul':
        disp_op = '*'
        total *= operand if operand != '' else 1

    else:
        disp_op = ''
    if int(total) == total:
        total = int(total)

    if last_op == '':
        print operand,
    else:
        print initial_total, disp_op, operand, '=', total
    last_op = op
    clearqueue()

What I want it to do is something like:
(the first list indicates button presses NOT the contents of the queue
[1, 2, 3, '+', 3, 2, 1, '*' 2] =>
queue = [1,2,3]; evaluate('add') gives output:
123 + 321 = 444
queue = [3,2,1]; evaluate('mul') gives output:
444 * 2 = 888

Like I said, the makeNumber function works, and the numbers are
definatly getting appended to the queue.  The logic within the above
function is the problem.  The main problem is allowing button
sequences like:
number op number equals, number op number equals


Did that make any sense at all?
-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com

From rabidpoobear at gmail.com  Thu Oct 30 17:22:09 2008
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Thu, 30 Oct 2008 11:22:09 -0500
Subject: [Tutor] Problems with Calculator Program
In-Reply-To: <f0b4202b0810300850m217b7f25o30f4bc06868c5bbd@mail.gmail.com>
References: <f0b4202b0810300850m217b7f25o30f4bc06868c5bbd@mail.gmail.com>
Message-ID: <dfeb4470810300922x2f241bb6kc38920499386a4f2@mail.gmail.com>

Seems like when they press "op" you assume that the current number is
done being executed and save the value.  Then when they press another
op, you evaluate the previous op with the new value.  You don't update
the display until they start typing again.
However, when they press =, you evaluate the previous instruction,
display the result, and then accept input.

On Thu, Oct 30, 2008 at 10:50 AM, Richard Lovely
<roadierich at googlemail.com> wrote:
> Hi,  I'm trying to teach myself Tkinter by making a desktop calculator.
>
> I've got the Tkinter bit working, but getting the output to work how I
> want it to is causing serious brainfreeze...
>
> The buttons 0 through 9 and '.' all append to a queue, which
> makeNumber(queue) returns as an actual python number.  That all works.
>
> Pressing one of the operators (+, -, /, *, or =) calls the following function:
>
> def evaluate(op):
>    """Evaluate a queue of button presses:
>    eg: [1, 2, 3, '+', 3, 2, 1] => 123 + 321 = 444"""
>
>    global last_op, total
>
>    initial_total = total
>    try:
>        operand = makeNumber(queue)
>    except ValueError:
>        operand = ''
>
>    if last_op == 'add':
>        disp_op = '+'
>        total += operand if operand != '' else 0
>
>    elif last_op == 'sub':
>        disp_op = '-'
>        total -= operand if operand != '' else 0
>
>    elif last_op == 'div':
>        disp_op = '/'
>        total /= float(operand) if operand != '' else 1
>
>    elif last_op == 'mul':
>        disp_op = '*'
>        total *= operand if operand != '' else 1
>
>    else:
>        disp_op = ''
>    if int(total) == total:
>        total = int(total)
>
>    if last_op == '':
>        print operand,
>    else:
>        print initial_total, disp_op, operand, '=', total
>    last_op = op
>    clearqueue()
>
> What I want it to do is something like:
> (the first list indicates button presses NOT the contents of the queue
> [1, 2, 3, '+', 3, 2, 1, '*' 2] =>
> queue = [1,2,3]; evaluate('add') gives output:
> 123 + 321 = 444
> queue = [3,2,1]; evaluate('mul') gives output:
> 444 * 2 = 888
>
> Like I said, the makeNumber function works, and the numbers are
> definatly getting appended to the queue.  The logic within the above
> function is the problem.  The main problem is allowing button
> sequences like:
> number op number equals, number op number equals
>
>
> Did that make any sense at all?
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From dineshbvadhia at hotmail.com  Thu Oct 30 19:36:10 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Thu, 30 Oct 2008 11:36:10 -0700
Subject: [Tutor] fast list traversal
Message-ID: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>

I need to process a large number (> 20,000) of long and variable length lists (> 5,000 elements) ie.

for element in long_list:
    <do something with element>        # the result of this operation is not a list

The performance is reasonable but I wonder if there are faster Python methods?

Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/d1eb4541/attachment-0001.htm>

From bgailer at gmail.com  Thu Oct 30 19:40:17 2008
From: bgailer at gmail.com (bob gailer)
Date: Thu, 30 Oct 2008 14:40:17 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
Message-ID: <4909FF91.5060307@gmail.com>

Dinesh B Vadhia wrote:
> I need to process a large number (> 20,000) of long and variable 
> length lists (> 5,000 elements) ie.
>  
> for element in long_list:
>     <do something with element>        # the result of this operation 
> is not a list
>  
> The performance is reasonable but I wonder if there are faster Python 
> methods?

I don't know of any. Of course it could depend on what you are doing 
with each element. Say more!

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From Shawn at milochik.com  Thu Oct 30 19:46:50 2008
From: Shawn at milochik.com (Shawn Milochik)
Date: Thu, 30 Oct 2008 14:46:50 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <4909FF91.5060307@gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
Message-ID: <2dc0c81b0810301146o13fd83e6u91424abb4675bf48@mail.gmail.com>

On Thu, Oct 30, 2008 at 2:40 PM, bob gailer <bgailer at gmail.com> wrote:
> Dinesh B Vadhia wrote:
>>
>> I need to process a large number (> 20,000) of long and variable length
>> lists (> 5,000 elements) ie.
>>  for element in long_list:
>>    <do something with element>        # the result of this operation is
>> not a list
>>  The performance is reasonable but I wonder if there are faster Python
>> methods?


You might try using dictionaries instead. I've had phenomenal speed
gains by switching lists to dictionaries before, although that may
have had more to do with the fact that I needed to access certain
values, rather than iterating through them in sequential order like
you're doing.

It seems counter-intuitive because  a dictionary has a key and a
value, and you really only need the key (you can leave all the values
blank, or set them to zero or something), but it's a lot faster to
find a dictionary element than a list element. It has something to do
with the underlying code, but I have been assured that the same thing
applies to hashes and arrays in Perl, etc.

Shawn

From dineshbvadhia at hotmail.com  Thu Oct 30 20:00:05 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Thu, 30 Oct 2008 12:00:05 -0700
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
Message-ID: <COL103-DS18A945128B3F288CD72383A3210@phx.gbl>

Bob:  Nothing special is being done on the elements of the list - additions/subtractions/ - and storing the results in an array. That's it.

Dinesh



From: bob gailer 
Sent: Thursday, October 30, 2008 11:40 AM
To: Dinesh B Vadhia 
Cc: tutor at python.org 
Subject: Re: [Tutor] fast list traversal


Dinesh B Vadhia wrote:
> I need to process a large number (> 20,000) of long and variable 
> length lists (> 5,000 elements) ie.
>  
> for element in long_list:
>     <do something with element>        # the result of this operation 
> is not a list
>  
> The performance is reasonable but I wonder if there are faster Python 
> methods?

I don't know of any. Of course it could depend on what you are doing 
with each element. Say more!

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/eb5a0cea/attachment.htm>

From kent37 at tds.net  Thu Oct 30 21:01:45 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 30 Oct 2008 16:01:45 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
Message-ID: <1c2a2c590810301301q27885c86le914e77f83d872bf@mail.gmail.com>

On Thu, Oct 30, 2008 at 2:36 PM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> I need to process a large number (> 20,000) of long and variable length
> lists (> 5,000 elements) ie.
>
> for element in long_list:
>     <do something with element>        # the result of this operation is not
> a list
>
> The performance is reasonable but I wonder if there are faster Python
> methods?

A list comprehension might be faster. A specific code example would
help, optimizations are pretty specific to the job at hand.

Kent

From kent37 at tds.net  Thu Oct 30 21:05:13 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 30 Oct 2008 16:05:13 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <2dc0c81b0810301146o13fd83e6u91424abb4675bf48@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
	<2dc0c81b0810301146o13fd83e6u91424abb4675bf48@mail.gmail.com>
Message-ID: <1c2a2c590810301305x207f730awbb483964e58365ad@mail.gmail.com>

On Thu, Oct 30, 2008 at 2:46 PM, Shawn Milochik <Shawn at milochik.com> wrote:

> You might try using dictionaries instead. I've had phenomenal speed
> gains by switching lists to dictionaries before, although that may
> have had more to do with the fact that I needed to access certain
> values, rather than iterating through them in sequential order like
> you're doing.

Looking up individual values (i.e. testing for membership) is much
faster for dicts and sets than for lists. Problems of the form

for item in long_list_1:
  if item in long_list_2:
    do something with item

will be much faster if long_list_2 is changed to a set. This is
because the complexity goes from O(len(long_list_1) *
len(long_list_2)) to O(len(long_list_1)).

Iterating is probably faster on lists, certainly it is not
"phenomenally" faster to iterate a dict than a list.

Kent

From denis.spir at free.fr  Thu Oct 30 21:07:00 2008
From: denis.spir at free.fr (spir)
Date: Thu, 30 Oct 2008 21:07:00 +0100
Subject: [Tutor] [Re:  class/type methods/functions]
Message-ID: <490A13E4.5000206@free.fr>

[forwarded, only A.T.Hofkamp got this answer]

A.T.Hofkamp a ?crit :
> spir wrote:
>> Q: Is there a way to write /type/ (class) functions, meaning methods 
not bound to an instance, in python?
>
> As Bob Gailer already said, staticmethod seems to do what you want.
Thank you for you answers about static methods. I will explore that 
path. Seems to be what I was looking for.
>
> After reading your mail, I cannot help wondering that something 
crucial seems to be missing in your class structure. (I get the 
impression that you are trying to squeeze object information and object 
meta information together in one class definition.)
>
Yes. This is a consequence of type & instance beeing defined in the same 
class() code section. If I unserstand well, what you call 
meta_information is for me simply type attributes. They will be 
available to any object of this type. Is this a misuse of types/classes? 
See also below for some more precisions.
This syntax that mixes type and object definition applies to all OOP 
languages, no? That's why we need a syntactic rule to distinguish type & 
instance attributes. In python, the way I understand it, the prefix 
'self.' (or any other special name) plays that role. It works for 
properties, i.e. non-method attributes. But the syntax chosen for method 
definition (with self written as argument instead of prefixed) makes it 
impossible: it seems that any method has to be bound to an instance.
> The examples you give are however too fragmented for me, to 
understand the underlying problem you are trying to solve.
>
Unfortunately, I can't paste right now a full & real snippet of the, as 
it is beeing refactored: it would rather be confusing. Here is a kind of 
outline of a typical symbol type:

class Format(Symbol):
   ''' block formats symbol '''
   # import relevant config data for this symbol type
   from_codes = config.formats.from_codes
   to_codes = config.formats.to_codes
   names = config.formats.names
   # open_format to be checked with closing tag (xhtml only)
   open_format = None
   def __init__(self, source, mark, section_level, posV, posH, close = 
False,
                   list_type = None, list_level=0):
       # posV & posH ~ line & element numbers for error output
       # 'mark' can be a wiki code or an xhfml tag
       self.section_level = section_level        # = current title level
       self.indent = section_level * TAB         # for nicer xhtml output
       self.close = close                        # for automatic 
closing (wiki only)
       self.list_level = list_level              # nesting level
       self.list_type = list_type                # bullet or number
       self.error = False                        # flag used for no output
       # read & record symbol data
       if source == WIKI:
           self.from_wiki(mark, posV, posH)
           return
       if source == XHTML:
           self.from_xhtml(mark, posV, posH)
   def from_wiki(self, code, posV, posH):
       ''' Define formats name.
           Record whether it's an opening or closing mark.'''
       [...]
   def from_xhtml(self, tag, posV, posH):
       ''' Define formats code. '''
       [...]
   def into_wiki(self):
       if self.error or self.close:
           return ''
       if self.name == LIST_ITEM:        # case of a list
           code = Format.to_codes[self.list_type]
           code *= self.list_level
       else:
           code = Format.to_codes[self.name]
       if code in header_block_codes:
           code *= self.section_level
       return code + SPACE
   def into_xhtml(self):
       if self.error:
           return ''
       return write_tag(self.name, self.close, DIV, self.section_level)
   def to_table():
       ''' write symbol data into plain text, table-like, format
           (for test or export to DB) '''
       [...]
  
(Note: by the way, native english speakers may tell me if the 
identifiers & comments seem clear -- the original program was in french 
-- but I will probably share it later. One of reasons of the rebuilding.)

So, as you can see, symbols of the Format type will use data held by 
their type. This seems rather an obvious and consistent practice to me. 
Namely, the from_codes, to_codes and names type attributes are available 
to future Format instances. these attributes were imported from an 
config module/object built at startup (from a config file).
The main process for building a sequence of symbols is (simplified):
* A function reads the source file step by step. Actually, it is a 
method of kind of state machine. Let's say the source is an xhtml doc 
(wiki codes vary much and are much less regular and more ambiguous).
* When it steps on a format tag (e.g. <li> for a lit item), it launches 
the creation of a format object, thus an instance of the Format type. 
Clear? Passes to it as argument relevant actual data of the parsing 
process, especially 'mark', that in this case holds the tag.
* The format will "read itself" from the tag, meaning it will record 
that it is an opening tag, a 'list item', and, say, one of the bullet 
kind. That'all for this kind of simple example.
That is more or less the way a representation of the source text is built.
The writing process is more straighforword. A (very) simplified outline 
may be:
for symbol in tortue.symbols:   # I called the state machine'turtle' ;-)
   out_file.write(symbol.into_wiki())  # case of writing into wiki lang
The symbols even take care of line feeds & consistent indentation!
Now, imagine it was a wiki text instead, and the user wishes to output 
it into a wiki language different of the one it was originally coded in. 
At some time between the reading & writing will the config been rebuilt 
and, as a consequence, data held by Symbol types. As this is an action 
of the type, I wish it to be performed by the type. So:
class Format(Symbol):
   ''' block formats symbol '''
   # import relevant config data for this symbol type
   def config():   # should be a type method (static?)
       from_codes = config.formats.from_codes
       to_codes = config.formats.to_codes
       names = config.formats.names


> Have you considered using the factory pattern? (ie make an object 
that represents the type, and another one for the data) In that way you 
can nicely seperate both kinds of information.
>
Definitely! That is the pattern I'm using -- or trying. I didn't know it 
has a name.  Now, isn't this factory<->object pattern precisely what the 
type<->instance relationship is supposed to be?
Now, I admit that in my particuliar case, the types/classes need the 
full potential of real objects:
* config ==> type properties
* config change at runtime ==> type methods
>
> Sincerely,
> Albert
>

If anyone of you wishes to comment/criticize the "exploration" part of 
my previous post, welcome!

Thank you all for your advices.
denis






From denis.spir at free.fr  Thu Oct 30 21:09:29 2008
From: denis.spir at free.fr (spir)
Date: Thu, 30 Oct 2008 21:09:29 +0100
Subject: [Tutor] class/type methods/functions
In-Reply-To: <49099CC8.3060801@free.fr>
References: <49099CC8.3060801@free.fr>
Message-ID: <490A1479.2010408@free.fr>

Hello again,

I just tried with the classmethod() built_in function. Well, this is 
exactly what I was looking for. It supplies a way of defining type_level 
methods -- what was missing before.
[I still think this is a workaround: we would not need this if the 
syntax was the same for methods and properties, or what?]
It makes the job: below an simulation example related to the previously 
exposed case.

class Config(object):
    pass
config = Config()

class Format(object):
    @classmethod                    # with so-called "decorator"
    def config(Format):
        Format.a = config.format_a
    #config = classmethod(config)   # with built_in function

def build_config():
    # (re)read config data from file
    # e.g. value for format 'n' parameter in file
    config.format_a = 1
    # let the symbol types (re) import their proper config
    # e.g. Format
    Format.config()    # no error!

build_config()
print Format.a # 1!

Well, would someone clarify the point about decorators? Rather the point 
of having both a built-in function (introduced in python 2.2, as I just 
read) and a "decorator" (2.4) for a single use of declaring a method 
not_to_be_bound_to_an_instance? I'm rather sure there's more behind... I 
noticed that more and more features expressed with built-in functions 
get alternative syntax.


Denis


From kent37 at tds.net  Thu Oct 30 21:47:14 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 30 Oct 2008 16:47:14 -0400
Subject: [Tutor] class/type methods/functions
In-Reply-To: <490A1479.2010408@free.fr>
References: <49099CC8.3060801@free.fr> <490A1479.2010408@free.fr>
Message-ID: <1c2a2c590810301347q23d16723l7c708207a71eb90d@mail.gmail.com>

On Thu, Oct 30, 2008 at 4:09 PM, spir <denis.spir at free.fr> wrote:

> Well, would someone clarify the point about decorators? Rather the point of
> having both a built-in function (introduced in python 2.2, as I just read)
> and a "decorator" (2.4) for a single use of declaring a method
> not_to_be_bound_to_an_instance?

Decorators are the @ syntax, not the function. In otherwords,

@classmethod
def foo():
  ...

means, decorate the function foo using the function classmethod.

More details here:
http://personalpages.tds.net/~kent37/kk/00001.html

Kent

From Shawn at milochik.com  Thu Oct 30 21:55:56 2008
From: Shawn at milochik.com (Shawn Milochik)
Date: Thu, 30 Oct 2008 16:55:56 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <1c2a2c590810301305x207f730awbb483964e58365ad@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
	<2dc0c81b0810301146o13fd83e6u91424abb4675bf48@mail.gmail.com>
	<1c2a2c590810301305x207f730awbb483964e58365ad@mail.gmail.com>
Message-ID: <2dc0c81b0810301355r75d95c4ew8b0bfcbc9c7715ec@mail.gmail.com>

On Thu, Oct 30, 2008 at 4:05 PM, Kent Johnson <kent37 at tds.net> wrote:
> On Thu, Oct 30, 2008 at 2:46 PM, Shawn Milochik <Shawn at milochik.com> wrote:
>
>> You might try using dictionaries instead. I've had phenomenal speed
>> gains by switching lists to dictionaries before, although that may
>> have had more to do with the fact that I needed to access certain
>> values, rather than iterating through them in sequential order like
>> you're doing.
>
> Looking up individual values (i.e. testing for membership) is much
> faster for dicts and sets than for lists. Problems of the form
>
> for item in long_list_1:
>  if item in long_list_2:
>    do something with item
>
> will be much faster if long_list_2 is changed to a set. This is
> because the complexity goes from O(len(long_list_1) *
> len(long_list_2)) to O(len(long_list_1)).
>
> Iterating is probably faster on lists, certainly it is not
> "phenomenally" faster to iterate a dict than a list.
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



I just ran a very crude test.

Results: Lists load more quickly but iterate more slowly. Dictionaries
take longer to load but iteration takes about half the time.

Sample output:



Results for 9999999 iterations:
	List:
		Load: 4.75 seconds
		Process: 6.64 seconds

	Dictionary:
		Load: 7.54 seconds
		Process: 3.31 seconds

Comparison:
	List loads 0.63 times the speed of a dictionary.
	List processes loads 2.00 times the speed of a dictionary.







Results for 7654321 iterations:
	List:
		Load: 3.29 seconds
		Process: 4.72 seconds

	Dictionary:
		Load: 5.47 seconds
		Process: 2.41 seconds

Comparison:
	List loads 0.60 times the speed of a dictionary.
	List processes loads 1.96 times the speed of a dictionary.







Code:


#!/usr/bin/env python


import time

the_dict = {}
the_list = []

iter_num = 7654321


fill_list_time = time.time()

for x in range(iter_num):
    the_list.append(x)

fill_list_time = time.time() - fill_list_time

fill_dict_time = time.time()

for x in range(iter_num):
    the_list.append(x)
    the_dict[x] = 0

fill_dict_time = time.time() - fill_dict_time





proc_list_time = time.time()

for thing in the_list:

    thing = thing * 2

proc_list_time = time.time() - proc_list_time


proc_dict_time = time.time()

for thing in the_dict:

    thing = thing * 2

proc_dict_time = time.time() - proc_dict_time


print "Results for %d iterations:" % iter_num
print "\tList:"
print "\t\tLoad: %.2f seconds" % fill_list_time
print "\t\tProcess: %.2f seconds" % proc_list_time
print
print "\tDictionary:"
print "\t\tLoad: %.2f seconds" % fill_dict_time
print "\t\tProcess: %.2f seconds" % proc_dict_time
print
print "Comparison: "
print "\tList loads %.2f times the speed of a dictionary." %
(fill_list_time / fill_dict_time)
print "\tList processes loads %.2f times the speed of a dictionary." %
(proc_list_time / proc_dict_time)

From dineshbvadhia at hotmail.com  Thu Oct 30 23:01:15 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Thu, 30 Oct 2008 15:01:15 -0700
Subject: [Tutor] unordered and ordered defaultdict(set)
Message-ID: <COL103-DS246E03867DDF07DFB70561A3210@phx.gbl>

Here is an interesting result with defaultdict(set). This program creates 2 dictionaries of sets with the first dictionary containing 10 elements per set and the second containing 25 elements.  You'll see the sets in the first dictionary are unordered and in the second they are ordered.  

import random
from collections import defaultdict

a = defaultdict(set)

l = [10, 25, 35]
for last in l:
        for s in xrange(0, 10, 1):
            for t in xrange(0, last, 1):
                    r = random.randint(1,101)
                    a[s].add(r)

            for r in a.items():
                    print r
    print


(0, set([36, 38, 12, 77, 15, 49, 19, 23, 61, 95]))
(1, set([1, 34, 3, 37, 38, 11, 80, 17, 59]))
(2, set([67, 37, 11, 79, 81, 90, 60, 62, 69]))
(3, set([34, 98, 44, 66, 13, 81, 53, 55, 25, 79]))
(4, set([98, 101, 81, 14, 47, 49, 53, 88, 92, 61]))
(5, set([49, 72, 40, 50, 52, 89, 57, 60, 30, 31]))
(6, set([65, 98, 39, 80, 51, 87, 26, 91]))
(7, set([33, 6, 42, 16, 85, 56, 58, 21, 63]))
(8, set([64, 33, 35, 93, 80, 21, 24, 90, 47, 58]))
(9, set([3, 73, 74, 44, 77, 17, 35, 21, 54, 89]))

(0, set([4, 12, 15, 16, 18, 19, 21, 22, 23, 24, 26, 28, 30, 36, 38, 41, 45, 46, 49, 52, 61, 64, 74, 77, 80, 85, 87, 89, 91, 94, 95, 96]))
(1, set([1, 3, 8, 10, 11, 17, 28, 30, 32, 33, 34, 35, 37, 38, 39, 40, 48, 50, 55, 56, 58, 59, 62, 79, 80, 81, 90, 92, 100]))
(2, set([8, 9, 11, 22, 34, 37, 41, 48, 49, 53, 57, 60, 61, 62, 65, 67, 69, 71, 73, 74, 75, 76, 79, 80, 81, 90, 94, 95, 98]))
(3, set([3, 7, 9, 12, 13, 17, 18, 23, 24, 25, 27, 31, 34, 44, 53, 54, 55, 59, 66, 67, 69, 76, 79, 81, 88, 89, 94, 95, 98, 101]))
(4, set([8, 14, 17, 19, 20, 25, 32, 33, 34, 37, 43, 46, 47, 49, 53, 58, 59, 61, 63, 68, 69, 71, 81, 86, 88, 89, 92, 95, 96, 98, 101]))
(5, set([2, 7, 10, 14, 20, 24, 27, 30, 31, 38, 39, 40, 43, 44, 46, 49, 50, 52, 57, 59, 60, 62, 64, 67, 68, 70, 72, 76, 79, 83, 85, 86, 89, 90]))
(6, set([1, 2, 3, 6, 9, 16, 18, 23, 26, 30, 32, 34, 37, 39, 43, 47, 49, 50, 51, 63, 65, 80, 87, 91, 96, 97, 98, 99]))
(7, set([3, 5, 6, 7, 9, 14, 15, 16, 17, 21, 24, 28, 33, 34, 42, 44, 51, 53, 56, 58, 61, 63, 69, 74, 76, 84, 85, 87, 92]))
(8, set([4, 5, 6, 8, 9, 17, 20, 21, 24, 28, 33, 35, 38, 47, 55, 58, 59, 64, 66, 69, 70, 71, 77, 79, 80, 82, 86, 87, 90, 93, 100, 101]))
(9, set([3, 5, 6, 12, 14, 17, 19, 20, 21, 23, 35, 43, 44, 46, 47, 50, 54, 55, 58, 62, 63, 68, 71, 73, 74, 76, 77, 87, 89, 91, 92]))

Unless my eyes are squiffy the 2nd dictionary of sets appears ordered.  I've run it with other numbers > 25 and continue to get ordered sets but anything < 25 results in unordered sets.  A feature or a bug?

Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/e0921e8a/attachment.htm>

From wescpy at gmail.com  Thu Oct 30 23:06:12 2008
From: wescpy at gmail.com (wesley chun)
Date: Thu, 30 Oct 2008 15:06:12 -0700
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
Message-ID: <78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>

based on the all the performance questions, i would say agree that
dictionary access is faster than lists (hashes exist cuz they're fast)
but they use up more memory, as shown in shawn's numbers. also, one of
the reasons why slots was added to classes was because the attribute
dictionary began to impact memory (when creating many instances), so
converting that to __slots__ list of attributes instead made it more
conservative of resources.

thus, i would suggest using sets instead. if the data doesn't change,
then frozensets. a for-loop thru sets would be very fast; and in
Python 3.0, you can use *set comprehensions* too. :-)

shawn, do you have time to run some numbers for sets and frozensets?

anyway, just a suggestion...
-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

"Python Web Development with Django", Addison Wesley, (c) 2008
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

From Shawn at milochik.com  Thu Oct 30 23:54:58 2008
From: Shawn at milochik.com (Shawn Milochik)
Date: Thu, 30 Oct 2008 18:54:58 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>
Message-ID: <2dc0c81b0810301554q2eab6450x467972562aa2c206@mail.gmail.com>

On Thu, Oct 30, 2008 at 6:06 PM, wesley chun <wescpy at gmail.com> wrote:
> based on the all the performance questions, i would say agree that
> dictionary access is faster than lists (hashes exist cuz they're fast)
> but they use up more memory, as shown in shawn's numbers. also, one of
> the reasons why slots was added to classes was because the attribute
> dictionary began to impact memory (when creating many instances), so
> converting that to __slots__ list of attributes instead made it more
> conservative of resources.
>
> thus, i would suggest using sets instead. if the data doesn't change,
> then frozensets. a for-loop thru sets would be very fast; and in
> Python 3.0, you can use *set comprehensions* too. :-)
>
> shawn, do you have time to run some numbers for sets and frozensets?
>
> anyway, just a suggestion...
> -wesley


They seem pretty similar. Here are two tests (code follows). Perhaps I
could have loaded them differently and it would have made more of a
difference. In this case I just made a list and populated the sets
from it.

Results for 9999999 iterations:
	Set:
		Load: 1.24 seconds
		Process: 4.43 seconds

	Frozenset:
		Load: 0.96 seconds
		Process: 4.09 seconds

Comparison:
	Set loads 1.30 times the speed of a frozenset.
	Set processes loads 1.08 times the speed of a frozenset.





Results for 9999999 iterations:
	Set:
		Load from list: 0.89 seconds
		Process: 3.72 seconds

	Frozenset:
		Load from list: 0.94 seconds
		Process: 4.67 seconds

Comparison:
	Set loads 0.94 times the speed of a frozenset.
	Set processes loads 0.80 times the speed of a frozenset.


Results for 7654321 iterations:
	Set:
		Load from list: 0.81 seconds
		Process: 2.52 seconds

	Frozenset:
		Load from list: 0.76 seconds
		Process: 2.52 seconds

Comparison:
	Set loads 1.07 times the speed of a frozenset.
	Set processes loads 1.00 times the speed of a frozenset.






#!/usr/bin/env python


import time

the_list = []

iter_num = 7654321


fill_list_time = time.time()

for x in range(iter_num):
    the_list.append(x)

fill_list_time = time.time() - fill_list_time

fill_frozenset_time = time.time()
the_frozenset = frozenset(the_list)
fill_frozenset_time = time.time() - fill_frozenset_time


fill_set_time = time.time()
the_set = set(the_list)
fill_set_time = time.time() - fill_set_time



proc_set_time = time.time()

for thing in the_set:

    thing = thing * 2

proc_set_time = time.time() - proc_set_time


proc_frozenset_time = time.time()

for thing in the_frozenset:

    thing = thing * 2

proc_frozenset_time = time.time() - proc_frozenset_time


print "Results for %d iterations:" % iter_num
print "\tSet:"
print "\t\tLoad from list: %.2f seconds" % fill_set_time
print "\t\tProcess: %.2f seconds" % proc_set_time
print
print "\tFrozenset:"
print "\t\tLoad from list: %.2f seconds" % fill_frozenset_time
print "\t\tProcess: %.2f seconds" % proc_frozenset_time
print
print "Comparison: "
print "\tSet loads %.2f times the speed of a frozenset." %
(fill_set_time / fill_frozenset_time)
print "\tSet processes loads %.2f times the speed of a frozenset." %
(proc_set_time / proc_frozenset_time)

From Larry at riedel.org  Fri Oct 31 00:30:16 2008
From: Larry at riedel.org (Larry Riedel)
Date: Thu, 30 Oct 2008 16:30:16 -0700
Subject: [Tutor] unordered and ordered defaultdict(set)
In-Reply-To: <COL103-DS246E03867DDF07DFB70561A3210@phx.gbl>
References: <COL103-DS246E03867DDF07DFB70561A3210@phx.gbl>
Message-ID: <7c64c2920810301630t231ede38xf4610ab7c43ebac1@mail.gmail.com>

> Unless my eyes are squiffy the 2nd dictionary of sets
> appears ordered.  I've run it with other numbers > 25
> and continue to get ordered sets but anything < 25
> results in unordered sets.  A feature or a bug?

No, not a feature or a bug... it would be a bug to assume
the elements will be in order, or to assume the elements
will not be in order.  It is a happenstance if they are.
Maybe for that implementation of the Python runtime that
happenstance is consistent, but on another it may not be.

My guess (totally a guess) would be for small sets it is
expected to be faster to use an array with a linear search
than a tree with fewer operations per search, so the
implementation starts with an array until the set gets
big enough to justify using a tree, then it switches over.


Larry

From dineshbvadhia at hotmail.com  Fri Oct 31 00:40:36 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Thu, 30 Oct 2008 16:40:36 -0700
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>
Message-ID: <COL103-DS1E13434DF07784012A88AA3210@phx.gbl>

Thanks Wesley

I use both dictionaries (especially defaultdict) and sets all the time but for this particular problem I need the dictionary or set (preferably) to be ordered ie. the set contains integers, which don't change, but they have to be ordered - low to high - when read back with a for-loop.

Btw, cannot move to Python 2.6 or 3.0 until Numpy/Scipy catches up.

Dinesh



From: wesley chun 
Sent: Thursday, October 30, 2008 3:06 PM
To: Dinesh B Vadhia 
Cc: tutor at python.org 
Subject: Re: [Tutor] fast list traversal


based on the all the performance questions, i would say agree that
dictionary access is faster than lists (hashes exist cuz they're fast)
but they use up more memory, as shown in shawn's numbers. also, one of
the reasons why slots was added to classes was because the attribute
dictionary began to impact memory (when creating many instances), so
converting that to __slots__ list of attributes instead made it more
conservative of resources.

thus, i would suggest using sets instead. if the data doesn't change,
then frozensets. a for-loop thru sets would be very fast; and in
Python 3.0, you can use *set comprehensions* too. :-)

shawn, do you have time to run some numbers for sets and frozensets?

anyway, just a suggestion...
-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

"Python Web Development with Django", Addison Wesley, (c) 2008
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/9402292b/attachment.htm>

From wescpy at gmail.com  Fri Oct 31 00:55:08 2008
From: wescpy at gmail.com (wesley chun)
Date: Thu, 30 Oct 2008 16:55:08 -0700
Subject: [Tutor] fast list traversal
In-Reply-To: <2dc0c81b0810301554q2eab6450x467972562aa2c206@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<78b3a9580810301506v1f93491fr9cf2582bf77aae96@mail.gmail.com>
	<2dc0c81b0810301554q2eab6450x467972562aa2c206@mail.gmail.com>
Message-ID: <78b3a9580810301655h2983fb69pe9302d00a457ffa6@mail.gmail.com>

> They seem pretty similar. Here are two tests (code follows). Perhaps I
> could have loaded them differently and it would have made more of a
> difference. In this case I just made a list and populated the sets
> from it.
>
> Results for 9999999 iterations:
>        Set:
>                Load: 1.24 seconds
>                Process: 4.43 seconds
>
>        Frozenset:
>                Load: 0.96 seconds
>                Process: 4.09 seconds
>
> Comparison:
>        Set loads 1.30 times the speed of a frozenset.
>        Set processes loads 1.08 times the speed of a frozenset.


wow, is it me, or do both set types seem to have *significantly*
faster load times... process times seems to be in the middle. very
ineresting... thx for running it through!

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

"Python Web Development with Django", Addison Wesley, (c) 2008
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

From eike.welk at gmx.net  Fri Oct 31 00:31:37 2008
From: eike.welk at gmx.net (Eike Welk)
Date: Fri, 31 Oct 2008 00:31:37 +0100
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS18A945128B3F288CD72383A3210@phx.gbl>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
	<COL103-DS18A945128B3F288CD72383A3210@phx.gbl>
Message-ID: <200810310031.37753.eike.welk@gmx.net>

Hello Dinesh!

On Thursday 30 October 2008, Dinesh B Vadhia wrote:
> Bob:  Nothing special is being done on the elements of the list -
> additions/subtractions/ - and storing the results in an array.
> That's it.

You could convert the list into a numpy array first, and you could try 
to express the algorithm with operations that act on the array as a 
whole. 

If this is possible I'd expect a big speedup. 

Kind regards,
Eike.

From dwbarne at earthlink.net  Fri Oct 31 02:03:30 2008
From: dwbarne at earthlink.net (dwbarne at earthlink.net)
Date: Thu, 30 Oct 2008 21:03:30 -0400 (EDT)
Subject: [Tutor] remap tab key to 4 spaces in a Tkinter text box
Message-ID: <7520273.1225415011097.JavaMail.root@elwamui-mouette.atl.sa.earthlink.net>

Hi tutors.

Is there a way to remap a tab key to enter a user-specified number of spaces in a Tkinter text widget instead of a genuine tab? An internet search has turned up zilch. The tab option in a text widget lets you enter the number of centimeters to space over, but this option is truly useless when you want real live spaces instead.

I tried using 'bind' to call a method that inserts 4 spaces, for example, but this approach enters the number of spaces AND a tab as well (as expected, after thinking about it). Not good.

Any ideas?

From john at fouhy.net  Fri Oct 31 02:31:33 2008
From: john at fouhy.net (John Fouhy)
Date: Fri, 31 Oct 2008 14:31:33 +1300
Subject: [Tutor] remap tab key to 4 spaces in a Tkinter text box
In-Reply-To: <7520273.1225415011097.JavaMail.root@elwamui-mouette.atl.sa.earthlink.net>
References: <7520273.1225415011097.JavaMail.root@elwamui-mouette.atl.sa.earthlink.net>
Message-ID: <5e58f2e40810301831j259f30fcsa7f6158bad0d3e4d@mail.gmail.com>

2008/10/31  <dwbarne at earthlink.net>:
> Hi tutors.
>
> Is there a way to remap a tab key to enter a user-specified number of spaces in a Tkinter text widget instead of a genuine tab? An internet search has turned up zilch. The tab option in a text widget lets you enter the number of centimeters to space over, but this option is truly useless when you want real live spaces instead.
>
> I tried using 'bind' to call a method that inserts 4 spaces, for example, but this approach enters the number of spaces AND a tab as well (as expected, after thinking about it). Not good.

My Tkinter is a bit rusty, but the latter approach might be the one to
take.  Just remember to return 'break' at the end of your callback.
This prevents the event from being passed on to the text widget.

-- 
John.

From btkuhn at email.unc.edu  Fri Oct 31 02:41:50 2008
From: btkuhn at email.unc.edu (btkuhn at email.unc.edu)
Date: Thu, 30 Oct 2008 21:41:50 -0400
Subject: [Tutor] Setting up server for CGI
Message-ID: <20081030214150.gzgasxe28s8gcwko@webmail4.isis.unc.edu>


Hi everyone,

I am new to programming and have been programming with Python for
about 2.5 months. After learning the basics of the language I am
trying to teach myself CGI with Python. I've
come across a few resources that teach CGI, but I am having much
trouble setting up a
server to view CGI scripts on my browser (Note: some of terminology
may be wrong). I am running Windows XP with a Firefox browser.

Here is what I've tried so far:

I followed the instructions on a tutorial and created a "C:\cgihome"
server, and then
created the following file:

C:\cgihome\server\cgihttpserver.py

It contains the following code:
[CODE]
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["/cgi"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
[/CODE]

This is supposed to set up a basic server on my system. When I run
from the command line,
it seems to be working and displays the message "Serving at Port
8000".

According to the tutorial I should then be able to run CGI scripts by
saving them in
C:/cgihome/cgi , and then opening in the browser (after running the
server script on the
command line). So for instance I wrote this script:
[CODE]
#!c:\Python25\python.exe

print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
[/CODE]
and saved it as C:\cgihome\cgi\cgitest.py . When I try opening it in
my browser, though,
I just get 404 error: "File not found". This shows up both in the
browser window and the
command prompt window. When I try using a plain .html file saved in
C:\cgihome instead, I
get the same error. I can't get anything to run. I'm sure I'm doing
something wrong, but
I don't know what. I have also tried downloading the Apache server as
well, but it is 10
times more complex than my simple server script, and geared towards
Linux users who know what they are doing.

Can someone please explain to me like I'm a child how to set up a
basic web server that I
can run CGI scripts on?

Thanks very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/706e2610/attachment-0001.htm>

From kent37 at tds.net  Fri Oct 31 03:19:52 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 30 Oct 2008 22:19:52 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <2dc0c81b0810301355r75d95c4ew8b0bfcbc9c7715ec@mail.gmail.com>
References: <COL103-DS21FE7CC6248170C778FD76A3210@phx.gbl>
	<4909FF91.5060307@gmail.com>
	<2dc0c81b0810301146o13fd83e6u91424abb4675bf48@mail.gmail.com>
	<1c2a2c590810301305x207f730awbb483964e58365ad@mail.gmail.com>
	<2dc0c81b0810301355r75d95c4ew8b0bfcbc9c7715ec@mail.gmail.com>
Message-ID: <1c2a2c590810301919u5078fc89od2dc182534b28215@mail.gmail.com>

On Thu, Oct 30, 2008 at 4:55 PM, Shawn Milochik <Shawn at milochik.com> wrote:

> I just ran a very crude test.
>
> Results: Lists load more quickly but iterate more slowly. Dictionaries
> take longer to load but iteration takes about half the time.


Here are my results using timeit and Python 2.6:

Initializing a list is faster than a dict:
kent $ py -m timeit -n 1 -r 3 -s "l=[]" "for i in range(7654321):
l.append(i)"
1 loops, best of 3: 1.77 sec per loop

kent $ py -m timeit -n 1 -r 3 -s "d={}" "for i in range(7654321): d[i] = 0"
1 loops, best of 3: 2.27 sec per loop

The list version can be sped up considerably by hoisting the lookup of the
append method out of the loop:
kent $ py -m timeit -n 1 -r 3 -s "l=[];append=l.append" "for i in
range(7654321): append(i)"
1 loops, best of 3: 1.02 sec per loop

However this is not the fastest way to create either the list or the dict
from a range:
kent $ py -m timeit -n 1 -r 3  "l = range(7654321)"
1 loops, best of 3: 167 msec per loop

kent $ py -m timeit -n 1 -r 3  "d=dict.fromkeys(range(7654321), 0)"
1 loops, best of 3: 1.63 sec per loop

xrange() is a little faster for the dict:
kent $ py -m timeit -n 1 -r 3  "d=dict.fromkeys(xrange(7654321), 0)"
1 loops, best of 3: 1.43 sec per loop

That is why I asked the OP for some real code; you have to optimize for a
specific case, not a generality.

For iteration, I get nearly identical results for the list and dict:
kent $ py -m timeit -n 1 -r 3  -s "l = range(7654321)" "for i in l: i*i"
1 loops, best of 3: 2.74 sec per loop

kent $ py -m timeit -n 1 -r 3  -s "d = dict.fromkeys(range(7654321), 0)"
"for i in d: i*i"
1 loops, best of 3: 2.81 sec per loop

Using a list comprehension is slower, which surprised me; probably because
it has to actually create the list:

kent $ py -m timeit -n 1 -r 3  -s "l = range(7654321)" "[i*i for i in l]"
1 loops, best of 3: 3.65 sec per loop

kent $ py -m timeit -n 1 -r 3  -s "d = dict.fromkeys(range(7654321), 0)"
"[i*i for i in d]"
1 loops, best of 3: 3.66 sec per loop

The moral of the story, as usual with optimization, is that you have to time
and you have to use real code to get meaningful results.

fill_dict_time = time.time()
>
> for x in range(iter_num):
>    the_list.append(x)


Not sure why you have the list append in this loop?


>    the_dict[x] = 0
>
> fill_dict_time = time.time() - fill_dict_time


the_list now has twice as many entries as the_dict, which would account for
it taking twice as long to iterate. Which is another pitfall of timing
tests; it is remarkably easy to make a mistake and time something different
than what you think you are timing.

Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/5c6de155/attachment.htm>

From kent37 at tds.net  Fri Oct 31 03:29:13 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 30 Oct 2008 22:29:13 -0400
Subject: [Tutor] Setting up server for CGI
In-Reply-To: <20081030214150.gzgasxe28s8gcwko@webmail4.isis.unc.edu>
References: <20081030214150.gzgasxe28s8gcwko@webmail4.isis.unc.edu>
Message-ID: <1c2a2c590810301929l3204924ay435a4549fafe4a3d@mail.gmail.com>

On Thu, Oct 30, 2008 at 9:41 PM, <btkuhn at email.unc.edu> wrote:
>
> I followed the instructions on a tutorial and created a "C:\cgihome" server, and then
> created the following file:
>
> C:\cgihome\server\cgihttpserver.py
>
> It contains the following code:
> [CODE]
> import CGIHTTPServer
> import BaseHTTPServer
> class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
>    cgi_directories = ["/cgi"]
> PORT = 8000
> httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
> print "serving at port", PORT
> httpd.serve_forever()
> [/CODE]
>
> This is supposed to set up a basic server on my system. When I run from the command line,
> it seems to be working and displays the message "Serving at Port 8000".

What directory do you run from? It should be the cgihome directory.

Alternately, rename your /cgi directory to /cgi-bin and from the
command line in the cgihome directory, run

python -m CGIHTTPServer

We had a very recent thread about this that might help; see the various
"please help with simple python CGI script" posts here:
http://mail.python.org/pipermail/tutor/2008-October/thread.html

Kent

From peter.anderson at internode.on.net  Fri Oct 31 04:03:41 2008
From: peter.anderson at internode.on.net (Peter Anderson)
Date: Fri, 31 Oct 2008 14:03:41 +1100
Subject: [Tutor] Problem formatting raw_input
Message-ID: <490A758D.2080103@internode.on.net>

Hi!

I am teaching myself Python using John Zelle's excellent book Python 
Programming (ISBN: 1-887902-99-6). At the end of Chapter 4 - Computing 
with Strings is an exercise to convert an existing program to use a list 
to decode ASCII number input. My solution is shown below.

My problem is with the actual entry of the ASCII codes. My solution has 
a "if" test to remove the leading "0" from an input of say "033". With 
this test the output of the decode is correct in printing "!". Without 
the "if" test the output is "\x1b" at best or a run-time error for other 
numbers.

My question is this: is there a better way to convert raw input of say 
"033" to "33" than what I have used? Thanks in advance for any help.

My source code
---------------

import string

def main():
print "This script converts a sequence of ASCII numbers"
print "into the string of text that it represents."
print
data = getNumbers()
print data

def getNumbers():
# Setup an empty list
inString = []

# Get the numbers to decode
inNum = raw_input("Please enter an ASCII number\n(33 - 126, [Enter] to 
quit): ")
while inNum != "":
# strip leading '0's from ASCII numbers
if inNum[0] == "0":
inNum = inNum[1] + inNum[2]
inStr = chr(eval(inNum))
inString.append(inStr) # append the input to the list
inNum = raw_input("Please enter an ASCII number\n(33 - 126, [Enter] to 
quit): ")
return inString

if __name__ == '__main__':
main()


-- 
*Peter Anderson*
There is nothing more difficult to take in hand, more perilous to 
conduct, or more uncertain in its success, than to take the lead in the 
introduction of a new order of things?Niccolo Machiavelli, /The Prince/, 
ch. 6

From btkuhn at email.unc.edu  Fri Oct 31 04:18:20 2008
From: btkuhn at email.unc.edu (btkuhn at email.unc.edu)
Date: Thu, 30 Oct 2008 23:18:20 -0400
Subject: [Tutor] Setting up server for CGI
In-Reply-To: <1c2a2c590810301929l3204924ay435a4549fafe4a3d@mail.gmail.com>
References: <20081030214150.gzgasxe28s8gcwko@webmail4.isis.unc.edu>
	<1c2a2c590810301929l3204924ay435a4549fafe4a3d@mail.gmail.com>
Message-ID: <20081030231820.x3ed9dtnkkwcwwss@webmail4.isis.unc.edu>

I'm not sure what you mean, "What directory do you run from?". I have 
the file saved as C:\cgihome\cgi\cgitest.py and I try running it by 
typing the following in the URL field: 
http://localhost:8000/cgi/cgitest.py . I tried changing the folder name 
to cgi-bin and get the same error. It says, "Nothing matches the given 
URI", even though the file is saved in the directory specified.

The Python program itself is saved in C:/Python25 but I don't think 
this makes a difference, especially since I can't run regular html 
files with my server.

Thanks again.

Quoting Kent Johnson <kent37 at tds.net>:

> On Thu, Oct 30, 2008 at 9:41 PM, <btkuhn at email.unc.edu> wrote:
>>
>> I followed the instructions on a tutorial and created a "C:\cgihome" 
>> server, and then
>> created the following file:
>>
>> C:\cgihome\server\cgihttpserver.py
>>
>> It contains the following code:
>> [CODE]
>> import CGIHTTPServer
>> import BaseHTTPServer
>> class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
>>    cgi_directories = ["/cgi"]
>> PORT = 8000
>> httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
>> print "serving at port", PORT
>> httpd.serve_forever()
>> [/CODE]
>>
>> This is supposed to set up a basic server on my system. When I run 
>> from the command line,
>> it seems to be working and displays the message "Serving at Port 8000".
>
> What directory do you run from? It should be the cgihome directory.
>
> Alternately, rename your /cgi directory to /cgi-bin and from the
> command line in the cgihome directory, run
>
> python -m CGIHTTPServer
>
> We had a very recent thread about this that might help; see the various
> "please help with simple python CGI script" posts here:
> http://mail.python.org/pipermail/tutor/2008-October/thread.html
>
> Kent
>



From peter.anderson at internode.on.net  Fri Oct 31 06:24:00 2008
From: peter.anderson at internode.on.net (Peter Anderson)
Date: Fri, 31 Oct 2008 16:24:00 +1100
Subject: [Tutor] Problem formatting raw_input
In-Reply-To: <e9764b730810302041g68853274i5f834081ecbbcfe@mail.gmail.com>
References: <490A758D.2080103@internode.on.net>
	<e9764b730810302041g68853274i5f834081ecbbcfe@mail.gmail.com>
Message-ID: <490A9670.1000400@internode.on.net>

Dj Gilcrease wrote:
> The simple answer is to just use chr(int(inNum))
>
> though here is how I would do it
>
> def convert_string_to_int(strInt):
>     try:
>         return int(strInt)
>     except ValueError:
>         return 0
>
> def getNumbers(output):
>     inNum = raw_input("Please enter an ASCII number\n(33 - 126,
> [Enter] to quit): ")
>     ascii_num = convert_string_to_int(inNum)
>     if ascii_num >= 33 and ascii_num <=126:
>         output.append(chr(ascii_num))
>         getNumbers(output)
>
> if __name__ == '__main__':
>     print "This script converts a sequence of ASCII numbers"
>     print "into the string of text that it represents."
>     print
>     output = []
>     getNumbers(output)
>     print output
>
> Dj Gilcrease
> OpenRPG Developer
> ~~http://www.openrpg.com
Dj,

Thanks for the suggestions; both work perfectly.  Can I ask a 
supplementary question please?

In the def convert_string... function why do you include the "except 
ValueError: / return 0" clause?

Regards,
Peter
-- 
*Peter Anderson*
There is nothing more difficult to take in hand, more perilous to 
conduct, or more uncertain in its success, than to take the lead in the 
introduction of a new order of things?Niccolo Machiavelli, /The Prince/, 
ch. 6

From kent37 at tds.net  Fri Oct 31 11:31:57 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 31 Oct 2008 06:31:57 -0400
Subject: [Tutor] Setting up server for CGI
In-Reply-To: <20081030231820.x3ed9dtnkkwcwwss@webmail4.isis.unc.edu>
References: <20081030214150.gzgasxe28s8gcwko@webmail4.isis.unc.edu>
	<1c2a2c590810301929l3204924ay435a4549fafe4a3d@mail.gmail.com>
	<20081030231820.x3ed9dtnkkwcwwss@webmail4.isis.unc.edu>
Message-ID: <1c2a2c590810310331h5fed78a3ld022a58daef3cf71@mail.gmail.com>

On Thu, Oct 30, 2008 at 11:18 PM, <btkuhn at email.unc.edu> wrote:

> I'm not sure what you mean, "What directory do you run from?".


I mean, what is the working directory when you run your cgihttpserver.py
program. You should be in the parent directory of the cgi directory so the
server can find the cgi files. So, given the paths you originally specified,
at the command prompt try these two commands:

cd C:\cgihome
python server\cgihttpserver.py

Then browse to http://localhost:8000/cgi/cgitest.py

Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/8023b72a/attachment-0001.htm>

From kent37 at tds.net  Fri Oct 31 11:55:07 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 31 Oct 2008 06:55:07 -0400
Subject: [Tutor] Problem formatting raw_input
In-Reply-To: <490A758D.2080103@internode.on.net>
References: <490A758D.2080103@internode.on.net>
Message-ID: <1c2a2c590810310355j176bd6e8j35a3421b3bec9849@mail.gmail.com>

On Thu, Oct 30, 2008 at 11:03 PM, Peter Anderson <
peter.anderson at internode.on.net> wrote:

> My problem is with the actual entry of the ASCII codes. My solution has a
> "if" test to remove the leading "0" from an input of say "033". With this
> test the output of the decode is correct in printing "!". Without the "if"
> test the output is "\x1b" at best or a run-time error for other numbers.


That is because the leading 0 marks the number as octal when eval()
interprets it as a number.


> My question is this: is there a better way to convert raw input of say
> "033" to "33" than what I have used? Thanks in advance for any help.


Dj's use of int() is the best way to do this. For future reference, the easy
way to strip leading 0's from a string is with lstrip():

In [5]: '033'.lstrip('0')
Out[5]: '33'

Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/0f5c1dc9/attachment.htm>

From denis.spir at free.fr  Fri Oct 31 12:58:54 2008
From: denis.spir at free.fr (spir)
Date: Fri, 31 Oct 2008 12:58:54 +0100
Subject: [Tutor] python editor / IDE
Message-ID: <490AF2FE.5060907@free.fr>

Hello,

I have read tons of reviews of editors for python. But they seem to be 
all biased, meaning that what the author finds important is well 
documented while the rest not at all.
I'm looking for  something like a simple table showing main features for 
all editors or IDEs. Do you know of anything like that? If not, maybe 
you could point me to editors that meet the following requirements:

Fondamental features:
* Written in python (because I plan to tweak inside for some specific 
needs).
* Use of wxPython for UI (ditto -- I find wx clearer than tk or QT).
* /Really/ work well with non-ascii systems, including edition of utf-8 
files (most don't in real life use, even when they pretend to).
* Customizable syntax highlighting.
* Customizable key bindings.
* Running of python code from inside the IDE.
* Code browser at least for currently edited file.
* Multiple file opening through tabs.
* Basic editing: search/replace, (un)comment, un(indent),...

Nice additional features:
* Additional editing features: tooltips, code expansion, regexps (maybe 
one day I will learn that ;-)),...
* Project level management/browsing.
* GUI building (like boa, but boa constantly crashes with non-ascii -- 
even with unicode version of wxPython installed).

I currently use DrPython which is very well designed for most of this, 
but its lack of code browsing is a pain as soon as a project starts 
scaling. And some of its behaviour is a bit weird for me in some fields 
(such as edition actions on folded or half-folded block).
Notepad++ is my favorite editor for everything except coding in python. 
I would love to use it, but as far as I know, it lacks integration of a 
python interpretor.

Thanks,
Denis


From dineshbvadhia at hotmail.com  Fri Oct 31 13:34:40 2008
From: dineshbvadhia at hotmail.com (Dinesh B Vadhia)
Date: Fri, 31 Oct 2008 05:34:40 -0700
Subject: [Tutor] fast list traversal
Message-ID: <COL103-DS141D724F7A5CF87591229DA3200@phx.gbl>

Hi Kent

The code is very simple:

dict_long_lists = defaultdict(list)
for long_list in dict_long_lists.itervalues()
        for element in long_list:
                array_a[element] = m + n + p        # m,n,p are numbers

The long_list's are read from a defaultdict(list) dictionary and so don't need initializing.  The elements of long_list are integers and ordered (sorted before placing in dictionary).  There are > 20,000 long_list's each with a variable number of elements (>5,000).  The elements of long_list are immutable (ie. don't change).

I've tried set() using defaultdict(set) but the elements are not ordered.

The problem is what is the fastest way to traverse long_list sequentially from the beginning to the end?  Maybe there is another data structure that can be used instead of a list.

Hth

Dinesh


--------------------------------------------------------------------------------

Message: 1
Date: Thu, 30 Oct 2008 22:19:52 -0400
From: "Kent Johnson" <kent37 at tds.net>
Subject: Re: [Tutor] fast list traversal
To: "Shawn Milochik" <Shawn at milochik.com>
Cc: tutor at python.org
Message-ID:
<1c2a2c590810301919u5078fc89od2dc182534b28215 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Thu, Oct 30, 2008 at 4:55 PM, Shawn Milochik <Shawn at milochik.com> wrote:

> I just ran a very crude test.
>
> Results: Lists load more quickly but iterate more slowly. Dictionaries
> take longer to load but iteration takes about half the time.


Here are my results using timeit and Python 2.6:

Initializing a list is faster than a dict:
kent $ py -m timeit -n 1 -r 3 -s "l=[]" "for i in range(7654321):
l.append(i)"
1 loops, best of 3: 1.77 sec per loop

kent $ py -m timeit -n 1 -r 3 -s "d={}" "for i in range(7654321): d[i] = 0"
1 loops, best of 3: 2.27 sec per loop

The list version can be sped up considerably by hoisting the lookup of the
append method out of the loop:
kent $ py -m timeit -n 1 -r 3 -s "l=[];append=l.append" "for i in
range(7654321): append(i)"
1 loops, best of 3: 1.02 sec per loop

However this is not the fastest way to create either the list or the dict
from a range:
kent $ py -m timeit -n 1 -r 3  "l = range(7654321)"
1 loops, best of 3: 167 msec per loop

kent $ py -m timeit -n 1 -r 3  "d=dict.fromkeys(range(7654321), 0)"
1 loops, best of 3: 1.63 sec per loop

xrange() is a little faster for the dict:
kent $ py -m timeit -n 1 -r 3  "d=dict.fromkeys(xrange(7654321), 0)"
1 loops, best of 3: 1.43 sec per loop

That is why I asked the OP for some real code; you have to optimize for a
specific case, not a generality.

For iteration, I get nearly identical results for the list and dict:
kent $ py -m timeit -n 1 -r 3  -s "l = range(7654321)" "for i in l: i*i"
1 loops, best of 3: 2.74 sec per loop

kent $ py -m timeit -n 1 -r 3  -s "d = dict.fromkeys(range(7654321), 0)"
"for i in d: i*i"
1 loops, best of 3: 2.81 sec per loop

Using a list comprehension is slower, which surprised me; probably because
it has to actually create the list:

kent $ py -m timeit -n 1 -r 3  -s "l = range(7654321)" "[i*i for i in l]"
1 loops, best of 3: 3.65 sec per loop

kent $ py -m timeit -n 1 -r 3  -s "d = dict.fromkeys(range(7654321), 0)"
"[i*i for i in d]"
1 loops, best of 3: 3.66 sec per loop

The moral of the story, as usual with optimization, is that you have to time
and you have to use real code to get meaningful results.

fill_dict_time = time.time()
>
> for x in range(iter_num):
>    the_list.append(x)


Not sure why you have the list append in this loop?


>    the_dict[x] = 0
>
> fill_dict_time = time.time() - fill_dict_time


the_list now has twice as many entries as the_dict, which would account for
it taking twice as long to iterate. Which is another pitfall of timing
tests; it is remarkably easy to make a mistake and time something different
than what you think you are timing.

Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/5c6de155/attachment-0001.htm>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/c1605e7f/attachment.htm>

From a.t.hofkamp at tue.nl  Fri Oct 31 13:56:57 2008
From: a.t.hofkamp at tue.nl (A.T.Hofkamp)
Date: Fri, 31 Oct 2008 13:56:57 +0100
Subject: [Tutor] [Re:  class/type methods/functions]
In-Reply-To: <490A13E4.5000206@free.fr>
References: <490A13E4.5000206@free.fr>
Message-ID: <490B0099.90803@tue.nl>

spir wrote:
>> After reading your mail, I cannot help wondering that something 
> crucial seems to be missing in your class structure. (I get the 
> impression that you are trying to squeeze object information and object 
> meta information together in one class definition.)
>>
> Yes. This is a consequence of type & instance beeing defined in the same 
> class() code section. If I unserstand well, what you call 
> meta_information is for me simply type attributes. They will be 
> available to any object of this type. Is this a misuse of types/classes? 

Not necessarily, it kind of depends on how you look at the problem. In 
programming there are usually many good solutions.

However, by moving the 'type' information to a seperate object, your classes 
become less cluttered, and the problem (and thus the solution) becomes easier 
to understand/program.


[I have moved this piece of discussion up, since I think it is the core of the 
structuring gap I experince.]
 >> Have you considered using the factory pattern? (ie make an object
 > that represents the type, and another one for the data) In that way you
 > can nicely seperate both kinds of information.
 >>
 > Definitely! That is the pattern I'm using -- or trying. I didn't know it
 > has a name.  Now, isn't this factory<->object pattern precisely what the
 > type<->instance relationship is supposed to be?

No.

The factory pattern is best explained by considering a real factory where you 
make products.
You have a Factory class + factory object (usually 1) that represents the real 
factory, and you have a Product class + many prduct objects for the products 
it makes.

Each product object has properties and functions (ie its color and how you can 
use it).
Meta information, like what kind of products exist and how to make/transform 
them however is *not* part of the product object but belongs in the factory 
object.
(Look at real life, you can use a car to get from A to B and back, but a car 
cannot tell you what kinds of other cars exist, or how to install eg a radio.)

In your application, that would mean that the things you call 'instance' above 
are part of eg the 'format' object, and things you name 'type' above, are part 
of the 'formatfactory' (or 'formattype') object.

The difference between your approach and the factory pattern imho is that the 
'type' information of an object is not stored in its class, but in another 
object (of class Factory).


> Unfortunately, I can't paste right now a full & real snippet of the, as 
> it is beeing refactored: it would rather be confusing. Here is a kind of 
> outline of a typical symbol type:

oke.
I used this example mainly to understand better what you are trying to do.
I wrote some comments about things I noticed and observations I made.


> class Format(Symbol):
>   ''' block formats symbol '''
>   # import relevant config data for this symbol type
>   from_codes = config.formats.from_codes
>   to_codes = config.formats.to_codes
>   names = config.formats.names
>   # open_format to be checked with closing tag (xhtml only)
>   open_format = None
>   def __init__(self, source, mark, section_level, posV, posH, close = 
> False,
>                   list_type = None, list_level=0):
>       # posV & posH ~ line & element numbers for error output
>       # 'mark' can be a wiki code or an xhfml tag
>       self.section_level = section_level        # = current title level
>       self.indent = section_level * TAB         # for nicer xhtml output

As a side-note:
self.indent can be computed from self.section_level. In general, it is better 
in such cases not to store the computable attribute, but instead to compute 
whenever you need it.
This strategy prevents that you get inconsistencies in your data (ie suppose 
that self.section_level == 1 and self.indent == TAB + TAB at some point in the 
program, which of both is then the true value?)

>       self.close = close                        # for automatic closing 
> (wiki only)
>       self.list_level = list_level              # nesting level
>       self.list_type = list_type                # bullet or number
>       self.error = False                        # flag used for no output

As a side-note:
you may want to consider using doc strings for documenting your class and 
instance variables, see eg pydoc or epydoc.


A variable like "section_level" leads me to believe that Format class is a 
part of a page.



>       # read & record symbol data
>       if source == WIKI:
>           self.from_wiki(mark, posV, posH)
>           return
>       if source == XHTML:
>           self.from_xhtml(mark, posV, posH)

This looks like a (factory!) class hierarchy you currently don't have. In OOP 
I would expect something like

self.load(...)    # 'self.from()' is not possible, since 'from' is a reserved 
word in Python

and the underlying object type of 'self' would decide the conversion you 
actually perform.

> So, as you can see, symbols of the Format type will use data held by 
> their type. This seems rather an obvious and consistent practice to me. 
> Namely, the from_codes, to_codes and names type attributes are available 
> to future Format instances. these attributes were imported from an 
> config module/object built at startup (from a config file).

In the factory pattern, you'd have a formattype object (of class FormatType) 
that holds the global (config?) information, and each Format object may hold a 
reference to formattype (if you want).


> Now, imagine it was a wiki text instead, and the user wishes to output 
> it into a wiki language different of the one it was originally coded in. 
> At some time between the reading & writing will the config been rebuilt 
> and, as a consequence, data held by Symbol types. As this is an action 
> of the type, I wish it to be performed by the type. So:

That's one option. Another option may be to make the page object 
language-agnostic (ie you have a 'list', a 'picture' and many more page 
elements, but not attached to a specific language.)

Also, you have a number of language objects that know how to convert the page 
to their language.
A few class definitions to make it a bit clearer (hopefully):


class Language(object):
     """
     Base class containing symbols/tags of any language used in your 
application. It also states what operations you can do, and has common code.
     """
     def __init__(self):
         # Setup common attributes (valid for all languages)

     def load_page(self, ....):
         """ Load a page """
         raise NotImplementedError("Implement me in a derived class")

Language class is not really needed, but very nice to make clear what 
operations you can do with it.



class WikiLanguage(Language):
     """
     Properties and symbols/tags that exist in the wiki language
     """
     def __init__(self):
         Language.__init__()
         self.list_tag = '*'

     def load_page(self, ....):
         # load page in wiki format, and return a Page object

class XHtmlLanguage(Language):
     """
     Properties and symbols/tags that exist in the xhtml language
     """
     def __init__(self):
         Language.__init__()
         self.list_tag = 'li'

     def load_page(self, ....):
         # load page in xhtml format, and return a Page object

For each language class that you have, you make a object (probably 1 for each 
language that you have). It describes what the language contains and how it 
performs its functions.
A Language object also knows how to load/save a page in its language, how to 
render it, etc.


Actual pages are stored in a Page object, I am not sure how this relates to 
your Format object.
(I don't understand the meaning of the name)


class Page(object):
     """
     A page of text
     """
     def __init__(self, lang):
	self.symbols = [] # Contents of the page, list or tree of Element's




class Element(object):
     """
     A concept that exists at a page (list, text, paragraph, picture, etc)
     """

class ListElement(Element):
     ....

class TextElement(Element):
     .....

A page is simply a tree or a list of Elements. Since a page here is 
language-agnostic, it doesn't even need to know its language.
(don't know whether this would work for you).


Hope it makes some sense,
Albert


From srilyk at gmail.com  Fri Oct 31 14:04:30 2008
From: srilyk at gmail.com (W W)
Date: Fri, 31 Oct 2008 08:04:30 -0500
Subject: [Tutor] python editor / IDE
In-Reply-To: <490AF2FE.5060907@free.fr>
References: <490AF2FE.5060907@free.fr>
Message-ID: <333efb450810310604p4be0cc20w2a998a0cf80ef014@mail.gmail.com>

Denis,
You'll find that most editing is subjective - people use what they're
comfortable with.

My recommendation to you, since you love notepad++ and are obviously
comfortable with it; set it as your default editor and install IPython, then
use the %ed magic function to work on your code; or have two windows open;
Notepad++ on one side, IPython on the other, and use the %run magic function
to execute your code.

This is similar to what I do with vi, only if I want to execute (since I
work on *nix) I simply type :!python myfile.py

With IPython, you can use cd just like you would at the command line (and if
you install readlines you can use tab for autocomplete), pwd tells you the
current directory:



In [9]: pwd
Out[9]: 'C:\\Documents and Settings\\Wayne\\Desktop'

In [10]: ls
 Volume in drive C has no label.
 Volume Serial Number is 6082-062C

 Directory of C:\Documents and Settings\Wayne\Desktop
<snip>
10/31/2008  07:57 AM                52 mytest.py
<snip>

In [11]: %run mytest.py
Hello world!
IPython is a nifty tool!

So, to sum it up - if you want to integrate notepad++ with a python
interpreter, IPython is the way to go!
(Find Ipython here: http://ipython.scipy.org/moin/ )
HTH,
Wayne


On Fri, Oct 31, 2008 at 6:58 AM, spir <denis.spir at free.fr> wrote:

> Hello,
>
> I have read tons of reviews of editors for python. But they seem to be all
> biased, meaning that what the author finds important is well documented
> while the rest not at all.
> I'm looking for  something like a simple table showing main features for
> all editors or IDEs. Do you know of anything like that? If not, maybe you
> could point me to editors that meet the following requirements:
>
> Fondamental features:
> * Written in python (because I plan to tweak inside for some specific
> needs).
> * Use of wxPython for UI (ditto -- I find wx clearer than tk or QT).
> * /Really/ work well with non-ascii systems, including edition of utf-8
> files (most don't in real life use, even when they pretend to).
> * Customizable syntax highlighting.
> * Customizable key bindings.
> * Running of python code from inside the IDE.
> * Code browser at least for currently edited file.
> * Multiple file opening through tabs.
> * Basic editing: search/replace, (un)comment, un(indent),...
>
> Nice additional features:
> * Additional editing features: tooltips, code expansion, regexps (maybe one
> day I will learn that ;-)),...
> * Project level management/browsing.
> * GUI building (like boa, but boa constantly crashes with non-ascii -- even
> with unicode version of wxPython installed).
>
> I currently use DrPython which is very well designed for most of this, but
> its lack of code browsing is a pain as soon as a project starts scaling. And
> some of its behaviour is a bit weird for me in some fields (such as edition
> actions on folded or half-folded block).
> Notepad++ is my favorite editor for everything except coding in python. I
> would love to use it, but as far as I know, it lacks integration of a python
> interpretor.
>
> Thanks,
> Denis
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/518ea610/attachment-0001.htm>

From zstumgoren at gmail.com  Fri Oct 31 14:29:54 2008
From: zstumgoren at gmail.com (Serdar Tumgoren)
Date: Fri, 31 Oct 2008 09:29:54 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
	<1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>
Message-ID: <cadf44510810310629w1cc420d3q29f1ff0903e423b1@mail.gmail.com>

Hey everyone,

I spent a day trying to adapt Mr. Gailer's simple and elegant code to the
csv version suggested by Mr. Johnson, but I can't seem to get it working.

I adapted the example to my particular use case, but the problem occurs
regardless of the dataset used: Namely, when I loop through the items in the
list of fields and use "writerows" to print to a csv file, the loop splits
every

So my starting dataset:

"White, Barry","brave","tall","52"
"Rick Davis","confident","average","48"
"Jane Doe","pretty","short","40","New York"
"Smith, Janet","organized","65","San Francisco","CA"
"John Quincy","lazy","tall","35"
"Mike Leeds","curious","38"

...looks like this:

W,h,i,t,e,",", ,B,a,r,r,y
b,r,a,v,e
W,h,i,t,e,",", ,B,a,r,r,y
t,a,l,l
W,h,i,t,e,",", ,B,a,r,r,y
5,2
R,i,c,k, ,D,a,v,i,s
c,o,n,f,i,d,e,n,t
R,i,c,k, ,D,a,v,i,s
a,v,e,r,a,g,e
R,i,c,k, ,D,a,v,i,s
4,8
<snip>

...instead of the desired result:

White, Barry    brave
White, Barry    tall
White, Barry    52
Rick Davis      confident
Rick Davis      average
Rick Davis      48
Jane Doe        pretty
Jane Doe        short
<snip>

When print to the shell, however, I get the results I'm looking for.


Below is my code. Can someone tell me how I'm botching the use of the
"writerows" method? Also, on a separate note, is it possible and necessary
to close the input and output files when using csv module? I keep getting a
"module has no close method" error when I try to close the files...

 1 #!/usr/bin/python
 2
 3 import csv
 4
 5
 6 reader = csv.reader(open('/path/to/infile2.txt',    'rb'))
 7
 8
 9 writer = csv.writer(open('/path/to/outfile2.txt',    'wb'))
10
11 #loop through fields in row
12 for line in reader:
13     #name is the first field in row
14     name = line[0]
15     #create list of person's attributes
16     attributes = line[1:]
17
18     for characteristic in attributes:
19         #print to shell for testing
20         print name + "\t" + characteristic
21
22         #write rows to file
23         writer.writerows((name,characteristic))




On Wed, Oct 29, 2008 at 1:31 PM, Kent Johnson <kent37 at tds.net> wrote:

> On Wed, Oct 29, 2008 at 11:28 AM, bob gailer <bgailer at gmail.com> wrote:
> > qsqgeekyogdty at tiscali.co.uk wrote:
> >>
> >> hello,
> >> i have the follwoing csv file:
> >>
> >> "Berat","Berat","Ku?ov?","Skrapar"
>
> > There is a csv module, but for something this simple the following will
> > suffice:
>
> as long as none of the data fields include a comma...given that the
> equivalent program using csv is barely longer than your example, and
> more robust, it seems worth using to me. For example (untested):
>
> import csv
>
> inputFile= open(path-to-the-input-file, 'rb')
> reader = csv.reader(inputFile)
> outputFile = open(path-to-the-output-file, 'wb')
> writer = csv.writer(outputFile)
>
> for line in reader:
>  region = line [0]
>  for district in line[1:]:
>   writer.write((region, district))
> inputFile.close()
> outputFile.close()
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/d3c3f4f9/attachment.htm>

From zstumgoren at gmail.com  Fri Oct 31 14:32:58 2008
From: zstumgoren at gmail.com (Serdar Tumgoren)
Date: Fri, 31 Oct 2008 09:32:58 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <cadf44510810310629w1cc420d3q29f1ff0903e423b1@mail.gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
	<1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>
	<cadf44510810310629w1cc420d3q29f1ff0903e423b1@mail.gmail.com>
Message-ID: <cadf44510810310632j7c4926fci21048cca0b494a37@mail.gmail.com>

sorry -- forgot to complete my thought in 2nd graf. see below...

On Fri, Oct 31, 2008 at 9:29 AM, Serdar Tumgoren <zstumgoren at gmail.com>wrote:

> Hey everyone,
>
> I spent a day trying to adapt Mr. Gailer's simple and elegant code to the
> csv version suggested by Mr. Johnson, but I can't seem to get it working.
>
> I adapted the example to my particular use case, but the problem occurs
> regardless of the dataset used: Namely, when I loop through the items in the
> list of fields and use "writerows" to print to a csv file, the loop splits
> the entire line and prints every letter, space, etc. separated by a comma
> (rather than the name-attribute pairings I'm aiming for on each line).
>
> So my starting dataset:
>
> "White, Barry","brave","tall","52"
> "Rick Davis","confident","average","48"
> "Jane Doe","pretty","short","40","New York"
> "Smith, Janet","organized","65","San Francisco","CA"
> "John Quincy","lazy","tall","35"
> "Mike Leeds","curious","38"
>
> ...looks like this:
>
> W,h,i,t,e,",", ,B,a,r,r,y
> b,r,a,v,e
> W,h,i,t,e,",", ,B,a,r,r,y
> t,a,l,l
> W,h,i,t,e,",", ,B,a,r,r,y
> 5,2
> R,i,c,k, ,D,a,v,i,s
> c,o,n,f,i,d,e,n,t
> R,i,c,k, ,D,a,v,i,s
> a,v,e,r,a,g,e
> R,i,c,k, ,D,a,v,i,s
> 4,8
> <snip>
>
> ...instead of the desired result:
>
> White, Barry    brave
> White, Barry    tall
> White, Barry    52
> Rick Davis      confident
> Rick Davis      average
> Rick Davis      48
> Jane Doe        pretty
> Jane Doe        short
> <snip>
>
> When print to the shell, however, I get the results I'm looking for.
>
>
> Below is my code. Can someone tell me how I'm botching the use of the
> "writerows" method? Also, on a separate note, is it possible and necessary
> to close the input and output files when using csv module? I keep getting a
> "module has no close method" error when I try to close the files...
>
>  1 #!/usr/bin/python
>  2
>  3 import csv
>  4
>  5
>  6 reader = csv.reader(open('/path/to/infile2.txt',    'rb'))
>  7
>  8
>  9 writer = csv.writer(open('/path/to/outfile2.txt',    'wb'))
> 10
> 11 #loop through fields in row
> 12 for line in reader:
> 13     #name is the first field in row
> 14     name = line[0]
> 15     #create list of person's attributes
> 16     attributes = line[1:]
> 17
> 18     for characteristic in attributes:
> 19         #print to shell for testing
> 20         print name + "\t" + characteristic
> 21
> 22         #write rows to file
> 23         writer.writerows((name,characteristic))
>
>
>
>
>
> On Wed, Oct 29, 2008 at 1:31 PM, Kent Johnson <kent37 at tds.net> wrote:
>
>> On Wed, Oct 29, 2008 at 11:28 AM, bob gailer <bgailer at gmail.com> wrote:
>> > qsqgeekyogdty at tiscali.co.uk wrote:
>> >>
>> >> hello,
>> >> i have the follwoing csv file:
>> >>
>> >> "Berat","Berat","Ku?ov?","Skrapar"
>>
>> > There is a csv module, but for something this simple the following will
>> > suffice:
>>
>> as long as none of the data fields include a comma...given that the
>> equivalent program using csv is barely longer than your example, and
>> more robust, it seems worth using to me. For example (untested):
>>
>> import csv
>>
>> inputFile= open(path-to-the-input-file, 'rb')
>> reader = csv.reader(inputFile)
>> outputFile = open(path-to-the-output-file, 'wb')
>> writer = csv.writer(outputFile)
>>
>> for line in reader:
>>  region = line [0]
>>  for district in line[1:]:
>>   writer.write((region, district))
>> inputFile.close()
>> outputFile.close()
>>
>> Kent
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>


-- 
Serdar Tumgoren
The Record
150 River Street
Hackensack, NJ 07601
201-403-0834
tumgoren at northjersey.com
northjersey.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/57ba84e6/attachment.htm>

From kent37 at tds.net  Fri Oct 31 14:59:45 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 31 Oct 2008 09:59:45 -0400
Subject: [Tutor] fast list traversal
In-Reply-To: <COL103-DS141D724F7A5CF87591229DA3200@phx.gbl>
References: <COL103-DS141D724F7A5CF87591229DA3200@phx.gbl>
Message-ID: <1c2a2c590810310659t3662020iacedfaa41873e597@mail.gmail.com>

On Fri, Oct 31, 2008 at 8:34 AM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> Hi Kent
>
> The code is very simple:
>
> dict_long_lists = defaultdict(list)
> for long_list in dict_long_lists.itervalues()
>         for element in long_list:
>                 array_a[element] = m + n + p        # m,n,p are numbers
>
> The long_list's are read from a defaultdict(list) dictionary and so don't
> need initializing.  The elements of long_list are integers and ordered
> (sorted before placing in dictionary).  There are > 20,000 long_list's each
> with a variable number of elements (>5,000).  The elements of long_list are
> immutable (ie. don't change).

I don't see a lot of potential for optimization. How long does it take now?

If m+n+p don't change within the loop, you should hoist the addition
out of the loop. If the code is running at module level, put it into a
function or method and make sure all the names used in the loop are
local -  name lookup is faster for local names inside a function. Also
you could try replacing the inner loop with

itertools.imap(array_a.__setitem__, long_list, itertools.repeat(m+n+p))

Perhaps there is a way to do this with numpy that would be faster, I don't know.

You might want to ask on comp.lang.python, there are some optimization
gurus who hang out there.

Kent

From kent37 at tds.net  Fri Oct 31 15:02:32 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 31 Oct 2008 10:02:32 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <cadf44510810310632j7c4926fci21048cca0b494a37@mail.gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
	<1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>
	<cadf44510810310629w1cc420d3q29f1ff0903e423b1@mail.gmail.com>
	<cadf44510810310632j7c4926fci21048cca0b494a37@mail.gmail.com>
Message-ID: <1c2a2c590810310702i6bef9845sfa5660e7703aec59@mail.gmail.com>

On Fri, Oct 31, 2008 at 9:32 AM, Serdar Tumgoren <zstumgoren at gmail.com> wrote:
>> Below is my code. Can someone tell me how I'm botching the use of the
>> "writerows" method? Also, on a separate note, is it possible and necessary
>> to close the input and output files when using csv module? I keep getting a
>> "module has no close method" error when I try to close the files...

Use writerow() not writerows() - you are writing a single row.

To close the files you have to keep a reference to the underlying
file. See my original example.

Kent

From zstumgoren at gmail.com  Fri Oct 31 15:09:05 2008
From: zstumgoren at gmail.com (Serdar Tumgoren)
Date: Fri, 31 Oct 2008 10:09:05 -0400
Subject: [Tutor] csv manipulation
In-Reply-To: <1c2a2c590810310702i6bef9845sfa5660e7703aec59@mail.gmail.com>
References: <14073297.1225292030644.JavaMail.root@ps30>
	<4908812E.4000708@gmail.com>
	<1c2a2c590810291031s65583600t4ae57855faff711e@mail.gmail.com>
	<cadf44510810310629w1cc420d3q29f1ff0903e423b1@mail.gmail.com>
	<cadf44510810310632j7c4926fci21048cca0b494a37@mail.gmail.com>
	<1c2a2c590810310702i6bef9845sfa5660e7703aec59@mail.gmail.com>
Message-ID: <cadf44510810310709k53fbc5fak668b3fb3e7e37ab3@mail.gmail.com>

Aha! That did the trick. Thanks so much!

On Fri, Oct 31, 2008 at 10:02 AM, Kent Johnson <kent37 at tds.net> wrote:

> On Fri, Oct 31, 2008 at 9:32 AM, Serdar Tumgoren <zstumgoren at gmail.com>
> wrote:
> >> Below is my code. Can someone tell me how I'm botching the use of the
> >> "writerows" method? Also, on a separate note, is it possible and
> necessary
> >> to close the input and output files when using csv module? I keep
> getting a
> >> "module has no close method" error when I try to close the files...
>
> Use writerow() not writerows() - you are writing a single row.
>
> To close the files you have to keep a reference to the underlying
> file. See my original example.
>
> Kent
>



-- 
Serdar Tumgoren
The Record
150 River Street
Hackensack, NJ 07601
201-403-0834
tumgoren at northjersey.com
northjersey.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081031/680dd1a4/attachment.htm>

From bgailer at gmail.com  Fri Oct 31 19:50:19 2008
From: bgailer at gmail.com (bob gailer)
Date: Fri, 31 Oct 2008 14:50:19 -0400
Subject: [Tutor] Problem formatting raw_input
In-Reply-To: <490A9670.1000400@internode.on.net>
References: <490A758D.2080103@internode.on.net>	<e9764b730810302041g68853274i5f834081ecbbcfe@mail.gmail.com>
	<490A9670.1000400@internode.on.net>
Message-ID: <490B536B.1060300@gmail.com>

Peter Anderson wrote:
> Dj Gilcrease wrote:
>> The simple answer is to just use chr(int(inNum))
>>
>> though here is how I would do it
>>
>> def convert_string_to_int(strInt):
>>     try:
>>         return int(strInt)
>>     except ValueError:
>>         return 0
>>
>> def getNumbers(output):
>>     inNum = raw_input("Please enter an ASCII number\n(33 - 126,
>> [Enter] to quit): ")
>>     ascii_num = convert_string_to_int(inNum)
>>     if ascii_num >= 33 and ascii_num <=126:
>>         output.append(chr(ascii_num))
>>         getNumbers(output)

I would avoid recursion. Save that for recursive algorithms. An ordinary 
loop is easier to read/maintain and you will not run out of recursion 
depth. Also give user a meaningful error message.

    while True:
        inNum = raw_input("Please enter an ASCII number\n(33 - 126, 
[Enter] to quit): ")
        if not inNum:
            break
        ascii_num = convert_string_to_int(inNum)
        if ascii_num >= 33 and ascii_num <=126:
            output.append(chr(ascii_num))
        else:
            print "Input must be an integer in range 33..126"

>>
>> if __name__ == '__main__':
>>     print "This script converts a sequence of ASCII numbers"
>>     print "into the string of text that it represents."
>>     print
>>     output = []
>>     getNumbers(output)
>>     print output
>>
>> Dj Gilcrease
>> OpenRPG Developer
>> ~~http://www.openrpg.com
> Dj,
>
> Thanks for the suggestions; both work perfectly.  Can I ask a 
> supplementary question please?
>
> In the def convert_string... function why do you include the "except 
> ValueError: / return 0" clause?
try: must be followed by except or finally.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


From dwbarne at earthlink.net  Fri Oct 31 21:16:52 2008
From: dwbarne at earthlink.net (dwbarne at earthlink.net)
Date: Fri, 31 Oct 2008 16:16:52 -0400 (EDT)
Subject: [Tutor] how to call a binding method from an imported module
Message-ID: <30629396.1225484212200.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>

This problem involves a callback method while using 'bind'. The bind statement and the callback function are both in a module imported to the main program. Relevant code snippets are as follows:

#++++ begin snippet

# main code
<code>
import module_Editor
.
class MyClass():
<code>
    def editor(self):

        module_Editor.my_Editor(self,self.frameParent)
<code>
# end of main code

# module 'module_Editor'
<imports>
def my_Editor(self,parentFrame):
<code>
    self.textMyCode.bind(
        "<KeyPress-Return>",
        handlerTextLineNumbersReturn(self)
        )
<code>
def handlerTextLineNumbersReturn(self,event):
    def temp():
    
        print '\n** In handlerTextLineNumbersReturn'

    return temp
<code>
# end of module 'module_Editor'

# ++++ end snippet

When the bind callback handler is called, the following error is returned:

++++ begin error
Exception in Tkinter callback
Traceback (most recent call last):
 File "c:\Python251_102507\lib\lib-tk\Tkinter.py", line 1403, in __call__
    return self.func(*args)
TypeError: tempDef() takes no arguments (1 given)

++++ end error

The above approach works for widgets in the module calling callback handlers that return a def like the above, but bind statements apparently do not like this approach for some reason.

Any ideas on what I'm doing wrong here? Maybe a "*args" needs to go somewhere in the calling or def statements? If so, where does it go?

Daniel

From kent37 at tds.net  Fri Oct 31 22:46:53 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 31 Oct 2008 17:46:53 -0400
Subject: [Tutor] how to call a binding method from an imported module
In-Reply-To: <30629396.1225484212200.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>
References: <30629396.1225484212200.JavaMail.root@mswamui-swiss.atl.sa.earthlink.net>
Message-ID: <1c2a2c590810311446i7dcd76cap600dd73057b5bec4@mail.gmail.com>

On Fri, Oct 31, 2008 at 4:16 PM,  <dwbarne at earthlink.net> wrote:
> This problem involves a callback method while using 'bind'. The bind statement and the callback function are both in a module imported to the main program. Relevant code snippets are as follows:
>
> #++++ begin snippet
>
> # main code
> <code>
> import module_Editor
> .
> class MyClass():
> <code>
>    def editor(self):
>
>        module_Editor.my_Editor(self,self.frameParent)
> <code>
> # end of main code
>
> # module 'module_Editor'
> <imports>
> def my_Editor(self,parentFrame):

This is confusing. Is my_Editor() part of a class? If not, why does it
take a self parameter?
> <code>
>    self.textMyCode.bind(
>        "<KeyPress-Return>",
>        handlerTextLineNumbersReturn(self)

Presumably you are using Tkinter?

Note that you are calling handlerTextLineNumbersReturn() here. I would
expect a TypeError here because you only pass one argument.

Normally the second argument to bind() is a function, not a call to a function.
>        )

> <code>
> def handlerTextLineNumbersReturn(self,event):
>    def temp():
>
>        print '\n** In handlerTextLineNumbersReturn'
>
>    return temp

I don't understand why you define and return another function here.
Normally an event handler does not return a value.

> <code>
> # end of module 'module_Editor'
>
> # ++++ end snippet
>
> When the bind callback handler is called, the following error is returned:
>
> ++++ begin error
> Exception in Tkinter callback
> Traceback (most recent call last):
>  File "c:\Python251_102507\lib\lib-tk\Tkinter.py", line 1403, in __call__
>    return self.func(*args)
> TypeError: tempDef() takes no arguments (1 given)

What is tempDef() ?
>
> ++++ end error
>
> The above approach works for widgets in the module calling callback handlers that return a def like the above, but bind statements apparently do not like this approach for some reason.

Can you give an example of what you are doing that works?

> Any ideas on what I'm doing wrong here? Maybe a "*args" needs to go somewhere in the calling or def statements? If so, where does it go?

The code seems a bit confused. I don't understand what you are trying
to do. Possibly what you want is this:

def my_Editor(self,parentFrame):
<code>
   self.textMyCode.bind(
       "<KeyPress-Return>",
       handlerTextLineNumbersReturn
       )
<code>
def handlerTextLineNumbersReturn(event):
       print '\n** In handlerTextLineNumbersReturn'

Kent

From qsqgeekyogdty at tiscali.co.uk  Fri Oct 31 23:04:57 2008
From: qsqgeekyogdty at tiscali.co.uk (qsqgeekyogdty at tiscali.co.uk)
Date: Fri, 31 Oct 2008 23:04:57 +0100 (GMT+01:00)
Subject: [Tutor] mergin two csv files based on a common join
Message-ID: <24055736.1225490697083.JavaMail.root@ps28>

Hello again,
Thanks for the replies on my previous post, but I have a different 
problem now and don't see how to deal with it in a smooth way.

I have two csv files where:

1.csv

"1", "text", "aa"
"2", "text2", "something else"
"3", "text3", "something else"

2.csv

"text", "xx"
"text", "yy"
"text3", "zz"

now I would like to have an output like:

"1", "text", "aa"
"1", "text", "xx"
"2", "text2", "something else"
"3", "text3", "something else"
"3", "text3", "zz"

I basically need to merge the two csv files based on the column-2

Thanks



________________________________________________

Escape to the sun - http://www.tiscali.co.uk/travel/

________________________________________________