From rikard.bosnjakovic at gmail.com  Fri Jun  1 07:41:00 2007
From: rikard.bosnjakovic at gmail.com (Rikard Bosnjakovic)
Date: Fri, 1 Jun 2007 07:41:00 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <42E18E55C3B8C24FBE1633506D22EC1303833311@DET-MAIL-EVS03.DETISP.LOCAL>
References: <42E18E55C3B8C24FBE1633506D22EC1303833311@DET-MAIL-EVS03.DETISP.LOCAL>
Message-ID: <d9e88eaf0705312241p69ae57a2v16cc013d9ac1ee46@mail.gmail.com>

On 5/30/07, Treloar, Nick <Nick.Treloar at education.nsw.gov.au> wrote:

> how do you import sounds

Do you mean a module named "sounds", or sounds in general? If the
latter, what do you mean by "import" sounds? Read a sound-file? Play a
sound-file?

There is a wav-module you can use: http://docs.python.org/lib/module-wave.html

If you want to play sounds, check pygame: http://www.pygame.org/


-- 
- Rikard - http://bos.hack.org/cv/

From preecha88 at gmail.com  Fri Jun  1 08:04:28 2007
From: preecha88 at gmail.com (Preecha Bundrikwong)
Date: Fri, 1 Jun 2007 13:04:28 +0700
Subject: [Tutor] newbie: Reading text file
Message-ID: <30c6012b0705312304u39d3e5dbg517756aaddcadede@mail.gmail.com>

Dear Tutors,

I have a text file (mylist.py actually), it contains exactly below:
---------------
# file mylist.py
jobs = [
        'Lions',
        'SysTest',
        'trainDD',
        'Cats',
        'train',
        'sharks',
        'whale',
        ]
----------------

I want to write another script and get the list "jobs" from the above
script.

Is it possible for me to get the variable 'jobs' and its value from the file
(as a list)? What I'm trying to do now is open the file, readlines in a
loop, once it finds the line with "jobs = [", then start accumulate (append)
a varible until it hits the line with "]" then stop. This is too
complicated. I believe there should be an easier way in Python. Can anyone
guide me, please.

Thanks in advance,
PB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/9c490735/attachment.html 

From duncan at thermal.esa.int  Fri Jun  1 09:17:01 2007
From: duncan at thermal.esa.int (Duncan Gibson)
Date: Fri, 1 Jun 2007 09:17:01 +0200
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <30c6012b0705312304u39d3e5dbg517756aaddcadede@mail.gmail.com>
References: <30c6012b0705312304u39d3e5dbg517756aaddcadede@mail.gmail.com>
Message-ID: <20070601091701.109485ba.duncan@thermal.esa.int>


> I have a text file (mylist.py actually), it contains exactly below:
> ---------------
> # file mylist.py
> jobs = [
>         'Lions',
>         'SysTest',
>         'trainDD',
>         'Cats',
>         'train',
>         'sharks',
>         'whale',
>         ]
> ----------------
> 
> I want to write another script and get the list "jobs" from the above
> script.

I assume you mean in another python script? Try:

import mylist
print mylist.jobs


From alan.gauld at btinternet.com  Fri Jun  1 09:31:59 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 08:31:59 +0100
Subject: [Tutor] newbie: Reading text file
References: <30c6012b0705312304u39d3e5dbg517756aaddcadede@mail.gmail.com>
Message-ID: <f3oi2p$6hv$1@sea.gmane.org>


"Preecha Bundrikwong" <preecha88 at gmail.com> wrote

> I have a text file (mylist.py actually), it contains exactly below:
> ---------------
> # file mylist.py
> jobs = [
>        'Lions',
>        'SysTest',
>        ]
> ----------------
>
> I want to write another script and get the list "jobs" from the 
> above
> script.

Because this is a python file and python files are effectively
modules you can use import:

import mylist
print mylist.jobs

> Is it possible for me to get the variable 'jobs' and its value from 
> the file
> (as a list)? What I'm trying to do now is open the file, readlines 
> in a
> loop, once it finds the line with "jobs = [", then start accumulate 
> (append)
> a varible until it hits the line with "]" then stop.

If it wasn't a python file (some other language say) then that is
exactly what you would need to do. Programming often makes
apparently simple things seem complicated! :-)

Alan G. 



From grantahagstrom at gmail.com  Fri Jun  1 10:12:13 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 03:12:13 -0500
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <f3oi2p$6hv$1@sea.gmane.org>
References: <30c6012b0705312304u39d3e5dbg517756aaddcadede@mail.gmail.com>
	<f3oi2p$6hv$1@sea.gmane.org>
Message-ID: <4257d6370706010112nce20db3hf812e225d7ff4f87@mail.gmail.com>

Hey,

I'm a newbie and this is my first script submission to this email list.
I was able to parse out the jobs list into a string: "jobs = [ . . ."
However, I can't make python interpret that string as the command "jobs = [
some list]"

#SCRIPT

# open the file and assign it to the variable "thefile"
thefile = open("/home/banter/Desktop/mylist.py")

# read the file and assign it to the variable "read_thefile"
read_thefile = file.read(thefile)

# make the file's contents into a string
string_thefile = str(read_thefile)

# split that string up into a list
splitlist_thefile = string_thefile.split()

# index the list to find the placement of the word 'jobs'
it_starts = splitlist_thefile.index('jobs')

# index the list to find the placement of the ']'
# bug warning: an item in list "job" with a bracket will
#    throw off this script
# Also, there needs to be a comparison between instances of
# ']' such that the returned index number will be the smallest
# number that is still larger than 'it_starts'
it_almost_ends = splitlist_thefile.index(']')

# the ending index number is not good enough
# we need to add a 1 to the number
# read this to find out why
# http://www.diveintopython.org/native_data_types/lists.html
it_ends = it_almost_ends + 1

# assign the data that you want to a variable
# if you have a question about this, then you
# probably didn't read the link above
wanted_data = splitlist_thefile[it_starts:it_ends]

# join it all up
joined = " ".join(wanted_data)

print joined

#END SCRIPT

So close yet so far away!

oh, and Alan, are you getting a duplicate copy of this email? I am CCing
tutor at python and TOing you . . .

Best,

Grant Hagstrom

On 6/1/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>
> "Preecha Bundrikwong" <preecha88 at gmail.com> wrote
>
> > I have a text file (mylist.py actually), it contains exactly below:
> > ---------------
> > # file mylist.py
> > jobs = [
> >        'Lions',
> >        'SysTest',
> >        ]
> > ----------------
> >
> > I want to write another script and get the list "jobs" from the
> > above
> > script.
>
> Because this is a python file and python files are effectively
> modules you can use import:
>
> import mylist
> print mylist.jobs
>
> > Is it possible for me to get the variable 'jobs' and its value from
> > the file
> > (as a list)? What I'm trying to do now is open the file, readlines
> > in a
> > loop, once it finds the line with "jobs = [", then start accumulate
> > (append)
> > a varible until it hits the line with "]" then stop.
>
> If it wasn't a python file (some other language say) then that is
> exactly what you would need to do. Programming often makes
> apparently simple things seem complicated! :-)
>
> 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/20070601/6733241c/attachment.htm 

From grantahagstrom at gmail.com  Fri Jun  1 10:26:59 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 03:26:59 -0500
Subject: [Tutor] bug or feature
Message-ID: <4257d6370706010126q75e8826bqc88e05a768afeb92@mail.gmail.com>

A bug or feature in the IDLE of python 2.5?

pre-step: save the following file to your computer:
# file mylist.py
jobs = [
        'Lions',
        'SysTest',
        'trainDD',
        'Cats',
        'train',
        'sharks',
        'whale',
        ]

Step 1.

copy, paste this script into the idle window. hit f5 to run.

thefile = open("mylist.py")
read_thefile = file.read(thefile)

string_thefile = str(read_thefile)

splitlist_thefile = string_thefile.split()

it_starts = splitlist_thefile.index('jobs')

Step 2.

open a new window. close the window from step one. close the shell from the
previous f5 execution.

Step 3.

paste and run this code.

thefile = open("/home/banter/Desktop/mylist.py")
read_thefile = file.read(thefile)

#string_thefile = str(read_thefile)

splitlist_thefile = string_thefile.split()

it_starts = splitlist_thefile.index('jobs')

Result: python remembers "string_thefile" even after both the shell and the
original scripting window have been closed!
bug or feature?

Best,

Grant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/2486e930/attachment.html 

From alan.gauld at btinternet.com  Fri Jun  1 10:42:18 2007
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Fri, 1 Jun 2007 08:42:18 +0000 (GMT)
Subject: [Tutor] newbie: Reading text file
Message-ID: <440963.67763.qm@web86112.mail.ird.yahoo.com>

Hi Grant,

> I'm a newbie and this is my first script submission to this email list.
> I was able to parse out the jobs list into a string: "jobs = [ . . ."
> However, I can't make python interpret that string as the command "jobs = [ some list]"


There are ways of doing that but unless you are specifically doing that 
as a challenge it is much easier just to import your py file. When you 
import a module Python will evaluate the contents as Python code 
and the variables in the module become available to you. That way 
you don't need to read the file manually.

The only caveat with the import method is that Python needs to find 
our module so it must either be in the same folder as your python 
script or the folder must be in the sys.path variable. Thus for a general solution:

import sys
sys.path.append('the/folder/where/myfile/lives')
import myfile    # no .py
jobs = myfile.jobs

And that should be it. jobs should now contain the same list that 
was in your myfile.py


However if you do want todo it the hard way:

> #SCRIPT
> # open the file and assign it to the variable "thefile"
> thefile = open("/home/banter/Desktop/mylist.py") 

OK To here but....

> # read the file and assign it to the variable "read_thefile"

> read_thefile = file.read(thefile)
> # make the file's contents into a string
> string_thefile = str(read_thefile)

this should simply be

data = thefile.read()

# split that string up into a list
splitlist = data.split()


# index the list to find the placement of the word 'jobs'
it_starts = splitlist.index('jobs')

# index the list to find the placement of the ']'

OK Now its getting rather messy. Its probably easier to take a 
completely different approach, something like(untested code!):

started = False
for line in file(myfile.py'):
     if 'jobs' in line and not started:
        jobs = []
        started = True
        continue
    if ']' not in line and started:
        jobs.append(line')
    else: break

> are you getting a duplicate copy of this email? 
> I am CCing 
tutor at python and TOing you . . .

Yes that's the correct procedure. Use ReplyAll in your mail tool 
and all should be well. (although some folks would prefer if you 
just reply to the list, it's a bit of a hot topic! :-)

HTH,

Alan G.





      ____________________________________________________
Which email service gives you unlimited storage?
http://uk.mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/f63e182c/attachment.htm 

From andreas at kostyrka.org  Fri Jun  1 11:16:24 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Fri, 01 Jun 2007 11:16:24 +0200
Subject: [Tutor] bug or feature
In-Reply-To: <4257d6370706010126q75e8826bqc88e05a768afeb92@mail.gmail.com>
References: <4257d6370706010126q75e8826bqc88e05a768afeb92@mail.gmail.com>
Message-ID: <465FE3E8.9000709@kostyrka.org>

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

Just the way IDLE works. Unexpected, but certainly not a bug, I'd say.

Andreas

Grant Hagstrom wrote:
> A bug or feature in the IDLE of python 2.5?
> 
> pre-step: save the following file to your computer:
> # file mylist.py
> jobs = [
>         'Lions',
>         'SysTest',
>         'trainDD',
>         'Cats',
>         'train',
>         'sharks',
>         'whale',
>         ]
> 
> Step 1.
> 
> copy, paste this script into the idle window. hit f5 to run.
> 
> thefile = open(" mylist.py")
> read_thefile = file.read(thefile)
> 
> string_thefile = str(read_thefile)
> 
> splitlist_thefile = string_thefile.split()
> 
> it_starts = splitlist_thefile.index('jobs')
> 
> Step 2.
> 
> open a new window. close the window from step one. close the shell from
> the previous f5 execution.
> 
> Step 3.
> 
> paste and run this code.
> 
> thefile = open("/home/banter/Desktop/mylist.py")
> read_thefile = file.read(thefile)
> 
> #string_thefile = str(read_thefile)
> 
> splitlist_thefile = string_thefile.split()
> 
> it_starts = splitlist_thefile.index('jobs')
> 
> Result: python remembers "string_thefile" even after both the shell and
> the original scripting window have been closed!
> bug or feature?
> 
> Best,
> 
> Grant
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGX+PnHJdudm4KnO0RAsdhAKCBUU9HxXqHPZXo0BXqDEtQ+kBc1wCfS/kc
Tk1icM3HgifChP7wxKShM2k=
=fig0
-----END PGP SIGNATURE-----

From grantahagstrom at gmail.com  Fri Jun  1 11:32:00 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 04:32:00 -0500
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <440963.67763.qm@web86112.mail.ird.yahoo.com>
References: <440963.67763.qm@web86112.mail.ird.yahoo.com>
Message-ID: <4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>

Thanks for your help Alan.

I found that when I used the code, it did returne a list but it is riddled
with formatting characters.
My question is, is it possible to strip out multiple characters at once?

started = False
for line in file('mylist.py'):
    if 'jobs' in line and not started:
        jobs = []
        started = True
        continue
    if ']' not in line and started:
        nospaces = line.lstrip()
        no_n = nospaces.strip("\n")          #note the constant
re-variabling
        no_comma = no_n.strip(",")
        no_quote = no_comma.strip("\'")
        jobs.append(no_quote)
    else: print "break"

Thanks,

Grant



On 6/1/07, ALAN GAULD <alan.gauld at btinternet.com> wrote:
>
> Hi Grant,
>
> > I'm a newbie and this is my first script submission to this email list.
> > I was able to parse out the jobs list into a string: "jobs = [ . . ."
> > However, I can't make python interpret that string as the command "jobs
> = [ some list]"
>
> There are ways of doing that but unless you are specifically doing that
> as a challenge it is much easier just to import your py file. When you
> import a module Python will evaluate the contents as Python code
> and the variables in the module become available to you. That way
> you don't need to read the file manually.
>
> The only caveat with the import method is that Python needs to find
> our module so it must either be in the same folder as your python
> script or the folder must be in the sys.path variable. Thus for a general
> solution:
>
> import sys
> sys.path.append('the/folder/where/myfile/lives')
> import myfile    # no .py
> jobs = myfile.jobs
>
> And that should be it. jobs should now contain the same list that
> was in your myfile.py
>
>
> However if you do want todo it the hard way:
>
> > #SCRIPT
> > # open the file and assign it to the variable "thefile"
> > thefile = open("/home/banter/Desktop/mylist.py")
>
> OK To here but....
>
> > # read the file and assign it to the variable "read_thefile"
> > read_thefile = file.read(thefile)
> > # make the file's contents into a string
> > string_thefile = str(read_thefile)
>
> this should simply be
>
> data = thefile.read()
>
> # split that string up into a list
> splitlist = data.split()
>
> # index the list to find the placement of the word 'jobs'
> it_starts = splitlist.index('jobs')
>
> # index the list to find the placement of the ']'
>
> OK Now its getting rather messy. Its probably easier to take a
> completely different approach, something like(untested code!):
>
> started = False
> for line in file(myfile.py'):
>      if 'jobs' in line and not started:
>         jobs = []
>         started = True
>         continue
>     if ']' not in line and started:
>         jobs.append(line')
>     else: break
>
> > are you getting a duplicate copy of this email?
> > I am CCing tutor at python and TOing you . . .
>
> Yes that's the correct procedure. Use ReplyAll in your mail tool
> and all should be well. (although some folks would prefer if you
> just reply to the list, it's a bit of a hot topic! :-)
>
> HTH,
>
> Alan G.
>
> Inbox cluttering up with junk? Clean up with Yahoo! Mail<http://us.rd.yahoo.com/mailuk/taglines/gmail/clean_up/*http://us.rd.yahoo.com/evt=48525/*http://uk.docs.yahoo.com/mail/isp_targeting.html>
> .
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/45d26e33/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mylist.py
Type: text/x-python
Size: 158 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070601/45d26e33/attachment.py 

From alan.gauld at btinternet.com  Fri Jun  1 11:32:51 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 10:32:51 +0100
Subject: [Tutor] PyCrust IDE/Shell
Message-ID: <f3op5d$uv7$1@sea.gmane.org>

Is anyone else out there using PyCrust as their python shell?

I've been using it for a few weeks now and I'm completely sold.
It is the best shell I've used, everything just seems to work.
I can cut n paste sections of interpreter code and PyCrust 
correctly strips out the prompts and organises things. The 
tooltips and autocomplete work better than IDLE or pythonwin. 
There are no indentation problems like on IDLE. The namespace 
viewer and other tools are genuinely useful.

I haven't tried the other Py tools yet - A La Mode seems the 
obvious next step with its multi tabbed editors. But the beauty 
of PyCrust is that it works beautifully with vim (or anything 
else that can cut n paste)

Any other users got PyCrust tiposthey can share?

Alan G.


From kent37 at tds.net  Fri Jun  1 12:24:50 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 01 Jun 2007 06:24:50 -0400
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>
References: <440963.67763.qm@web86112.mail.ird.yahoo.com>
	<4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>
Message-ID: <465FF3F2.1050003@tds.net>

Grant Hagstrom wrote:
> Thanks for your help Alan.
> 
> I found that when I used the code, it did returne a list but it is 
> riddled with formatting characters.
> My question is, is it possible to strip out multiple characters at once?

Yes, just pass multiple characters to strip(), e.g.
line = line.strip('\r\n\t \'",')

I'm curious why you don't like the import solution. exec and execfile() 
could also work although all three require that the file contain trusted 
data.

Here are a couple of recipes that do almost what you want (you would 
still have to strip out the "jobs = " part:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/281056

Kent

From grantahagstrom at gmail.com  Fri Jun  1 12:57:06 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 05:57:06 -0500
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <465FF3F2.1050003@tds.net>
References: <440963.67763.qm@web86112.mail.ird.yahoo.com>
	<4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>
	<465FF3F2.1050003@tds.net>
Message-ID: <4257d6370706010357i6c834192o91246519f7dfc062@mail.gmail.com>

Kent,

Your multistrip tid-bit worked perfectly. Thanks!

The reason why I didn't want the import solution is that I am learning
python because I want to parse text data. This problem was perfect practice.

Thanks for the links. I'll check them out. You don't happen to have any
parsing tutorials bookmarked somewhere do you? I'm already exploring
http://gnosis.cx/TPiP/. It's pretty heavy though.

Best,

Grant

On 6/1/07, Kent Johnson <kent37 at tds.net> wrote:
>
> Grant Hagstrom wrote:
> > Thanks for your help Alan.
> >
> > I found that when I used the code, it did returne a list but it is
> > riddled with formatting characters.
> > My question is, is it possible to strip out multiple characters at once?
>
> Yes, just pass multiple characters to strip(), e.g.
> line = line.strip('\r\n\t \'",')
>
> I'm curious why you don't like the import solution. exec and execfile()
> could also work although all three require that the file contain trusted
> data.
>
> Here are a couple of recipes that do almost what you want (you would
> still have to strip out the "jobs = " part:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/281056
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/ec20d191/attachment.html 

From alan.gauld at btinternet.com  Fri Jun  1 13:58:52 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 12:58:52 +0100
Subject: [Tutor] newbie: Reading text file
References: <440963.67763.qm@web86112.mail.ird.yahoo.com><4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com><465FF3F2.1050003@tds.net>
	<4257d6370706010357i6c834192o91246519f7dfc062@mail.gmail.com>
Message-ID: <f3p1n6$u24$1@sea.gmane.org>


"Grant Hagstrom" <grantahagstrom at gmail.com> wrote

> The reason why I didn't want the import solution is that I am 
> learning
> python because I want to parse text data. This problem was perfect 
> practice.

The best book on this topic is David Mertz' book Text Processing in
Python. The draft version is available online here:

http://gnosis.cx/TPiP/

You may well finde it helpful, however it is not a beginners book.


-- 
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 Jun  1 14:04:18 2007
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Fri, 1 Jun 2007 12:04:18 +0000 (GMT)
Subject: [Tutor] newbie: Reading text file
Message-ID: <174619.8683.qm@web86101.mail.ird.yahoo.com>

Grant,

> My question is, is it possible to strip out multiple characters at once? 

Kent answered that bit.

> started = False

> for line in file('mylist.py'):
>     if 'jobs' in line and not started:
> ...
>    if ']' not in line and started:
>        
jobs.append(line.strip('...'))
>    else: print "break"

Are you sure you only want to print break? If so the code will 
continue processing lines after the end of your list. My break 
command will exit the loop when it finds the ] character. If you 
don't want to use break you could set started to False again.


Alan G.




	
	
		
___________________________________________________________ 
New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes. 
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/30526897/attachment.htm 

From kent37 at tds.net  Fri Jun  1 14:04:46 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 01 Jun 2007 08:04:46 -0400
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <4257d6370706010356o2abd5058gb9f717ee78281477@mail.gmail.com>
References: <440963.67763.qm@web86112.mail.ird.yahoo.com>	
	<4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>	
	<465FF3F2.1050003@tds.net>
	<4257d6370706010356o2abd5058gb9f717ee78281477@mail.gmail.com>
Message-ID: <46600B5E.2090109@tds.net>

Grant Hagstrom wrote:

> Thanks for the links. I'll check them out. You don't happen to have any 
> parsing tutorials bookmarked somewhere do you? I'm already exploring 
> http://gnosis.cx/TPiP/. It's pretty heavy though.

For general text processing, you might want to browse the Text section 
of the Python Cookbook, either the printed version or online:
http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Text

Many text processing problems can be solved with the string methods or 
regular expressions and a simple state machine.
http://docs.python.org/lib/string-methods.html
http://www.amk.ca/python/howto/regex/

If the data structure is recursive or the number of possible states is 
more than a handful, you may want to use a parsing package. I recommend 
looking at at pyparsing or PLY. I have found both of them to be well 
documented and pretty easy to use. Links to these and many other Python 
parser packages here:
http://www.nedbatchelder.com/text/python-parsers.html

Kent

PS Please use reply all to reply to the list.

From dsh0105 at comcast.net  Fri Jun  1 16:25:17 2007
From: dsh0105 at comcast.net (dsh0105 at comcast.net)
Date: Fri, 01 Jun 2007 14:25:17 +0000
Subject: [Tutor] Design Question...
Message-ID: <060120071425.14235.46602C4D000D3AFA0000379B2213484373CACFCECF089C0B@comcast.net>

I'm doing the initial design for what will (hopefully) be something like a flash-card system. This is mostly a learning exercise, but I'm hoping the results will be at least usable. So my question is does this class design shown by the psudo-code below sound reasonable?


class Deck(Questions):
    """"Contains a set of questions, and provides information and utility functions for them
          methods:
          add_question(Question) -- Ads a question to the deck
          get_next() -- Returns the next question in the deck


   """"

From dsh0105 at comcast.net  Fri Jun  1 16:46:18 2007
From: dsh0105 at comcast.net (dsh0105 at comcast.net)
Date: Fri, 01 Jun 2007 14:46:18 +0000
Subject: [Tutor] Design Question
Message-ID: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>

I think I may have sent an incomplete version of this question a moment ago (sorry). Here is the complete question:

I'm designing something along the lines of a flash card program. It's mostly just an exercise in learning Python, but I'd like it to be at least marginally usable when I'm done. So I'm looking for comments/suggestions on the key pieces of the 
design: the questions and the flash card deck:
Psudo-code of current design:

class Deck():
	"""Provides managment and informational functions about a set of questions to be asked
		methods incldue:
		__init__(questions) -- takes a list of question and creates a new deck with these questions.
		add_question(self,question) -- Adds a question to the current deck
		remove_question(self,question) -- returns True if the question was removed, False otherwise
		get_question() -- Returns the next unanswered question in the deck
		get_stats() -- returns a tuple containing: number_asked, number_correct, number_remaining
                shuffle_deck() -- shuffles the order of the remaining questions.
		Deck Overrived the __len__ function so that the len returned is the number of questions in the deck."
		

class Question():
	"""Provides questions to be asked
	methods:
	__init__(self,question,answer) -- question string representing the question. 
								    answer can be a text string, a tupple (for multiple correct answers)
									or an object implementing an is_correct() method that returns a boolean
									
	check_answer(self,answer) -- tests to see if the answer is correct and returns a boolean 
	"""
									
									
Mostly I'm wondering, is this over-kill? The idea is to allow for the deck to be used for as wide a variety of purposes as possible. Also, I want to make it easy to write code that generates decks.  Is this design over-kill?

Any comments/suggestions welcome.

Thanks,

David

From broek at cc.umanitoba.ca  Fri Jun  1 17:23:27 2007
From: broek at cc.umanitoba.ca (Brian van den Broek)
Date: Fri, 01 Jun 2007 11:23:27 -0400
Subject: [Tutor] Design Question
In-Reply-To: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>
References: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>
Message-ID: <466039EF.2030403@cc.umanitoba.ca>

dsh0105 at comcast.net said unto the world upon 06/01/2007 10:46 AM:
> I think I may have sent an incomplete version of this question a moment ago (sorry). Here is the complete question:
> 
> I'm designing something along the lines of a flash card program. It's mostly just an exercise in learning Python, but I'd like it to be at least marginally usable when I'm done. So I'm looking for comments/suggestions on the key pieces of the 
> design: the questions and the flash card deck:
> Psudo-code of current design:
> 
> class Deck():
> 	"""Provides managment and informational functions about a set of questions to be asked
> 		methods incldue:
> 		__init__(questions) -- takes a list of question and creates a new deck with these questions.
> 		add_question(self,question) -- Adds a question to the current deck
> 		remove_question(self,question) -- returns True if the question was removed, False otherwise
> 		get_question() -- Returns the next unanswered question in the deck
> 		get_stats() -- returns a tuple containing: number_asked, number_correct, number_remaining
>                 shuffle_deck() -- shuffles the order of the remaining questions.
> 		Deck Overrived the __len__ function so that the len returned is the number of questions in the deck."
> 		
> 
> class Question():
> 	"""Provides questions to be asked
> 	methods:
> 	__init__(self,question,answer) -- question string representing the question. 
> 								    answer can be a text string, a tupple (for multiple correct answers)
> 									or an object implementing an is_correct() method that returns a boolean
> 									
> 	check_answer(self,answer) -- tests to see if the answer is correct and returns a boolean 
> 	"""
> 									
> 									
> Mostly I'm wondering, is this over-kill? The idea is to allow for the deck to be used for as wide a variety of purposes as possible. Also, I want to make it easy to write code that generates decks.  Is this design over-kill?
> 
> Any comments/suggestions welcome.
> 
> Thanks,
> 
> David
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

David,

I'd make Deck and Question subclass object so as to have new-style 
classes, as in:

class Deck(object):
     # code here

If you don't know about the difference between classic classes and 
new-style, you needn't worry about it for now. There are a number of 
ways in which new-style are better, though.

I also have a suggestion that you might want to think about after you 
get the basic functionality working. When I did something similar, I 
used the pickle module make my Questions persistent between sessions, 
and had each Question keep track of how many times it has been asked 
and correctly answered. I then had my Deck.get_question pick which 
Question to ask in a way that favoured both Questions that had been 
rarely asked, and those that had the highest error rates.

Best,

Brian vdB

From alan.gauld at btinternet.com  Fri Jun  1 20:12:34 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 19:12:34 +0100
Subject: [Tutor] Design Question...
References: <060120071425.14235.46602C4D000D3AFA0000379B2213484373CACFCECF089C0B@comcast.net>
Message-ID: <f3pnjt$ij4$1@sea.gmane.org>

<dsh0105 at comcast.net> wrote

> I'm doing the initial design for what will (hopefully) be something
> like a flash-card system. This is mostly a learning exercise,
> but I'm hoping the results will be at least usable.
> So my question is does this class design shown
> by the psudo-code below sound reasonable?

It depends on what other classes exit however some quick
comments:

> class Deck(Questions):

It ingherits from Questions - which is an odd name for a class,
they are usually singular. But...
Is a deck a type of Question? I'd expect it to be a kind of list
or maybe a stack (but Python lists support push/pop methods)

>    """"Contains a set of questions, and provides information
>         and utility functions for them

The questions should contain any utility functions that operate
on the question itself. but the deck should control the questions
as a group.

>          methods:
>          add_question(Question) -- Ads a question to the deck
>          get_next() -- Returns the next question in the deck

These look reasonable. How will the questions be sorted?
Will it be first in first out? Or last in first out?
Or is there a sorting criteria? If so does it need to
be modifiable? If so you might like to create an internal
method for sorting that can be hooked with a comparison
function.
How do you hold the current position so you know where
next is?

These are all design questions to think about.

But fundamentally your Deck interface looks good.

Other interfaces you might consider:

search for a question (by what key?)
count the questions - total, unasked, asked etc?
restart

Without knowing much about the rest of the system - and only
a vague concept of what a flash card is - I can't say much more.

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



From grantahagstrom at gmail.com  Fri Jun  1 21:21:13 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 14:21:13 -0500
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <174619.8683.qm@web86101.mail.ird.yahoo.com>
References: <174619.8683.qm@web86101.mail.ird.yahoo.com>
Message-ID: <4257d6370706011221p54c4c254t7bc87a009b4896a4@mail.gmail.com>

Alan,

Good point. Earlier I was trying to figure out how the script worked, and
having else: print "break" seemed to help with that. For example, in one
version that I was tinkering with, break was printed 17 times. In the
current version, break is printed twice.

hope that makes sense,

Grnat

On 6/1/07, ALAN GAULD <alan.gauld at btinternet.com> wrote:
>
> Grant,
>
> > My question is, is it possible to strip out multiple characters at once?
>
>
> Kent answered that bit.
>
> > started = False
> > for line in file('mylist.py'):
> >     if 'jobs' in line and not started:
> > ...
> >    if ']' not in line and started:
> >        jobs.append(line.strip('...'))
> >    else: print "break"
>
> Are you sure you only want to print break? If so the code will
> continue processing lines after the end of your list. My break
> command will exit the loop when it finds the ] character. If you
> don't want to use break you could set started to False again.
>
> Alan G.
>
> ------------------------------
> New Yahoo! Mail is the ultimate force in competitive emailing. Find out
> more at the Yahoo! Mail Championships<http://uk.rd.yahoo.com/mail/uk/taglines/gmail_com/championships/games/*http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk/>.
> Plus: play games and win prizes.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/b4dc6176/attachment.html 

From alan.gauld at btinternet.com  Fri Jun  1 20:23:38 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 19:23:38 +0100
Subject: [Tutor] Design Question
References: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>
Message-ID: <f3po8k$krl$1@sea.gmane.org>


<dsh0105 at comcast.net> wrote

>I think I may have sent an incomplete version of this question

Indeed and I andswered it! :-)

> So I'm looking for comments/suggestions on the key pieces of the
> design: the questions and the flash card deck:
> Psudo-code of current design:
>
> class Deck():

Better, no longer derived from Question.

> """Provides managment and informational functions about
> a set of questions to be asked methods incldue:
> __init__(questions) -- takes a list of question and creates a new 
> deck with these questions.

Fine

> add_question(self,question) -- Adds a question to the current deck

Fine

> remove_question(self,question) -- returns True if the question
> was removed, False otherwise

Doesn't sound like, better to use a question style name like
is_removed(question)

But I'd ask how the deck would know? Does it keep a record
of all questions it ever stored? Or should the question be
storing its own status? I'm not sure how flash cards work
so either answer could be right.

> get_question() -- Returns the next unanswered question in the deck

Fine

> get_stats() -- returns a tuple containing: number_asked, 
> number_correct, number_remaining

Fine

>                shuffle_deck() -- shuffles the order of the remaining 
> questions.

OK, see my other reply about ordering and keepingtrack of
current position etc.

> Deck Overrived the __len__ function so that the len returned
> is the number of questions in the deck."

Good idea!

> class Question():

Better, no longer plural

> """Provides questions to be asked
> methods:
> __init__(self,question,answer) -- question string representing the 
> question.
>     answer can be a text string, a tupple (for multiple correct 
> answers)
> or an object implementing an is_correct() method that returns a 
> boolean

Fine although handling those different answers might be easier
done using inheriance with 3 different subclasses of question
and a check_answer method over-ridden in each.

> check_answer(self,answer) -- tests to see if the answer is
> correct and returns a boolean

If its a boolean the method could be called is_correct instead. think 
of how the client cpdfe will read:

if q.check_answer(ans): ...

or

if q.is_correct(ans): ...

personally I prefer the second style. But it is personal.

> Mostly I'm wondering, is this over-kill? The idea is to allow for
> the deck to be used for as wide a variety of purposes as possible.

Doesn't look overkill, but I don;t know enough to be sure.
It could be done with basic python types and a couple of
functions I suspect. But if you want to add features an OOP
design may well pay off.

Can you write a really basic version without OOP?
Or maybe write the Question class first and store them in a
basic list? Then add the deck once you have the question worked out?

> Also, I want to make it easy to write code that generates decks.

I'm not sure what that means in practice? Isn't that what your init 
does?

HTH,

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



From Mike.Hansen at atmel.com  Fri Jun  1 21:55:43 2007
From: Mike.Hansen at atmel.com (Mike Hansen)
Date: Fri, 1 Jun 2007 13:55:43 -0600
Subject: [Tutor] Design Question
In-Reply-To: <f3po8k$krl$1@sea.gmane.org>
References: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>
	<f3po8k$krl$1@sea.gmane.org>
Message-ID: <57B026980605A64F9B23484C5659E32E852031@poccso.US.ad.atmel.com>

> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Alan Gauld
> Sent: Friday, June 01, 2007 12:24 PM
> To: tutor at python.org
> Subject: Re: [Tutor] Design Question
> > remove_question(self,question) -- returns True if the question
> > was removed, False otherwise
> 
> Doesn't sound like, better to use a question style name like
> is_removed(question)
> 

Would it be better to have remove_question remove the question or raise
an exception if it can't remove the question? Then you'd put the call to
remove question in a try except block.

Mike

From carroll at tjc.com  Fri Jun  1 22:33:20 2007
From: carroll at tjc.com (Terry Carroll)
Date: Fri, 1 Jun 2007 13:33:20 -0700 (PDT)
Subject: [Tutor] Starting with wxPython
In-Reply-To: <f2v92i$po4$1@sea.gmane.org>
Message-ID: <Pine.LNX.4.44.0706011329420.21101-100000@violet.rahul.net>

On Tue, 22 May 2007, Alan Gauld wrote:

> "Alan Gilfoy" <agilfoy at frontiernet.net> wrote
> 
> > soon, and I plan to use wxPython to do so. What, do you think, is 
> > the best tutorial out there for wxPython?
> 
> I'm working through the new wxPython book and highly recommend
> it. 

I second that.  I've used Tkinter for a few years, mostly because the docs 
on it are good.  I looked at wxPython, but there was no good vehicle for 
learning it, and I gave up.

When the wxPython book came out, I borrowed a copy from the Library (hint: 
even if your library doesn't have it, it can probably get it for you via 
Inter-Library Loan) and read it.  I liked it enough to go and buy my own 
copy as a reference after returning it.

I'm now planning on my next GUI app to be wxPython-based.


From nswitanek at stanford.edu  Sat Jun  2 00:18:44 2007
From: nswitanek at stanford.edu (Switanek, Nick)
Date: Fri, 1 Jun 2007 15:18:44 -0700
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <mailman.51.1180692015.6469.tutor@python.org>
References: <mailman.51.1180692015.6469.tutor@python.org>
Message-ID: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5D1@gsb-exchmb02.stanford.edu>

Hi Alan,

Your excitement for the PyCrust IDE made me want to check it out, but
after downloading wxPython and the "Docs and Demos" at
http://www.wxpython.org/download.php#prerequisites
I've not been able to find an IDE to launch. Can you explain what I need
to do?

Thanks,
Nick

From hieu.d.hoang at gmail.com  Sat Jun  2 00:42:11 2007
From: hieu.d.hoang at gmail.com (=?UTF-8?Q?Hi=E1=BA=BFu_Ho=C3=A0ng?=)
Date: Sat, 2 Jun 2007 05:42:11 +0700
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5D1@gsb-exchmb02.stanford.edu>
References: <mailman.51.1180692015.6469.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5D1@gsb-exchmb02.stanford.edu>
Message-ID: <4f12b0dd0706011542j62fa8f8ay2436d7792295be2d@mail.gmail.com>

Hi Nick,

Installing wxPython on Windows creates a Scripts folder, in which the
goodies like PyCrust and Pyalamos are installed, you can run it and be
good to go.
On *nix, the scripts would be installed in the prefix's bin dir,
hopefully all starting with py :-)

The PyCrust is a better python shell (than the defacto one and the one
in IDLE), not quite a full blown IDE. I know of the SPE by Stani at
<http://pythonide.blogspot.com/> that use PyCrust, but I'm not aware
of any other one.

HTH,
Hieu

From alan.gauld at btinternet.com  Sat Jun  2 00:41:55 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 1 Jun 2007 23:41:55 +0100
Subject: [Tutor] PyCrust IDE/Shell
References: <mailman.51.1180692015.6469.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5D1@gsb-exchmb02.stanford.edu>
Message-ID: <f3q7ct$8io$1@sea.gmane.org>


"Switanek, Nick" <nswitanek at stanford.edu> wrote

> Your excitement for the PyCrust IDE made me want to check it out, 
> but
> after downloading wxPython and the "Docs and Demos" at
> http://www.wxpython.org/download.php#prerequisites
> I've not been able to find an IDE to launch.

PyCrust is part of the Py component set that is bundled with wxPython.

You will find it here:

{PYTHON}\Lib\site-packages\wx-2.8-msw-ansi\wx\py\PyCrust.pyw

On Windows just drag the file onto the start menu (or desktop)
and the file assoiciation mechanism should start it up for you.

Alan G. 



From grantahagstrom at gmail.com  Sat Jun  2 00:47:11 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 17:47:11 -0500
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <f3op5d$uv7$1@sea.gmane.org>
References: <f3op5d$uv7$1@sea.gmane.org>
Message-ID: <4257d6370706011547v40332432p6cdabf372646661b@mail.gmail.com>

I agree that pycrust is faster in terms of autocomplete. However, I love
being able to to just hit f5 to run my code in the shell while in the Python
IDLE environment. I wonder if this is possible with pycrust . . .

. . . on the wxPython page I found a list of other py related programs:

http://www.wxpython.org/py.php

   - PyAlaCarte
   - PyAlaMode
   - PyCrust
   - PyFilling
   - PyShell
   - PyWrap

The most interesting to me is pywrap: "PyWrap is a runtime utility that lets
you run an existing wxPython program with a PyCrust frame at the same time.
Inside the PyCrust shell namespace, the local variable app is assigned to
your application instance. In this way you can introspect your entire
application within the PyCrust shell, as well as the PyFilling namespace
viewer."

Has anyone tried any of these yet?

- Grant

On 6/1/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> Is anyone else out there using PyCrust as their python shell?
>
> I've been using it for a few weeks now and I'm completely sold.
> It is the best shell I've used, everything just seems to work.
> I can cut n paste sections of interpreter code and PyCrust
> correctly strips out the prompts and organises things. The
> tooltips and autocomplete work better than IDLE or pythonwin.
> There are no indentation problems like on IDLE. The namespace
> viewer and other tools are genuinely useful.
>
> I haven't tried the other Py tools yet - A La Mode seems the
> obvious next step with its multi tabbed editors. But the beauty
> of PyCrust is that it works beautifully with vim (or anything
> else that can cut n paste)
>
> Any other users got PyCrust tiposthey can share?
>
> 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/20070601/ed1d8c66/attachment.html 

From nswitanek at stanford.edu  Sat Jun  2 01:10:21 2007
From: nswitanek at stanford.edu (Switanek, Nick)
Date: Fri, 1 Jun 2007 16:10:21 -0700
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <4f12b0dd0706011542j62fa8f8ay2436d7792295be2d@mail.gmail.com>
References: <mailman.51.1180692015.6469.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5D1@gsb-exchmb02.stanford.edu>
	<4f12b0dd0706011542j62fa8f8ay2436d7792295be2d@mail.gmail.com>
Message-ID: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5E8@gsb-exchmb02.stanford.edu>

Hi Hieu,

In my Scripts folder there are MS-DOS batch files and files without extensions that include "pycrust" and "pyalamode". Double-clicking either version of pycrust in this folder doesn't do anything I can see. There are no .py files (apart from CreateBatchFiles.py and CreateMacScripts.py, which creates the MS-DOS batch files from the extension-less files), so how should I run pycrust?

Thanks in advance for any further help you can provide.

Nick




-----Original Message-----
From: Hi?u Ho?ng [mailto:hieu.d.hoang at gmail.com] 
Sent: Friday, June 01, 2007 3:42 PM
To: Switanek, Nick
Cc: tutor at python.org
Subject: Re: [Tutor] PyCrust IDE/Shell

Hi Nick,

Installing wxPython on Windows creates a Scripts folder, in which the
goodies like PyCrust and Pyalamos are installed, you can run it and be
good to go.
On *nix, the scripts would be installed in the prefix's bin dir,
hopefully all starting with py :-)

The PyCrust is a better python shell (than the defacto one and the one
in IDLE), not quite a full blown IDE. I know of the SPE by Stani at
<http://pythonide.blogspot.com/> that use PyCrust, but I'm not aware
of any other one.

HTH,
Hieu

From nswitanek at stanford.edu  Sat Jun  2 01:17:17 2007
From: nswitanek at stanford.edu (Switanek, Nick)
Date: Fri, 1 Jun 2007 16:17:17 -0700
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <mailman.28132.1180738037.32030.tutor@python.org>
References: <mailman.28132.1180738037.32030.tutor@python.org>
Message-ID: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5ED@gsb-exchmb02.stanford.edu>

Hi Alan,

Thanks for the path. I find a .py, .pyc, and an icon file name PyCrust,
but no .pyw. 

Any ideas?

Thanks,
Nick

From grantahagstrom at gmail.com  Sat Jun  2 01:33:20 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 18:33:20 -0500
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5ED@gsb-exchmb02.stanford.edu>
References: <mailman.28132.1180738037.32030.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5ED@gsb-exchmb02.stanford.edu>
Message-ID: <4257d6370706011633n6c9e4eb3sea7d497efff3bebc@mail.gmail.com>

Nick,

Have you tried copying the contents of PyCrust.py into your current IDLE?
Running that script will cause PyCrust to open on my machine. Perhaps this
is a start . . .

- Grant

On 6/1/07, Switanek, Nick <nswitanek at stanford.edu> wrote:
>
> Hi Alan,
>
> Thanks for the path. I find a .py, .pyc, and an icon file name PyCrust,
> but no .pyw.
>
> Any ideas?
>
> Thanks,
> Nick
> _______________________________________________
> 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/20070601/39babe33/attachment.htm 

From nswitanek at stanford.edu  Sat Jun  2 01:52:46 2007
From: nswitanek at stanford.edu (Switanek, Nick)
Date: Fri, 1 Jun 2007 16:52:46 -0700
Subject: [Tutor] PyCrust IDE/Shell
In-Reply-To: <4257d6370706011633n6c9e4eb3sea7d497efff3bebc@mail.gmail.com>
References: <mailman.28132.1180738037.32030.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5ED@gsb-exchmb02.stanford.edu>
	<4257d6370706011633n6c9e4eb3sea7d497efff3bebc@mail.gmail.com>
Message-ID: <21EB45BA6A0A4844B97D46A7721CFDF203A2A5FE@gsb-exchmb02.stanford.edu>

Thanks for this suggestion, Grant, it might prove illuminating. 

 

I got this import error when I tried running PyCrust.py from within
PythonWin (version 2.5). 

 

"ImportError: Module use of python24.dll conflicts with this version of
Python."

 

I also have previous versions of python installed, so maybe there is
some confusion there? If so, I'd be grateful for help understanding what
I need to do to resolve it.

 

Thanks,

Nick

 

 

________________________________

From: Grant Hagstrom [mailto:grantahagstrom at gmail.com] 
Sent: Friday, June 01, 2007 4:33 PM
To: Switanek, Nick
Cc: tutor at python.org
Subject: Re: [Tutor] PyCrust IDE/Shell

 

Nick,

Have you tried copying the contents of PyCrust.py into your current
IDLE? Running that script will cause PyCrust to open on my machine.
Perhaps this is a start . . .

- Grant

On 6/1/07, Switanek, Nick <nswitanek at stanford.edu> wrote:

Hi Alan,

Thanks for the path. I find a .py, .pyc, and an icon file name PyCrust,
but no .pyw.

Any ideas?

Thanks,
Nick
_______________________________________________
Tutor maillist  -   Tutor at python.org <mailto: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/20070601/b6b7f367/attachment.html 

From bradleytompkins at gmail.com  Sat Jun  2 05:59:57 2007
From: bradleytompkins at gmail.com (Brad Tompkins)
Date: Fri, 1 Jun 2007 20:59:57 -0700
Subject: [Tutor] Launch external application?
Message-ID: <f1b5123f0706012059t1e9da960oa2ff5176e902da85@mail.gmail.com>

Is there an easy way to make a python script that will launch an external
application for me ?  I'm using Windows XP and I'm trying to create a little
front end that will launch the VLC media player for me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/cf978041/attachment.htm 

From grantahagstrom at gmail.com  Sat Jun  2 06:12:48 2007
From: grantahagstrom at gmail.com (Grant Hagstrom)
Date: Fri, 1 Jun 2007 23:12:48 -0500
Subject: [Tutor] Launch external application?
In-Reply-To: <f1b5123f0706012059t1e9da960oa2ff5176e902da85@mail.gmail.com>
References: <f1b5123f0706012059t1e9da960oa2ff5176e902da85@mail.gmail.com>
Message-ID: <4257d6370706012112uab858acr6b0e0c46f8d92bed@mail.gmail.com>

Brad,

I believe that this will work . . .

import os
os.system(your_exe.exe)

in my case the following code opens the nautilus file browser

import os
os.system('nautilus')

best of luck,

Grant

On 6/1/07, Brad Tompkins <bradleytompkins at gmail.com> wrote:
>
> Is there an easy way to make a python script that will launch an external
> application for me ?  I'm using Windows XP and I'm trying to create a little
> front end that will launch the VLC media player for me.
>
> _______________________________________________
> 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/20070601/b0f32506/attachment.html 

From jped.aru at gmail.com  Sat Jun  2 07:52:52 2007
From: jped.aru at gmail.com (Adam Urbas)
Date: Sat, 2 Jun 2007 00:52:52 -0500
Subject: [Tutor] Calculator research
Message-ID: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com>

Sup all,

Ok, this is my research for a better calculator.  I want to make a
calculator that is much less lame than the one that comes standard
with windows.  If anyone has any ideas for how to start or some things
I should know, then feel free to inform me.  The truth is, I don't
exactly know where to start.  I'm not yet though, I'm still working on
that area calculation thing, which I intend to be a part of the
calculator.

Also, I'd like to know how to make my program have visual qualities,
like the standard calculator.  I assume that this is either impossible
or very advanced/difficult, considering I have not previously heard
anything about it.  It doesn't have to be a visual display, though,
just was wondering how to go about doing it and thought this might be
the program to try it out on.

Thanks,
Au

From jped.aru at gmail.com  Sat Jun  2 08:01:13 2007
From: jped.aru at gmail.com (Adam Urbas)
Date: Sat, 2 Jun 2007 01:01:13 -0500
Subject: [Tutor] [Fwd: Re: trouble with "if"]
In-Reply-To: <f3kp0l$dtq$1@sea.gmane.org>
References: <465CFE46.50900@cc.umanitoba.ca>
	<6faf39c90705292353g9c66286qa4e723cd33d64fb8@mail.gmail.com>
	<ef52818c0705300801x2332afcm6c51babc6eee460@mail.gmail.com>
	<465D968C.5060205@cc.umanitoba.ca>
	<ef52818c0705301038na8b49echa9ca00dd884f1f06@mail.gmail.com>
	<ef52818c0705301045j496a3fa5v8a7d0f4686fcc060@mail.gmail.com>
	<ef52818c0705301049u2b3913bat20555125a20510b0@mail.gmail.com>
	<f3kp0l$dtq$1@sea.gmane.org>
Message-ID: <ef52818c0706012301yd1c25e7idab0a92a5313c36@mail.gmail.com>

Sorry about all that trouble for you Alan, after I posted that, I
reformatted my code a bit and updated it to do the defining and then
the calling, like you said.  The only problem I had, and I was
probably doing something wrong, was that I would do:

choice()
if choice in["1","circle"]:
    circle()

and it wouldn't actually go to circle().  So I had to put the if
statement somewhere else, can't remember where it was right now and
don't have time to find out, because I really need to be getting off
of here.

Thanks for the advice, and if you could, would you mind explaining the
global variable thing a little more, because I kept getting an error
message that was saying something to the effect that the global
variable was not defined.

Thanks,

Au

On 5/30/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
> Hi Adam
>
> > flaw in my loop.  It is not infinite.
>
> In fact you don't have a loop, your program
> is really just a simple sequence.
>
> #Welcome screen:
> def welcome():
>     print "Welcome to the Area Calculation Program."
>     print
>
> welcome()
>
> AG:Since you only call this once there is no point in putting
> AG: it in a functuion
>
> #Shape choice:
> def shape():
>     print "Choose a Shape:"
>     print "1 Circle"
>     print "2 Square"
>     print "3 Triangle"
>     print "4 Exit"
>     print
>
> shape()
>
> AG: And you call this here and again at the end of the code.
> AG: But its not in a loop, its just two calls to the same function.
>
> #If circle:
> def circle():
>     shape=raw_input(">")
>     if shape in["1","circle"]:
>         print "1 Radius"
>         print "2 Diameter"
>         print "3 Circumference"
>         print "4 Area"
>         print
>
> circle()
>
> AG: And this gets a string fom the user and prints one of the
> AG: values but doesn't do anything with it. Functions should
> AG: normally do more than just print some values.
> AG: You never use the menu you print.
>
> #If radius:
> def radius():
>     radius=int(raw_input("Enter Radius:"))
>     diameter=(radius*2)
>     circumference=(diameter*3.14)
>     area=(radius**2*3.14)
>     print "Diameter",diameter
>     print "Circumference",circumference
>     print "Area",area
>     print
>     print
>
> def choice():
>     given=raw_input(">")
>     if given in["1","radius"]:
>         radius()
> choice()
>
> AG: Now you call radius which actually does some work
>
> shape()
> choice()
>
> AG: Then you call shape but don't use the result then call
> AG: choice which only works for circles.
>
> AG:If we use the more conventional approach of defining the
> AG: functins first then calling them at the end your code
> AG: looks like this:
>
>
> welcome()
> shape()
> circle()
> choice()  #--> which calls radius()
> shape()
> choice()
>
> As you see there is no loop just a sequence of function calls.
>
> Now if I rename your functions to reflect what theyactually do:
>
> printWelcomeMessage()
> printShapeMenu()
> getShapeAndIfCirclePrintCircleParameterNames()
> getParameterAndIfRadiuscallRadius()
> -----> getRadiusCalculateResultsAndPrintThem()
> printShapeMenu()
> getParameterAndIfRadiuscallRadius()
> -----> getRadiusCalculateResultsAndPrintThem()
>
> Hopefully this illustrates several things:
> 1) Naming your functions to reflect what they actually do
> helps see what the code does
> 2) Especially if you group the function calls together at the
> end of your program
> 3) Your functions are mixing up the presentation of menus
> and the getting of values.
>
> A better structure might be to do something like:
>
> shape = 0       # a variable to store the shape
> printWelcomeMessage()
> printShapeMenuAndGetValue()  #---store he result in the shape variable
> if shape in['1','circle']:
>     doAllCircleStuff()
> else: print "Only circles supported for now!"
>
> And then its easy to wrap that in a real loop
>
> shape = 0       # a variable to store the shape
> printWelcomeMessage()
> while shape == 0:
>    printShapeMenuAndGetValue()  #---store he result in the shape
> variable
>    if shape in['1','circle']:
>       doAllCircleStuff()
>       shape = 0     # reset shape back to zero
>    else: print "Only circles supported for now!"
>
> Can you rewrite your functions to match that? You need to change
> the shape() function so that it sets the shape global variable to the
> value input by the user. You will need to include the statement
> global shape at the top of the function for that to work. The other
> (and better) way is to use the return statement to return the value.
>
> BTW I'm not really suggesting you use those long names,
> they were just to point out what the functions were really doing!
>
> HTH,
>
> Alan G.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From rabidpoobear at gmail.com  Sat Jun  2 09:17:26 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Sat, 02 Jun 2007 02:17:26 -0500
Subject: [Tutor] [Fwd: Re: trouble with "if"]
In-Reply-To: <ef52818c0706012301yd1c25e7idab0a92a5313c36@mail.gmail.com>
References: <465CFE46.50900@cc.umanitoba.ca>	<6faf39c90705292353g9c66286qa4e723cd33d64fb8@mail.gmail.com>	<ef52818c0705300801x2332afcm6c51babc6eee460@mail.gmail.com>	<465D968C.5060205@cc.umanitoba.ca>	<ef52818c0705301038na8b49echa9ca00dd884f1f06@mail.gmail.com>	<ef52818c0705301045j496a3fa5v8a7d0f4686fcc060@mail.gmail.com>	<ef52818c0705301049u2b3913bat20555125a20510b0@mail.gmail.com>	<f3kp0l$dtq$1@sea.gmane.org>
	<ef52818c0706012301yd1c25e7idab0a92a5313c36@mail.gmail.com>
Message-ID: <46611986.2070700@gmail.com>

Adam Urbas wrote:
> Sorry about all that trouble for you Alan, after I posted that, I
> reformatted my code a bit and updated it to do the defining and then
> the calling, like you said.  The only problem I had, and I was
> probably doing something wrong, was that I would do:
>
> choice()
> if choice in["1","circle"]:
>     circle()
>
> and it wouldn't actually go to circle().  So I had to put the if
> statement somewhere else, can't remember where it was right now and
> don't have time to find out, because I really need to be getting off
> of here.
>
> Thanks for the advice, and if you could, would you mind explaining the
> global variable thing a little more, because I kept getting an error
> message that was saying something to the effect that the global
> variable was not defined.
>
> Thanks,
>
> Au

Adam -
Please realize that I mean this in the nicest way possible, and that 
everyone in this mailing list wishes to see you succeed in all your 
programming endeavors.
Having prefaced with that disclaimer, I must implore that you take 
further steps in your study of basic programming concepts.
While we would love to (and the name of the mailing list seems to imply 
that we do) take every individual from the level of beginner through to a
bona-fide pythonista with personal instruction, there simply isn't 
enough time to do that.
That applies to you as well; while every question you ask seems to get 
you a reply that fixes your problem,
you'll find that you'll continue to run into problems indefinitely.
And if every problem you ever face has a 5-hour delay before you get a 
solution, you'll find your progress to be agonizingly slow.

I would suggest that you consider what you can accomplish with 
programming, and whether you would like to continue to delve into it.
If you decide to, you'll need to take the time to read through more 
tutorials.
In addition to that, you should do any example programs they give you!
(Ideally) the examples in a tutorial will immediately apply the 
knowledge you just gained from reading that section of the tutorial,
and

I know it seems counter-intuitive to go abandon work on a program that 
is doing something useful to you to work on a program that
has no bearing on what you're trying to accomplish (as you would in a 
tutorial), but I truly believe it would be for the better in the long run.

An example of this:

These are the basics of the syntax of a function:
1. a function takes in n arguments (where n is any number, even 0) where 
any of them could have default values.
2. a function is defined by the "def" keyword, followed by the function 
name, then a parenthetical list of all arguments the function takes in 
(or empty parenthesis
if the function takes no arguments), where all of the arguments are 
separated by commas, followed by a colon.
3. the next line of code is indented at least 1 space or 1 tab, and all 
subsequent lines that are indented at the same level or further will be 
part of the function, until there is a line with less indentation.  If 
any lines are indented further than the first line, they must be part of 
another code block ( a function, a loop, a statement, a class, etc.) for 
their indentation to be valid.

you can learn these things by trial and error, but a tutorial will 
explain why all of these are necessary.
If you understand why they are necessary, it will be easier to remember 
them.
for part 1, a function taking arguments, you must understand the purpose 
of a function.

Suppose we had code that calculated the sum of an arithmetic sequence 
(for example 1,2,3,4,5,6,7,8,9,10)
There are many ways to solve this, but the easiest way is to use a 
formula for the sum of an arithmetic sequence.
one such formula is   total sum = half the number of terms in the 
sequence multiplied by the addition of the first and last terms.
In this particular example, this would be 5 * (1 + 10).  The 5 comes 
from the fact that there are 10 terms.
Now when programming this, assuming we know the values of the sequence, 
we could just do
sum = 5 * (1+10)

or even precompute this
sum= 55

but what do we do if we don't know the values in the sequence beforehand?
Say the user inputs the values for the list, and we end up with this list
seq = [1,2,3,4,5,6,7,8,9,10]

We want to know what the sum of it is without having to know what the 
list itself is.
We can use the formula to keep this process abstract, so that the 
solution will work with any sequence of length 10:
sum = ( 10 / 2.0 ) * (seq[0] + seq[9])

Now why all the parenthesis?
That's because of the order of operations.
This is the first part where you'd need advance knowledge to solve the 
problem.
The solution seems trivial looking at it, but if you didn't know that 
the multiplication would take
effect before the addition without the right set of parenthesis, you 
might not even notice, until you needed to use this
value for something and found it to be incorrect.
The order of operations is one thing that you will learn in a tutorial.
Another is that computers index lists starting from 0, not from 1, so 
seq[1] + seq[10] would create an error.

Now what if we want to generalize this further, so that it will work 
with a sequence of any length?
sum = ( len(seq) / 2.0) * (seq[0] + seq[-1])
More things we knew from before: len( some_list) will give you the 
length of the list,  some_list[-1] will give you the last element of the 
list.

Okay, that's handy, but do we really want to copy and paste this after 
every list that we need the sum of?
and if the list is named something else, like 'foobar', we'd have to go 
change all the 'seq's to 'foobar's.
There must be a better way...
and there is!

This brings us to functions.
What we want is a device that will accept any sequence we throw at it 
and give us back whatever the sum is.
It doesn't need to be concerned with how we arrived with the sequence, 
or what we're going to use the sum,
or even where we're going to store the sum.
Think of it like a meat grinder.  We put meat in, and out comes little 
tubes of processed meat at the other end.
It performs a simple task on input which results in output.

What we want our device to input is a sequence, and what we want it to 
output is a sum.
The manner in which we define functions, which was enumerated above, 
starts with a 'def',
which tells python "hey, we're about to define a function!"  followed by 
the function name,
in this case addSequence (we aren't calling it 'sum' because there is 
already a function called 'sum',
and if we call our function 'sum' also, the other 'sum' will no longer 
be accessible) followed by a list of the arguments
(in this case just the sequence name) and finally a colon.
this looks like the following:
def addSequence(seq):

now we are inside the function, so we want to indent our code a bit...
    sum = ( len(seq) / 2.0) * (seq[0] + seq[-1])

and now that we have this value, we want to give it back to whoever 
called the function.
we can do this by using the 'return' keyword.
    return sum

note that that line is indented just as far as the previous line is, 
because they are both part of the same function (addSequence.)

now that we have this function, any time we need the sum of a sequence,
say
foo = [1,2,3,4,5]
bar = [6,7,8,9,10]
foobar = [1,2,3,4,5,6,7,8,9,10]

we can simply pass these values to our function, and store the sum in a 
variable.
foo_sum = addSequence(foo)
bar_sum = addSequence(bar)
foobar_sum = addSequence(foobar)

note that all of these calls to addSequence have a different name.
Specifically, none of them are named 'seq'.
This is because inside of our function definition above, anytime we say 
'seq' we are really referring to the value that was passed
into our function.  'seq' is just another name for 'foo', or for 'bar', 
or for whatever other sequence we happen to have called addSequence with.

The reason I presented this to you was to make it evident that even a 
simple problem, like summing an arithmetic sequence, can be solved in
many ways, and that by learning important things like functions and 
if-statements and loops before you begin writing your own programs,
you will be able to see many of the possible ways to use code to solve a 
particular program, and hopefully which method would be best in your 
situation.
Now I believe that writing your own programs to do what you want is 
definitely a great way to learn,
but it is paramount that you understand the basics before you move onto 
that stage,
and while it is possible to puzzle them out yourself, I strongly suggest 
you don't try to.

I hope this helped you to see the logical process by which we solve 
problems,
and why it's necessary to spend the up-front time to get all of this 
general knowledge into your head about the syntax of the programming 
language, as well as problem-solving patterns that are commonly used.
So while you may certainly continue to ask questions here, and the nice 
folks will continue to answer your questions,
what we all are really hoping is that some day you won't have to.
and I believe the best way for you to get to this point is to work 
through various tutorials (obligatory recommendation of Alan's tutorial 
goes here)
and ask us questions if you get stuck with those.
But really, experimenting within the constraints of the tutorial, to 
begin, will help you to see common problems and things
that frustrate people, and the manner in which to work around them.  
Also, if you're working through a tutorial,
as opposed to learning it by persistence, we will know at what point you 
are, and what you've previously learned,
which will greatly enable us to give you better advice on finding a 
solution than we are now able to.

I apologize for what appears to have turned into a rant, and I hope you 
can find some value in it, Adam.
-Luke




From alan.gauld at btinternet.com  Sat Jun  2 10:03:32 2007
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Sat, 2 Jun 2007 08:03:32 +0000 (GMT)
Subject: [Tutor] PyCrust IDE/Shell
Message-ID: <278204.43849.qm@web86102.mail.ird.yahoo.com>

> I agree that pycrust is faster in terms of autocomplete. However, 
> I love being able to to just hit f5 to run my code in the shell while 
> in the Python IDLE environment. I wonder if this is possible with pycrust . . .

Not PyCrust itself because it is just a shell.
But PyA LaMode is the equivalent of IDLE with multi file editing 
as well as the PyCrust shell. And it should have an equivalent to F5.

> The most interesting to me is pywrap: "PyWrap is a runtime utility that 
> lets you run an existing wxPython
program with a PyCrust frame 

Yes, the wxPython book gives an example of how to do that as well 
as discussing each of the Py components.


Alan G




      ______________________________________________________
Yahoo! Mail now has unlimited storage, which means you can have spam control and more space for those important e-mails.
http://uk.mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070602/65b9232f/attachment.htm 

From project5 at redrival.net  Sat Jun  2 10:18:02 2007
From: project5 at redrival.net (Andrei)
Date: Sat, 02 Jun 2007 10:18:02 +0200
Subject: [Tutor] Calculator research
In-Reply-To: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com>
References: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com>
Message-ID: <f3r93b$dnr$1@sea.gmane.org>

Hi Adam,

> Ok, this is my research for a better calculator.  I want to make a
> calculator that is much less lame than the one that comes standard
> with windows.  If anyone has any ideas for how to start or some things

A very simple option would be to just call eval() - you get the full 
power of Python at basically no cost. The downside is that you get the 
full power of Python, meaning your calculator could be used for 
'dangerous' things. Depending on your target audience, that may or may 
not be an issue.

> Also, I'd like to know how to make my program have visual qualities,
> like the standard calculator.  I assume that this is either impossible
> or very advanced/difficult, considering I have not previously heard

You mean a GUI, right? It's more difficult than plain CLI, but it's not 
really difficult. Google for wxPython and wxGlade - you can design your 
interface in a point-and-click manner. You will need to learn a bit 
about wxPython in the process, but don't have to become an expert.

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info:
''.join([''.join(s) for s in zip(
"poet at aao.l pmfe!Pes ontuei ulcpss  edtels,s hr' one oC.",
"rjc5wndon.Sa-re laed o s npbi ot.Ira h it oteesn edt C")])


From alan.gauld at btinternet.com  Sat Jun  2 10:20:52 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 2 Jun 2007 09:20:52 +0100
Subject: [Tutor] PyCrust IDE/Shell
References: <mailman.28132.1180738037.32030.tutor@python.org>
	<21EB45BA6A0A4844B97D46A7721CFDF203A2A5ED@gsb-exchmb02.stanford.edu>
Message-ID: <f3r9af$e87$1@sea.gmane.org>


"Switanek, Nick" <nswitanek at stanford.edu> wrote


> Thanks for the path. I find a .py, .pyc, and an icon file name 
> PyCrust,
> but no .pyw.
>
> Any ideas?

Sorry, I think I did this bit myself.

Just rename the .py to .pyw

The effect is to prevent a Windows console window starting
in the background. I forgot I'd done that!

Alan G. 



From norman at khine.net  Sat Jun  2 10:29:32 2007
From: norman at khine.net (Norman Khine)
Date: Sat, 02 Jun 2007 10:29:32 +0200
Subject: [Tutor] Running two different python applications from one module
Message-ID: <46612A6C.6020305@khine.net>

Hello,
I would like to write a script using python 2.5 to interact with a Zope
application that is running on python 2.4.3

Can I call the python 2.4.3 module from within the python 2.5, if so how?

For example, my script is in /home/me/python2.4/create.py

and within my /home/me/python2.5/servers.py

When running server.py I would like to run the create.py and then
continue with my application in the python2.5

Can someone show me an example from the interpreter or as a module that
does this.

Hope this makes sense ;)

Many thanks

Norman



From alan.gauld at btinternet.com  Sat Jun  2 10:25:02 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 2 Jun 2007 09:25:02 +0100
Subject: [Tutor] Calculator research
References: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com>
Message-ID: <f3r9i9$eoi$1@sea.gmane.org>


"Adam Urbas" <jped.aru at gmail.com> wrote

> Ok, this is my research for a better calculator.  I want to make a
> calculator that is much less lame than the one that comes standard

Thats a good beginners project. But you should go through
one of the tutorials first because you are still asking a lot of
very basic questions. A few hours going through the
rudimentary things will speed up your project a lot.

> Also, I'd like to know how to make my program have visual qualities,
> like the standard calculator.

I assume you want it to have a GUI fron end with buttons etc?
Yes thats possible and my tutorial includes a topic to get you
started plus some example programs. but it is a more advanced
topic that really requires you to know about OOP and event-driven
style programs first.


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



From dsh0105 at comcast.net  Sat Jun  2 13:56:26 2007
From: dsh0105 at comcast.net (David Hamilton)
Date: Sat, 02 Jun 2007 06:56:26 -0500
Subject: [Tutor] Design Question
In-Reply-To: <466039EF.2030403@cc.umanitoba.ca>
References: <060120071446.11924.4660313A000F1FCD00002E942213484373CACFCECF089C0B@comcast.net>
	<466039EF.2030403@cc.umanitoba.ca>
Message-ID: <46615AEA.7050505@comcast.net>

Thanks for the guidance!  I'm glad to know my design wasn't wildly 
off-base. I will most likely take your advice about using pickle to 
implement persistence.  As for old style vs new style constructors...I'm 
still a little fuzzy on the details, but I've done enough reading to see 
that new style is vastly improved. I'll keep working on that.

Thanks again,

David

Brian van den Broek wrote:
> dsh0105 at comcast.net said unto the world upon 06/01/2007 10:46 AM:
>> I think I may have sent an incomplete version of this question a 
>> moment ago (sorry). Here is the complete question:
>>
>> I'm designing something along the lines of a flash card program. It's 
>> mostly just an exercise in learning Python, but I'd like it to be at 
>> least marginally usable when I'm done. So I'm looking for 
>> comments/suggestions on the key pieces of the design: the questions 
>> and the flash card deck:
>> Psudo-code of current design:
>>
>> class Deck():
>>     """Provides managment and informational functions about a set of 
>> questions to be asked
>>         methods incldue:
>>         __init__(questions) -- takes a list of question and creates a 
>> new deck with these questions.
>>         add_question(self,question) -- Adds a question to the current 
>> deck
>>         remove_question(self,question) -- returns True if the 
>> question was removed, False otherwise
>>         get_question() -- Returns the next unanswered question in the 
>> deck
>>         get_stats() -- returns a tuple containing: number_asked, 
>> number_correct, number_remaining
>>                 shuffle_deck() -- shuffles the order of the remaining 
>> questions.
>>         Deck Overrived the __len__ function so that the len returned 
>> is the number of questions in the deck."
>>        
>>
>> class Question():
>>     """Provides questions to be asked
>>     methods:
>>     __init__(self,question,answer) -- question string representing 
>> the question.                                     answer can be a 
>> text string, a tupple (for multiple correct answers)
>>                                     or an object implementing an 
>> is_correct() method that returns a boolean
>>                                    
>>     check_answer(self,answer) -- tests to see if the answer is 
>> correct and returns a boolean     """
>>                                    
>>                                    
>> Mostly I'm wondering, is this over-kill? The idea is to allow for the 
>> deck to be used for as wide a variety of purposes as possible. Also, 
>> I want to make it easy to write code that generates decks.  Is this 
>> design over-kill?
>>
>> Any comments/suggestions welcome.
>>
>> Thanks,
>>
>> David
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> David,
>
> I'd make Deck and Question subclass object so as to have new-style 
> classes, as in:
>
> class Deck(object):
>     # code here
>
> If you don't know about the difference between classic classes and 
> new-style, you needn't worry about it for now. There are a number of 
> ways in which new-style are better, though.
>
> I also have a suggestion that you might want to think about after you 
> get the basic functionality working. When I did something similar, I 
> used the pickle module make my Questions persistent between sessions, 
> and had each Question keep track of how many times it has been asked 
> and correctly answered. I then had my Deck.get_question pick which 
> Question to ask in a way that favoured both Questions that had been 
> rarely asked, and those that had the highest error rates.
>
> Best,
>
> Brian vdB
>


From alan.gauld at btinternet.com  Sat Jun  2 14:10:59 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 2 Jun 2007 13:10:59 +0100
Subject: [Tutor] Running two different python applications from one
	module
References: <46612A6C.6020305@khine.net>
Message-ID: <f3rmpu$g1u$1@sea.gmane.org>


"Norman Khine" <norman at khine.net> wrote

> I would like to write a script using python 2.5 to interact with a 
> Zope
> application that is running on python 2.4.3
>
> Can I call the python 2.4.3 module from within the python 2.5, if so 
> how?

You can generally import modules from older versions into
newer versions if the module is implemented in pure Python.
Where it gets messier is if the module is built in C. There
you generally need a library compiled for your version.

> For example, my script is in /home/me/python2.4/create.py
> and within my /home/me/python2.5/servers.py
>
> When running server.py I would like to run the create.py and then
> continue with my application in the python2.5

Your use of the term 'run' is confusing. What exactly do you mean?
You could:
1) use os.system to execute it as a separate process in a separate 
shell
2) use execfile to run it as a separate process (in the same shell?)
3) use import to load it into your program and execute its functuions
    within your process. In this case you need your sys.path to
    include the python  2.4 folder

And other options on top of that. What do you actually want to do?

> Can someone show me an example from the interpreter or as a module 
> that
> does this.

You can see examples of running subproceses in the OS topic of my 
tutorial.

HTH,

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



From norman at khine.net  Sat Jun  2 17:17:09 2007
From: norman at khine.net (Norman Khine)
Date: Sat, 02 Jun 2007 17:17:09 +0200
Subject: [Tutor] Running two different python applications from
	one	module
In-Reply-To: <f3rmpu$g1u$1@sea.gmane.org>
References: <46612A6C.6020305@khine.net> <f3rmpu$g1u$1@sea.gmane.org>
Message-ID: <466189F5.4070207@khine.net>

Thank you for your reply.

I have just found your book, it looks very good and I will look at sub
processes examples.

What I am trying to do is that I want to create a python module within
itools http://www.ikaaro.org/itools CMS that creates an object based on
a form input that has a post method in the zope application.

I can do this using this method, but I was wondering if I can by-pass
this and execute it from within the itools module.

The zope application basically creates trial shops, from BizarSoftware
as per this scrip

http://www.bizarsoftware.com.au/resource_centre/create_trial_shop.py

I want to replace the <form action="create_trial_shop" method="post"> to
be executed from within the python2.5


I have something like:

    def create(self, user):
        root = self.get_root()
        users = root.get_handler('users')

        firstname = user.get_property('ikaaro:firstname')
        lastname = user.get_property('ikaaro:lastname')
        email = user.get_property('ikaaro:email')

        # Create the user
        if user is None:
            email = context.get_form_value('ikaaro:email')
            firstname = context.get_form_value('ikaaro:firstname')
            lastname = context.get_form_value('ikaaro:lastname')
            users = root.get_handler('users')
            user = users.set_user(email)
            user.set_property('ikaaro:firstname', firstname)
            user.set_property('ikaaro:lastname', lastname)
            key = generate_password(30)
            user.set_property('ikaaro:user_must_confirm', key)
        user_id = user.name

....

once the user has come to this point, I would like to push the
firstname, lastname and email to the
http://www.bizarsoftware.com.au/resource_centre/create_trial_shop.py
script which runs on python2.4 and I am not sure how to deal with it
within my create class.

Cheers

Norman


Alan Gauld wrote:
> "Norman Khine" <norman at khine.net> wrote
> 
>> I would like to write a script using python 2.5 to interact with a 
>> Zope
>> application that is running on python 2.4.3
>>
>> Can I call the python 2.4.3 module from within the python 2.5, if so 
>> how?
> 
> You can generally import modules from older versions into
> newer versions if the module is implemented in pure Python.
> Where it gets messier is if the module is built in C. There
> you generally need a library compiled for your version.
> 
>> For example, my script is in /home/me/python2.4/create.py
>> and within my /home/me/python2.5/servers.py
>>
>> When running server.py I would like to run the create.py and then
>> continue with my application in the python2.5
> 
> Your use of the term 'run' is confusing. What exactly do you mean?
> You could:
> 1) use os.system to execute it as a separate process in a separate 
> shell
> 2) use execfile to run it as a separate process (in the same shell?)
> 3) use import to load it into your program and execute its functuions
>     within your process. In this case you need your sys.path to
>     include the python  2.4 folder
> 
> And other options on top of that. What do you actually want to do?
> 
>> Can someone show me an example from the interpreter or as a module 
>> that
>> does this.
> 
> You can see examples of running subproceses in the OS topic of my 
> tutorial.
> 
> HTH,
> 




From ezra.taylor at gmail.com  Sat Jun  2 15:44:50 2007
From: ezra.taylor at gmail.com (Ezra Taylor)
Date: Sat, 2 Jun 2007 09:44:50 -0400
Subject: [Tutor] Problem with python2.5 and pyGres-3.8.1
Message-ID: <eb90f15e0706020644x2f1b5b72sbd98b0db24843321@mail.gmail.com>

All:
      I'm trying to get python2.5 and PyGres-3.8.1 working.  I'm getting the
following error when doing an import.  I'm not sure what I have to do to
openssl.  I've seen this linger around on the web but no one suggested a
solution.  Your help will be much appreciated.

Ezra


ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
Python 2.5.1 (r251:54863, May  1 2007, 17:48:28)
[GCC 2.95.3 20010315 (SuSE)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _pg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/pgsql/lib/libpq.so.5: undefined symbol:
SSL_CTX_set_client_cert_cb



-- 
Ezra Taylor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070602/040f25fd/attachment.htm 

From D3IBZ at hotmail.com  Sat Jun  2 22:17:19 2007
From: D3IBZ at hotmail.com (Darren Williams)
Date: Sat, 2 Jun 2007 21:17:19 +0100
Subject: [Tutor] C# style multi-line textbox in Python
Message-ID: <BAY138-DAV25CBF139D801FD5C8D1E5E9230@phx.gbl>

Hi all,

I'm completely new when it comes to Python so forgive me for asking a potentially very simple question.  Can C# style multi-line textboxes for user-input be scripted in Python?  Are there any other attributes that I can add to either input() or raw_input()?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070602/5f597753/attachment.htm 

From alan.gauld at btinternet.com  Sun Jun  3 01:15:47 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 3 Jun 2007 00:15:47 +0100
Subject: [Tutor] C# style multi-line textbox in Python
References: <BAY138-DAV25CBF139D801FD5C8D1E5E9230@phx.gbl>
Message-ID: <f3stoe$mpv$1@sea.gmane.org>


"Darren Williams" <D3IBZ at hotmail.com> wrote
> I'm completely new when it comes to Python so forgive
> me for asking a potentially very simple question.
> Can C# style multi-line textboxes for user-input
> be scripted in Python?

Yes, but as part of a GUI.

> Are there any other attributes that I can add to
> either input() or raw_input()?

No, it's rather more complex.

Here is an example in Tkinter, the standard GUI
toolkit that comes with python:

from Tkinter import *
tk = Tk()
t = Text(tk)
t.pack()
tk.mainloop()


Or, with a scrollbar:

from Tkinter import *
import ScrolledText
tk = Tk()
ScrolledText.ScrolledText(tk).pack()
tk.mainloop()

Now that doesn't let you read the contents of the
text box but it shows that you can create one.

However before you get to that stage you will be better off
sticking with command line style programs for a while
until you are comfortable with the python language.

There are basic entry dialogs you can use without resorting
to Tkinter  completely but I don't think they include a
multiline input box. Try this link for more info:

http://www.pythonware.com/library/tkinter/introduction/x1164-data-entry.htm

Also the GUI topic of my tutorial covers the minimum needed
for GUI programming in Python.

HTH,

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



From jason at asahnekec.com  Sun Jun  3 21:09:37 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Sun, 3 Jun 2007 15:09:37 -0400
Subject: [Tutor] Command Line Promps
Message-ID: <004501c7a612$bb583210$21137044@dunamis34752e9>

Is it possible to have a Python program issue a command line promp to the terminal while the program is running?

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070603/3347826c/attachment.htm 

From bgailer at alum.rpi.edu  Sun Jun  3 21:27:36 2007
From: bgailer at alum.rpi.edu (Bob Gailer)
Date: Sun, 03 Jun 2007 12:27:36 -0700
Subject: [Tutor] Command Line Promps
In-Reply-To: <004501c7a612$bb583210$21137044@dunamis34752e9>
References: <004501c7a612$bb583210$21137044@dunamis34752e9>
Message-ID: <46631628.3030001@alum.rpi.edu>

Jason Coggins wrote:
> Is it possible to have a Python program issue a command line promp to 
> the terminal while the program is running?
See raw_input() and input() built-in functions.
>  
-- 
Bob Gailer
510-978-4454


From matt at mattanddawn.orangehome.co.uk  Sun Jun  3 22:12:39 2007
From: matt at mattanddawn.orangehome.co.uk (Matt Smith)
Date: Sun, 03 Jun 2007 21:12:39 +0100
Subject: [Tutor] More trouble debugging my game of life program
Message-ID: <1180901559.10369.14.camel@computer>

Hi,

I've got my program working correctly (or so it seems) with my original
data file (r-pentomino.txt - attached) but when I run it with a larger
(30*30) file (big-r-pentomino - also attached) in an attempt to make it
work with out so many edge effects it returns the following error
message:

Traceback (most recent call last):
  File "Python/game_of_life/life.py", line 75, in <module>
    curses.wrapper(main)
  File "curses/wrapper.py", line 44, in wrapper
  File "Python/game_of_life/life.py", line 60, in main
    draw_board(matrix, stdscr, generation)
  File "Python/game_of_life/life.py", line 28, in draw_board
    stdscr.addch(y + 1, x + 1, ' ')
_curses.error: addch() returned ERR

I thought I had designed the program to work with any text file as long
as the lines are all the same length so I cannot understand why I get
this error message. When I read through the code I cannot see a reason
why the program should work for one size file and not another. The part
of the program that is failing is just drawing a space character at a
particular location on the screen.

Here is the listing of the program that I have also attached:

#! /usr/bin/env python

# Curses based Game of Life program
# Written by Matt Smith

import curses
from copy import deepcopy

def read_start():
    # Read the starting configuration from a text file
    file = open('/home/matt/Python/game_of_life/r-pentomino.txt', 'r')
    matrix = []
    for line in file:
        line = line.rstrip('\n')
        line_list=[]
        for i in range(len(line)):
            line_list.append(int(line[i]))
        matrix.append(line_list)
    return matrix

def draw_board(matrix, stdscr, generation):
    # Draw the life board based on the matrix containing the current
state
    for x in range(len(matrix[0])):
        for y in range(len(matrix)):
            if matrix[y][x]:
                stdscr.addch(y + 1, x + 1, '*')
            else:
                stdscr.addch(y + 1, x + 1, ' ')
    stdscr.addstr(len(matrix) + 1, 0, 'Generation: %s' % (generation))
    stdscr.refresh()

def update_matrix(matrix):
    matrix_updated = deepcopy(matrix)
    # Perform check for each value in the matrix
    for x in range(len(matrix[0])):
        for y in range(len(matrix)):
            neighbour_count = 0
            for n in (x-1, x, x+1):
                for m in (y-1, y, y+1):
                    try:
                        if matrix[m][n]:
                            if (n,m) != (x,y):
                                neighbour_count = neighbour_count + 1
                    except IndexError:
                        pass
            # Apply game of life rules to each item in the matrix
            if neighbour_count < 2:
                matrix_updated[y][x] = 0
            elif neighbour_count > 3:
                matrix_updated[y][x] = 0
            elif neighbour_count == 3:
                matrix_updated[y][x] = 1
            # No need to change value if neighbour count == 2
    return matrix_updated

def main(stdscr):
    # Initialise some variables and put the screen in it's starting
configuration
    matrix = read_start()
    generation = 1
    draw_board(matrix, stdscr, generation)
    stdscr.addstr(len(matrix) + 2, 0, 
        'Press <space> to advance a generation, <q> to quit.')
    # The main program loop - respond to keyboard input
    while 1:
        key_press = stdscr.getkey()
        if key_press == 'q':
            break
        elif key_press == ' ':
            generation = generation + 1
            matrix = update_matrix(matrix)
            draw_board(matrix, stdscr, generation)

# Run the main program inside the curses wrapper to ensure it leaves the
screen
# in a usable state
curses.wrapper(main)

Can anyone come up with the reason why one input file works and the
other one doesn't??

Thanks,

Matt
-------------- next part --------------
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000110000000000000
00000000000001100000000000000
00000000000000100000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
00000000000000000000000000000
-------------- next part --------------
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000110000000
000001100000000
000000100000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
-------------- next part --------------
A non-text attachment was scrubbed...
Name: life.py
Type: text/x-python
Size: 2590 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070603/508dad81/attachment.py 

From matt at mattanddawn.orangehome.co.uk  Sun Jun  3 22:20:46 2007
From: matt at mattanddawn.orangehome.co.uk (Matt Smith)
Date: Sun, 03 Jun 2007 21:20:46 +0100
Subject: [Tutor] Suggestions for a first object orientated program
Message-ID: <1180902046.10369.23.camel@computer>

Hi,

I have been reading up on OOP in Python recently and feel ready to
attempt my first program using OOP principals. Can anyone suggest a
suitable first OOP project for me to get my teeth into?

I haven't done any real GUI programming but I have started gutting to
grips with the curses module under Linux (see my posts about the game of
life program). The game of life program might also show the kind of
stage I am at with my learning of Python at the moment.

Thanks,

Matt





From bgailer at alum.rpi.edu  Sun Jun  3 22:24:35 2007
From: bgailer at alum.rpi.edu (Bob Gailer)
Date: Sun, 03 Jun 2007 13:24:35 -0700
Subject: [Tutor] Command Line Promps
In-Reply-To: <000401c7a61c$658af890$21137044@dunamis34752e9>
References: <004501c7a612$bb583210$21137044@dunamis34752e9>
	<46631628.3030001@alum.rpi.edu>
	<000401c7a61c$658af890$21137044@dunamis34752e9>
Message-ID: <46632383.6030409@alum.rpi.edu>

Please always reply to the list, not just me. We are all working on 
these questions and we all learn from them.

Jason Coggins wrote:
> These seem to be ways of getting imput from the user.  I do not want 
> to send a command line to the user (for example, in the form of a 
> question) and get the users input.
>
> I want the Python program to open a terminal (if need be) and send a 
> command to the computer (through the terminal) that the program is 
> running on.
I think what you really want is to have Python run another program. True?

(Not that it matters a lot but which OS are you running?)

See os.system() and os.popen()
>
> Sorry if I was not more clear on this earlier,
Well it is often hard to be clear, but it sure saves time and energy.

-- 
Bob Gailer
510-978-4454


From jason at asahnekec.com  Sun Jun  3 23:05:57 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Sun, 3 Jun 2007 17:05:57 -0400
Subject: [Tutor] Command Line Promps
References: <004501c7a612$bb583210$21137044@dunamis34752e9>
	<46631628.3030001@alum.rpi.edu>
	<000401c7a61c$658af890$21137044@dunamis34752e9>
	<46632383.6030409@alum.rpi.edu>
Message-ID: <001201c7a622$fba7de50$21137044@dunamis34752e9>

I am using Linux and yes I am wanting the program to run another program.  I 
have tried these before but, if I remember correctly, these methods caused 
the original program to "freeze" while waiting on the "spawned" program to 
return a value (usually either true or false).  I am planning on having the 
program start another program and then exit the original program after the 
second program is started but before the second program ends.  I will take 
another look at these to see if I can work around the "freezing" problem 
because I have a little more experience then when I tried it the first time.

I used the reply button to send a reply to the first message.  I did not 
realize it would send the reply directly to you instead of the list.  I have 
tried to send this reply to the list.

Thanks,

Jason

----- Original Message ----- 
From: "Bob Gailer" <bgailer at alum.rpi.edu>
To: "Jason Coggins" <jason at asahnekec.com>
Cc: <tutor at python.org>
Sent: Sunday, June 03, 2007 4:24 PM
Subject: Re: [Tutor] Command Line Promps


> Please always reply to the list, not just me. We are all working on these 
> questions and we all learn from them.
>
> Jason Coggins wrote:
>> These seem to be ways of getting imput from the user.  I do not want to 
>> send a command line to the user (for example, in the form of a question) 
>> and get the users input.
>>
>> I want the Python program to open a terminal (if need be) and send a 
>> command to the computer (through the terminal) that the program is 
>> running on.
> I think what you really want is to have Python run another program. True?
>
> (Not that it matters a lot but which OS are you running?)
>
> See os.system() and os.popen()
>>
>> Sorry if I was not more clear on this earlier,
> Well it is often hard to be clear, but it sure saves time and energy.
>
> -- 
> Bob Gailer
> 510-978-4454
> 


From jim at well.com  Sun Jun  3 23:37:52 2007
From: jim at well.com (jim stockford)
Date: Sun, 3 Jun 2007 14:37:52 -0700
Subject: [Tutor] Command Line Promps
In-Reply-To: <001201c7a622$fba7de50$21137044@dunamis34752e9>
References: <004501c7a612$bb583210$21137044@dunamis34752e9>
	<46631628.3030001@alum.rpi.edu>
	<000401c7a61c$658af890$21137044@dunamis34752e9>
	<46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
Message-ID: <fa8c80061863c2bfde335d7c86b738db@well.com>


sounds like threading is a solution.

On Jun 3, 2007, at 2:05 PM, Jason Coggins wrote:

> I am using Linux and yes I am wanting the program to run another 
> program.  I
> have tried these before but, if I remember correctly, these methods 
> caused
> the original program to "freeze" while waiting on the "spawned" 
> program to
> return a value (usually either true or false).  I am planning on 
> having the
> program start another program and then exit the original program after 
> the
> second program is started but before the second program ends.  I will 
> take
> another look at these to see if I can work around the "freezing" 
> problem
> because I have a little more experience then when I tried it the first 
> time.
>
> I used the reply button to send a reply to the first message.  I did 
> not
> realize it would send the reply directly to you instead of the list.  
> I have
> tried to send this reply to the list.
>
> Thanks,
>
> Jason
>
> ----- Original Message -----
> From: "Bob Gailer" <bgailer at alum.rpi.edu>
> To: "Jason Coggins" <jason at asahnekec.com>
> Cc: <tutor at python.org>
> Sent: Sunday, June 03, 2007 4:24 PM
> Subject: Re: [Tutor] Command Line Promps
>
>
>> Please always reply to the list, not just me. We are all working on 
>> these
>> questions and we all learn from them.
>>
>> Jason Coggins wrote:
>>> These seem to be ways of getting imput from the user.  I do not want 
>>> to
>>> send a command line to the user (for example, in the form of a 
>>> question)
>>> and get the users input.
>>>
>>> I want the Python program to open a terminal (if need be) and send a
>>> command to the computer (through the terminal) that the program is
>>> running on.
>> I think what you really want is to have Python run another program. 
>> True?
>>
>> (Not that it matters a lot but which OS are you running?)
>>
>> See os.system() and os.popen()
>>>
>>> Sorry if I was not more clear on this earlier,
>> Well it is often hard to be clear, but it sure saves time and energy.
>>
>> -- 
>> Bob Gailer
>> 510-978-4454
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


From broek at cc.umanitoba.ca  Mon Jun  4 00:09:22 2007
From: broek at cc.umanitoba.ca (Brian van den Broek)
Date: Sun, 03 Jun 2007 18:09:22 -0400
Subject: [Tutor] More trouble debugging my game of life program
In-Reply-To: <1180901559.10369.14.camel@computer>
References: <1180901559.10369.14.camel@computer>
Message-ID: <46633C12.2030508@cc.umanitoba.ca>

Matt Smith said unto the world upon 06/03/2007 04:12 PM:
> Hi,
> 
> I've got my program working correctly (or so it seems) with my original
> data file (r-pentomino.txt - attached) but when I run it with a larger
> (30*30) file (big-r-pentomino - also attached) in an attempt to make it
> work with out so many edge effects it returns the following error
> message:
> 
> Traceback (most recent call last):
>   File "Python/game_of_life/life.py", line 75, in <module>
>     curses.wrapper(main)
>   File "curses/wrapper.py", line 44, in wrapper
>   File "Python/game_of_life/life.py", line 60, in main
>     draw_board(matrix, stdscr, generation)
>   File "Python/game_of_life/life.py", line 28, in draw_board
>     stdscr.addch(y + 1, x + 1, ' ')
> _curses.error: addch() returned ERR
> 
> I thought I had designed the program to work with any text file as long
> as the lines are all the same length so I cannot understand why I get
> this error message. When I read through the code I cannot see a reason
> why the program should work for one size file and not another. The part
> of the program that is failing is just drawing a space character at a
> particular location on the screen.
> 
> Here is the listing of the program that I have also attached:

<snip>


Hi Matt and all,

I'm not familiar with curses, and I didn't look too closely at your 
code. But, if I understand you aright, things work fine with a 15x15 
matrix, and go sideways with the 30x30.

The first thing I would do to try to track down the problem would be 
to try 15x30 and 30x15 matrices. If you have two cases where one 
behaves as expected and one does not, it is usually very useful to try 
to match the two cases as closely as possible as an aid to pinpointing 
the problem.

HTH,

Brian vdB

From jason at asahnekec.com  Mon Jun  4 00:13:30 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Sun, 3 Jun 2007 18:13:30 -0400
Subject: [Tutor] Command Line Promps
References: <004501c7a612$bb583210$21137044@dunamis34752e9>
	<46631628.3030001@alum.rpi.edu>
	<000401c7a61c$658af890$21137044@dunamis34752e9>
	<46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<fa8c80061863c2bfde335d7c86b738db@well.com>
Message-ID: <002201c7a62c$6bf8d570$21137044@dunamis34752e9>

Will the program that is started by the thread continue to run if the 
program that started the thread exits?

Jason

----- Original Message ----- 
From: "jim stockford" <jim at well.com>
To: "Jason Coggins" <jason at asahnekec.com>
Cc: <tutor at python.org>
Sent: Sunday, June 03, 2007 5:37 PM
Subject: Re: [Tutor] Command Line Promps


>
> sounds like threading is a solution.
>
> On Jun 3, 2007, at 2:05 PM, Jason Coggins wrote:
>
>> I am using Linux and yes I am wanting the program to run another program. 
>> I
>> have tried these before but, if I remember correctly, these methods 
>> caused
>> the original program to "freeze" while waiting on the "spawned" program 
>> to
>> return a value (usually either true or false).  I am planning on having 
>> the
>> program start another program and then exit the original program after 
>> the
>> second program is started but before the second program ends.  I will 
>> take
>> another look at these to see if I can work around the "freezing" problem
>> because I have a little more experience then when I tried it the first 
>> time.
>>
>> I used the reply button to send a reply to the first message.  I did not
>> realize it would send the reply directly to you instead of the list.  I 
>> have
>> tried to send this reply to the list.
>>
>> Thanks,
>>
>> Jason
>>
>> ----- Original Message -----
>> From: "Bob Gailer" <bgailer at alum.rpi.edu>
>> To: "Jason Coggins" <jason at asahnekec.com>
>> Cc: <tutor at python.org>
>> Sent: Sunday, June 03, 2007 4:24 PM
>> Subject: Re: [Tutor] Command Line Promps
>>
>>
>>> Please always reply to the list, not just me. We are all working on 
>>> these
>>> questions and we all learn from them.
>>>
>>> Jason Coggins wrote:
>>>> These seem to be ways of getting imput from the user.  I do not want to
>>>> send a command line to the user (for example, in the form of a 
>>>> question)
>>>> and get the users input.
>>>>
>>>> I want the Python program to open a terminal (if need be) and send a
>>>> command to the computer (through the terminal) that the program is
>>>> running on.
>>> I think what you really want is to have Python run another program. 
>>> True?
>>>
>>> (Not that it matters a lot but which OS are you running?)
>>>
>>> See os.system() and os.popen()
>>>>
>>>> Sorry if I was not more clear on this earlier,
>>> Well it is often hard to be clear, but it sure saves time and energy.
>>>
>>> -- 
>>> Bob Gailer
>>> 510-978-4454
>>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> 


From jason at asahnekec.com  Mon Jun  4 00:24:30 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Sun, 3 Jun 2007 18:24:30 -0400
Subject: [Tutor] ftp
Message-ID: <001f01c7a62d$f5808c10$21137044@dunamis34752e9>

What would be the best method to (1) check if there is a particular file available for download on the internet and (2) if the file is available, download the file to a particular directory.

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070603/d9e741a6/attachment.html 

From kent37 at tds.net  Mon Jun  4 00:41:26 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 03 Jun 2007 18:41:26 -0400
Subject: [Tutor] ftp
In-Reply-To: <001f01c7a62d$f5808c10$21137044@dunamis34752e9>
References: <001f01c7a62d$f5808c10$21137044@dunamis34752e9>
Message-ID: <46634396.7060508@tds.net>

Jason Coggins wrote:
> What would be the best method to (1) check if there is a particular file 
> available for download on the internet and (2) if the file is available, 
> download the file to a particular directory.

Use ftplib. Here are some examples:
http://effbot.org/librarybook/ftplib.htm

Here is a wrapper that provides a higher-level interface:
http://ftputil.sschwarzer.net/trac

Kent

From alan.gauld at btinternet.com  Mon Jun  4 01:35:30 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 4 Jun 2007 00:35:30 +0100
Subject: [Tutor] Command Line Promps
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
Message-ID: <f3vj9e$6t6$1@sea.gmane.org>

"Jason Coggins" <jason at asahnekec.com> wrote

>I am using Linux and yes I am wanting the program to run another 
>program.  I
> have tried these before but, if I remember correctly, these methods 
> caused
> the original program to "freeze" while waiting on the "spawned" 
> program to
> return a value (usually either true or false).  I am planning on 
> having the
> program start another program and then exit the original program 
> after the
> second program is started but before the second program ends.

Since you are on Linux you should look at os.fork()

The use of fork() is covered in my tutorial in the topic on
Inter-Process Communications under the heading Spawning Processes.

> I used the reply button to send a reply to the first message.  I did 
> not
> realize it would send the reply directly to you instead of the list. 
> I have
> tried to send this reply to the list.

Reply All is the tool to use. Reply replies only to the sender which
is set to the original sender.

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 Jun  4 01:46:31 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 4 Jun 2007 00:46:31 +0100
Subject: [Tutor] Suggestions for a first object orientated program
References: <1180902046.10369.23.camel@computer>
Message-ID: <f3vju3$8cn$1@sea.gmane.org>


"Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote

> I have been reading up on OOP in Python recently and feel ready to
> attempt my first program using OOP principals. Can anyone suggest a
> suitable first OOP project for me to get my teeth into?
>
> I haven't done any real GUI programming but I have started gutting 
> to
> grips with the curses module under Linux (see my posts about the 
> game of
> life program). The game of life program might also show the kind of
> stage I am at with my learning of Python at the moment.

The Game of life would be a good OOP project.

You could have a board that knows about the contents of each cell.
And you could have an organism that knows the rules for life/death
and can query the board about the state of its adjacent cells. The
best form of interaction between organism and board is one of the
typical design issues you get when doing OOP.

Finally you could create a Game object that knows how to initiate
a game, how to play it and how to end it.

So your main function looks like

GameOfLife().run()

Only three classes but you would learn a lot about OOP sorting
out the issues involved.

Only one tip - get the non OOP version working properly first!

HTH,

Alan G. 



From alan.gauld at btinternet.com  Mon Jun  4 01:48:03 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 4 Jun 2007 00:48:03 +0100
Subject: [Tutor] ftp
References: <001f01c7a62d$f5808c10$21137044@dunamis34752e9>
Message-ID: <f3vk0v$8kd$1@sea.gmane.org>


"Jason Coggins" <jason at asahnekec.com> wrote

> What would be the best method to (1) check if there is a
> particular file available for download on the internet and (2)
> if the file is available, download the file to a particular 
> directory.

Since you mention ftp in the subject line I'll assume the
remote seerver has an ftp daemon runing. If so use the
ftp module. Othewise we need to know more about the
protocol options available to you.


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



From preecha88 at gmail.com  Mon Jun  4 04:45:49 2007
From: preecha88 at gmail.com (Preecha Bundrikwong)
Date: Mon, 4 Jun 2007 09:45:49 +0700
Subject: [Tutor] newbie: Reading text file
In-Reply-To: <46600B5E.2090109@tds.net>
References: <440963.67763.qm@web86112.mail.ird.yahoo.com>
	<4257d6370706010231k43a1fafufe469c3f03b78988@mail.gmail.com>
	<465FF3F2.1050003@tds.net>
	<4257d6370706010356o2abd5058gb9f717ee78281477@mail.gmail.com>
	<46600B5E.2090109@tds.net>
Message-ID: <30c6012b0706031945h76cabc09k7e7644abe48885cf@mail.gmail.com>

Dear all,

Thanks for all your help. I followed Alan's suggestion -- dealing with the
directory search path, by the method sys.path.append(). At first I thought
it would mess up the whole sys.path after running the script. But it
actually doesn't. Thanks again!

Regards,
PB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/32cdc269/attachment.htm 

From jfabiani at yolo.com  Mon Jun  4 07:16:50 2007
From: jfabiani at yolo.com (johnf)
Date: Sun, 3 Jun 2007 22:16:50 -0700
Subject: [Tutor] using re
Message-ID: <200706032216.50822.jfabiani@yolo.com>

I have the following
pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth, 
self.DecimalWidth)
)
	if re.match(pattern, self.GetValue())==None:
	    self.BackColor == "pink"
	else:
	    self.BackColor == "white"

self.IntegerWidth = 2
self.DecimalWidth=2

the problem is the pattern allows ".999".  What am I doing wrong?
-- 
John Fabiani

From akap at isd.dp.ua  Mon Jun  4 10:05:42 2007
From: akap at isd.dp.ua (Alexander Kapshuk)
Date: Mon, 4 Jun 2007 11:05:42 +0300
Subject: [Tutor] software modeling tools used with Python
Message-ID: <70831DC71E5D814C9D1FA8A96653215E093B9A40@server.isd.dp.ua>

Dear Python Community,

 

I was just wondering about what software modelling tools are normally
used to design Python programs.

 

I have heard of Star UML. Has anyone used it to design their programs?

 

What else is available out there?

 

Thanking you all in advance.

 

Alexander Kapshuk

ISD Education Office

ICQ#295-121-606

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/b1a132c0/attachment-0001.html 

From mailchansek at yahoo.com  Mon Jun  4 10:45:57 2007
From: mailchansek at yahoo.com (Chandrashekar)
Date: Mon, 4 Jun 2007 01:45:57 -0700 (PDT)
Subject: [Tutor] SSH using python
Message-ID: <785903.8409.qm@web58708.mail.re1.yahoo.com>

Hi ,

Can anyone tell me how to do ssh to a machine using python and execute programs on the remote machine? Thanks in advance. 

Regards,
Chandru


       
---------------------------------
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/3cf981fe/attachment.htm 

From alan.gauld at btinternet.com  Mon Jun  4 10:32:11 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 4 Jun 2007 09:32:11 +0100
Subject: [Tutor] software modeling tools used with Python
References: <70831DC71E5D814C9D1FA8A96653215E093B9A40@server.isd.dp.ua>
Message-ID: <f40inn$ikl$1@sea.gmane.org>

"Alexander Kapshuk" <akap at isd.dp.ua> wrote 

> I was just wondering about what software modelling tools 
> are normally used to design Python programs.

By the nature of Python and the size of programs normally 
written I'd say there is no modelling tool used *normally*.

If a project is big enough to warrant a modelling tool then 
any of the normal tools would be adequate.

Personally I have used Borland Together, Rational Rose,
Visio, Dia and xfig plus a couple of really expensive 
Enterprise Architecture tools for which I happened 
to have licenses at the time... All of them worked
within their own limitations.

> I have heard of Star UML. 

Sorry, never heard of that one.

> What else is available out there?

See the list above :-)
Do you have a price range?
Do you have any particular features you need? 
For example do you want a fancy drawing tool (eg Visio) 
or do you want the tool to syntax check UML? 
Or generate code? Or reverse engineer existing code? 
To generate documents? Single or multi-user? Integration 
with change control tools or IDEs? etc etc etc.

Regards,

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


From rschroev_nospam_ml at fastmail.fm  Mon Jun  4 11:04:59 2007
From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven)
Date: Mon, 04 Jun 2007 11:04:59 +0200
Subject: [Tutor] using re
In-Reply-To: <200706032216.50822.jfabiani@yolo.com>
References: <200706032216.50822.jfabiani@yolo.com>
Message-ID: <f40kjr$nqr$1@sea.gmane.org>

johnf schreef:
> I have the following
> pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth, 
> self.DecimalWidth)
> )
> 	if re.match(pattern, self.GetValue())==None:
> 	    self.BackColor == "pink"
> 	else:
> 	    self.BackColor == "white"
> 
> self.IntegerWidth = 2
> self.DecimalWidth=2
> 
> the problem is the pattern allows ".999".  What am I doing wrong?

It's because of the 0 in {0,%s} in the first part of you regular 
expression. That 0 means that the pattern matches numbers without 
integer part.

You just need to change that 0 to a 1, as follows:

^([0-9]{&,%s})(\.[0-9]{0,%s})?$

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven


From preecha88 at gmail.com  Mon Jun  4 11:07:49 2007
From: preecha88 at gmail.com (Preecha Bundrikwong)
Date: Mon, 4 Jun 2007 16:07:49 +0700
Subject: [Tutor] installing maya/python on linux
Message-ID: <30c6012b0706040207g7a145199kda444002136be32b@mail.gmail.com>

Dear all,

Can anybody please give me an easy instruction on installing maya/python
(pysource/sourcepy etc.) on a Linux machine. I've already downloaded it but
never succeeded installing.

BTW, there's no way to make installing process easier to life than this?
(all those compile, source, .so, etc.. hmmmm...)

Regards,
PB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/57a5c925/attachment.html 

From thorsten at thorstenkampe.de  Mon Jun  4 12:05:23 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 4 Jun 2007 11:05:23 +0100
Subject: [Tutor] installing maya/python on linux
References: <30c6012b0706040207g7a145199kda444002136be32b@mail.gmail.com>
Message-ID: <f40o54$47p$1@sea.gmane.org>

* Preecha Bundrikwong (Mon, 4 Jun 2007 16:07:49 +0700)
> Can anybody please give me an easy instruction on installing maya/python
> (pysource/sourcepy etc.) on a Linux machine.

http://cgkit.sourceforge.net/mayadoc/install.html

> I've already downloaded it but never succeeded installing.

Aha. Why?
 
> BTW, there's no way to make installing process easier to life than this?
> (all those compile, source, .so, etc.. hmmmm...)

http://cgkit.sourceforge.net/support.html


From thorsten at thorstenkampe.de  Mon Jun  4 12:07:45 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 4 Jun 2007 11:07:45 +0100
Subject: [Tutor] SSH using python
References: <785903.8409.qm@web58708.mail.re1.yahoo.com>
Message-ID: <f40o9i$47p$2@sea.gmane.org>

* Chandrashekar (Mon, 4 Jun 2007 01:45:57 -0700 (PDT))
> Can anyone tell me how to do ssh to a machine using python and execute programs on the remote machine? Thanks in advance. 

Paramiko


From kent37 at tds.net  Mon Jun  4 12:10:50 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 04 Jun 2007 06:10:50 -0400
Subject: [Tutor] using re
In-Reply-To: <200706032216.50822.jfabiani@yolo.com>
References: <200706032216.50822.jfabiani@yolo.com>
Message-ID: <4663E52A.80406@tds.net>

johnf wrote:
> I have the following
> pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth, 
> self.DecimalWidth)

You should use a raw string (prefix with r) to define pattern, though 
that isn't the problem here.

> )
> 	if re.match(pattern, self.GetValue())==None:
> 	    self.BackColor == "pink"
> 	else:
> 	    self.BackColor == "white"
> 
> self.IntegerWidth = 2
> self.DecimalWidth=2
> 
> the problem is the pattern allows ".999".  What am I doing wrong?

Are you sure? That's not what I get:

In [3]: pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (2, 2)
In [5]: import re
In [9]: print re.match(pattern, '.99')
<_sre.SRE_Match object at 0x1280218>
In [10]: print re.match(pattern, '.999')
None

Kent

From preecha88 at gmail.com  Mon Jun  4 12:30:03 2007
From: preecha88 at gmail.com (Preecha Bundrikwong)
Date: Mon, 4 Jun 2007 17:30:03 +0700
Subject: [Tutor] installing maya/python on linux
In-Reply-To: <f40o54$47p$1@sea.gmane.org>
References: <30c6012b0706040207g7a145199kda444002136be32b@mail.gmail.com>
	<f40o54$47p$1@sea.gmane.org>
Message-ID: <30c6012b0706040330q7085c6c8pa1957df908cc8bcb@mail.gmail.com>

Thanks, but sorry again; how do you 'compile' the downloaded package? I'm
new to Linux :-(
PB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/396d5ca9/attachment.html 

From akap at isd.dp.ua  Mon Jun  4 12:54:28 2007
From: akap at isd.dp.ua (Alexander Kapshuk)
Date: Mon, 4 Jun 2007 13:54:28 +0300
Subject: [Tutor] software modeling tools used with Python
Message-ID: <70831DC71E5D814C9D1FA8A96653215E093B9A83@server.isd.dp.ua>

Thanks for your reply, Alan.

 

I'm not there yet, as in I'm not a very experienced Python programmer
and I'm still in the early stages of learning the language and
programming as a whole.

 

What I'm looking for is a way to design my programs, big or small, other
than just pseudo-coding them on a piece of paper.

 

How do you design your programs?

 

Regards,

 

Alexander Kapshuk

ISD Education Office

ICQ#295-121-606

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/053dbebc/attachment.html 

From dyoo at cs.wpi.edu  Mon Jun  4 15:48:40 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Mon, 4 Jun 2007 09:48:40 -0400 (EDT)
Subject: [Tutor] software modeling tools used with Python
Message-ID: <Pine.LNX.4.63.0706040942150.17298@cs.wpi.edu>

> What I'm looking for is a way to design my programs, big or small, other 
> than just pseudo-coding them on a piece of paper.
>
> How do you design your programs?

[Apologies to the list in advance: not much Python-specific information]

I hope you don't mind the "academic" answer, but:

     http://htdp.org/

might address your question at some level.


For myself, I'm starting to learn how to use a system for modeling 
software systems called Alloy:

     http://alloy.mit.edu/

It's a very nice modeling language with support for writing real 
assertions and tests, so it's more concrete than pseudocode.  I've started 
writing my experiences with it so far in:

     http://hashcollision.blogspot.com/2007/06/lists-1.html

Again, it doesn't have much to do with Python programming, but more to do 
with software designs at a different abstraction layer.


Best of wishes!

From akap at isd.dp.ua  Mon Jun  4 15:56:55 2007
From: akap at isd.dp.ua (Alexander Kapshuk)
Date: Mon, 4 Jun 2007 16:56:55 +0300
Subject: [Tutor] software modeling tools used with Python
Message-ID: <70831DC71E5D814C9D1FA8A96653215E093B9AD4@server.isd.dp.ua>

Thanks a lot Danny.

Will definitely look into those things.

Regards,

Alexander Kapshuk
ISD Education Office
ICQ#295-121-606


From jfabiani at yolo.com  Mon Jun  4 15:57:25 2007
From: jfabiani at yolo.com (johnf)
Date: Mon, 4 Jun 2007 06:57:25 -0700
Subject: [Tutor] using re
In-Reply-To: <4663E52A.80406@tds.net>
References: <200706032216.50822.jfabiani@yolo.com> <4663E52A.80406@tds.net>
Message-ID: <200706040657.25910.jfabiani@yolo.com>

On Monday 04 June 2007 03:10, you wrote:
> johnf wrote:
> > I have the following
> > pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth,
> > self.DecimalWidth)
>
> You should use a raw string (prefix with r) to define pattern, though
> that isn't the problem here.
>
> > )
> > 	if re.match(pattern, self.GetValue())==None:
> > 	    self.BackColor == "pink"
> > 	else:
> > 	    self.BackColor == "white"
> >
> > self.IntegerWidth = 2
> > self.DecimalWidth=2
> >
> > the problem is the pattern allows ".999".  What am I doing wrong?
>
> Are you sure? That's not what I get:
>
> In [3]: pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (2, 2)
> In [5]: import re
> In [9]: print re.match(pattern, '.99')
> <_sre.SRE_Match object at 0x1280218>
> In [10]: print re.match(pattern, '.999')
> None
>
> Kent
Thanks for you response.  You are correct and I have determined that something 
is wrong with the "self.BackColor == "pink" " statement because it does not 
turn the background pink but is firing.  
-- 
John Fabiani

From Mike.Hansen at atmel.com  Mon Jun  4 16:51:02 2007
From: Mike.Hansen at atmel.com (Mike Hansen)
Date: Mon, 4 Jun 2007 08:51:02 -0600
Subject: [Tutor] New programming tutorials
Message-ID: <57B026980605A64F9B23484C5659E32E852078@poccso.US.ad.atmel.com>

I was just looking at the Daily Python URL and there are two new Python
tutorials:

Building Skills in Programming
How To Write Your Own Software Using Python
http://homepage.mac.com/s_lott/books/nonprog/htmlchunks/index.html

Hands-on Python
http://www.cs.luc.edu/~anh/python/hands-on/

Mike

From thorsten at thorstenkampe.de  Mon Jun  4 17:43:58 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 4 Jun 2007 16:43:58 +0100
Subject: [Tutor] installing maya/python on linux
References: <30c6012b0706040207g7a145199kda444002136be32b@mail.gmail.com>
	<f40o54$47p$1@sea.gmane.org>
	<30c6012b0706040330q7085c6c8pa1957df908cc8bcb@mail.gmail.com>
Message-ID: <f41c02$f8k$1@sea.gmane.org>

* Preecha Bundrikwong (Mon, 4 Jun 2007 17:30:03 +0700)
> Thanks, but sorry again; how do you 'compile' the downloaded package? I'm
> new to Linux :-(

./configure
make
make install


From jnoller at gmail.com  Mon Jun  4 17:45:43 2007
From: jnoller at gmail.com (Jesse Noller)
Date: Mon, 4 Jun 2007 11:45:43 -0400
Subject: [Tutor] SSH using python
In-Reply-To: <785903.8409.qm@web58708.mail.re1.yahoo.com>
References: <785903.8409.qm@web58708.mail.re1.yahoo.com>
Message-ID: <4222a8490706040845n648264c0q1b506c2416e0c4e6@mail.gmail.com>

On 6/4/07, Chandrashekar <mailchansek at yahoo.com> wrote:
>
> Hi ,
>
> Can anyone tell me how to do ssh to a machine using python and execute
> programs on the remote machine? Thanks in advance.
>
> Regards,
> Chandru
>
> ------------------------------
> Boardwalk for $500? In 2007? Ha!
> Play Monopoly Here and Now<http://us.rd.yahoo.com/evt=48223/*http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow>(it's updated for today's economy) at Yahoo! Games.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
pSSH:
http://www.theether.org/pssh/

Paramiko:
http://www.lag.net/paramiko/

pExpect example:
http://www.palovick.com/code/python/python-ssh-client.php

Twisted Conch:
http://twistedmatrix.com/users/z3p/files/conch-talk.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070604/66886849/attachment.html 

From alan.gauld at btinternet.com  Mon Jun  4 20:00:19 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 4 Jun 2007 19:00:19 +0100
Subject: [Tutor] software modeling tools used with Python
References: <70831DC71E5D814C9D1FA8A96653215E093B9A83@server.isd.dp.ua>
Message-ID: <f41k0v$fpi$1@sea.gmane.org>

"Alexander Kapshuk" <akap at isd.dp.ua> wrote 

> What I'm looking for is a way to design my programs, 
> big or small, other than just pseudo-coding them on 
> a piece of paper.

IMHO One solution does not fit all here.

The other day I had to do a lot of file maintenance - bulk 
renames and moves etc. I did it with Python and I developed 
the 3 functions I needed interactively in pyCrust then copied 
them to a module which I then ran.

Slightly bigger programs I will use pseudo code. In fact I 
use pseudo code for almost anything for which I'm not 
using OOP regardless of size. Occasionally I supplement 
that with DFDs if there are multiple processes involved 
and ERDs if the data is complex.

For larger OOP projects (more than 6 classes say) I will 
draw a basic class diagram and sequence diagram using 
a simple drawing tool like Visio/Dia (or even pencil and paper!). 
This scales up to about 20 or so classes.

For big projects at work involving more than 30 classes 
and more than one process I'll use a full blown modelling 
tool - usually Borland Together now (used to be Rational Rose)
But its definitely overkill unless there are several 
designers/developers and a complex project. (My current 
project involves over 20 systems, each of which has multiple 
components each of which has many classes - and some 
have several processes running over multiple networks. Maybe 
3000 or so classes in total. With around 200 designers 
on the project, working across 8 different companies, 
in 3 different continents and time-zones, trying to design 
that without a formal modelling tool would be extremely 
difficult!)

I don't know if that answered the question, but its 
how I do things! :-)

Alan G.




From carroll at tjc.com  Mon Jun  4 21:57:56 2007
From: carroll at tjc.com (Terry Carroll)
Date: Mon, 4 Jun 2007 12:57:56 -0700 (PDT)
Subject: [Tutor] Launch external application?
In-Reply-To: <f1b5123f0706012059t1e9da960oa2ff5176e902da85@mail.gmail.com>
Message-ID: <Pine.LNX.4.44.0706041256560.30964-100000@violet.rahul.net>

On Fri, 1 Jun 2007, Brad Tompkins wrote:

> Is there an easy way to make a python script that will launch an external
> application for me ?  I'm using Windows XP and I'm trying to create a little
> front end that will launch the VLC media player for me.

In addition to Grant's approach, if your filetype (say "mpg") is already 
associated with VLC, you can use this:

os.startfile('filename.mpg')
 


From matt at mattanddawn.orangehome.co.uk  Mon Jun  4 22:05:49 2007
From: matt at mattanddawn.orangehome.co.uk (Matt Smith)
Date: Mon, 04 Jun 2007 21:05:49 +0100
Subject: [Tutor] More trouble debugging my game of life program
Message-ID: <1180987549.6246.15.camel@computer>

On Sun, 2007-06-03 at 18:09 -0400, Brian van den Broek wrote:

> The first thing I would do to try to track down the problem would be 
> to try 15x30 and 30x15 matrices. If you have two cases where one 
> behaves as expected and one does not, it is usually very useful to try 
> to match the two cases as closely as possible as an aid to pinpointing 
> the problem.

Thanks Brian,

Initially 15*30 worked but 30*15 didn't. I have just gradually
increased the width of my text file up to 30 characters and it worked
at 30*30 so I guess the problem must be with the text file I was using.
Looking at my code - I can see it will break if the lists within the
big list making up the matrix are not all the same length. Maybe this
is something I need to test for in the program.

Cheers,

Matt



From rabidpoobear at gmail.com  Tue Jun  5 06:28:30 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 04 Jun 2007 23:28:30 -0500
Subject: [Tutor] using re
In-Reply-To: <200706040657.25910.jfabiani@yolo.com>
References: <200706032216.50822.jfabiani@yolo.com> <4663E52A.80406@tds.net>
	<200706040657.25910.jfabiani@yolo.com>
Message-ID: <4664E66E.3010007@gmail.com>


> Thanks for you response.  You are correct and I have determined that something 
> is wrong with the "self.BackColor == "pink" " statement because it does not 
> turn the background pink but is firing.  
>   
== is comparison, not assignment.  Perhaps this is the problem?
-Luke


From LJones at securetrading.com  Tue Jun  5 11:03:43 2007
From: LJones at securetrading.com (Lee Jones)
Date: Tue, 5 Jun 2007 10:03:43 +0100
Subject: [Tutor] urlencode
Message-ID: <A517B25C116F414281788C829739DB3B6F289B@stmail.Menai.local>

Hello,

 

I am trying to urlencode a string.  In python the only thing I can see
is the urllib.urlencode().  But this takes a dictionary, and returns
"key=value", which is not what I want.  I only want to url-encode a
string.  Does any one know how to do this in python

Thanks

Lee

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070605/b418234c/attachment.htm 

From Senthil_OR at Dell.com  Tue Jun  5 12:18:26 2007
From: Senthil_OR at Dell.com (Senthil_OR at Dell.com)
Date: Tue, 5 Jun 2007 15:48:26 +0530
Subject: [Tutor] urlencode
In-Reply-To: <A517B25C116F414281788C829739DB3B6F289B@stmail.Menai.local>
References: <A517B25C116F414281788C829739DB3B6F289B@stmail.Menai.local>
Message-ID: <D6ED7B7268DC0F4C9BF6AF2537BCE5C6FA7EA7@blrx3m03.blr.amer.dell.com>


>From: Lee Jones
>Subject: [Tutor] urlencode
>Hello,
>I am trying to urlencode a string.  In python the only thing I can see
is the urllib.urlencode().  But this takes a dictionary, and returns
>"key=value", which is not what I want.  I only want to url-encode a
string.  Does any one know how to do this in python


Are you looking for urllib.quote() ?
 
>>> import urllib
>>> url = urllib.quote('http://puggy.symonds.net/~senthil')
>>> print url
http%3A//puggy.symonds.net/%7Esenthil
>>> 
 
 
-- 
Senthil

 

	

 

From akap at isd.dp.ua  Tue Jun  5 12:20:05 2007
From: akap at isd.dp.ua (Alexander Kapshuk)
Date: Tue, 5 Jun 2007 13:20:05 +0300
Subject: [Tutor] software modeling tools used with Python
Message-ID: <70831DC71E5D814C9D1FA8A96653215E093B9BA6@server.isd.dp.ua>

Thanks, Alan.

 

The whole situation is clear as day now.

 

Alexander Kapshuk

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070605/379afe0b/attachment.html 

From kent37 at tds.net  Tue Jun  5 12:28:16 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 05 Jun 2007 06:28:16 -0400
Subject: [Tutor] numbers and ranges
In-Reply-To: <4659EB01.5090306@tds.net>
References: <Pine.LNX.4.64.0705271047350.23903@cicero11.myuw.net>
	<4659EB01.5090306@tds.net>
Message-ID: <46653AC0.5050101@tds.net>

Kent Johnson wrote:
  Here is a solution that uses a generator to create the ranges:
> 
> def ranges(data):
>      i = iter(data)
>      first = last = i.next()
>      try:
>          while 1:
>              next = i.next()
>              if next > last+1:
>                  yield (first, last)
>                  first = last = next
>              else:
>                  last = next
>      except StopIteration:
>          yield (first, last)
> 
> print list(ranges((1,)))
> print list(ranges((1,2,3)))
> print list(ranges((1,3,5)))
> print list(ranges((1,3,5,7,8,9,10)))

I suspected when I wrote this that if I were clever enough I could use 
itertools.groupby() to solve this. It turns out that the last example at
http://docs.python.org/lib/itertools-example.html
is exactly the problem of finding runs in a sequence.

Kent

From kent37 at tds.net  Tue Jun  5 12:31:29 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 05 Jun 2007 06:31:29 -0400
Subject: [Tutor] urlencode
In-Reply-To: <D6ED7B7268DC0F4C9BF6AF2537BCE5C6FA7EA7@blrx3m03.blr.amer.dell.com>
References: <A517B25C116F414281788C829739DB3B6F289B@stmail.Menai.local>
	<D6ED7B7268DC0F4C9BF6AF2537BCE5C6FA7EA7@blrx3m03.blr.amer.dell.com>
Message-ID: <46653B81.4000607@tds.net>

Senthil_OR at Dell.com wrote:
>> From: Lee Jones
>> Subject: [Tutor] urlencode
>> Hello,
>> I am trying to urlencode a string.  In python the only thing I can see
> is the urllib.urlencode().  But this takes a dictionary, and returns
>> "key=value", which is not what I want.  I only want to url-encode a
> string.  Does any one know how to do this in python
> 
> 
> Are you looking for urllib.quote() ?

Or urllib.quote_plus() which also escapes spaces. This is the function 
that is called by urlencode().

Kent

From picioslug at gmail.com  Tue Jun  5 13:11:24 2007
From: picioslug at gmail.com (Picio)
Date: Tue, 5 Jun 2007 13:11:24 +0200
Subject: [Tutor] python & google gear
Message-ID: <825bef0c0706050411y31173e75saa377f87bfac5196@mail.gmail.com>

Salve, qualcuno sa dirmi se esiste una API in python per google gear?
code.google.com/apis/gears
Daniele
-- 
http://picio.gotdns.com ...Il mio blog su NSLU2

From carloslara at web.de  Tue Jun  5 14:20:40 2007
From: carloslara at web.de (Carlos)
Date: Tue, 05 Jun 2007 14:20:40 +0200
Subject: [Tutor] Is this a good idea?
Message-ID: <46655518.7000906@web.de>

Hello,

I'm trying to generate two classes, one of them is a given object and 
the other is a 'factory' of those objects. I'm doing this because I'm 
working with huge amounts of objects and would like to have a loop 
generating them. The problem is that I fear that my understanding of OOP 
is just not good enough. So what do you say, is this a good way to solve 
this??

class objct:

   def __init__(self, name, val):
       self.name = name
       self.val = val
      class collection:

   def __init__(self, objcts):
         objecList = []

       for i in range(objcts):
           instance = 'myInst%i' %(i)
           objecList.append(instance)

       for i in range(objcts):
           i = objct(objecList[i], i)
           print i.name
           print i.val
  myC = collection(10)

Regards,
Carlos

From kent37 at tds.net  Tue Jun  5 14:43:59 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 05 Jun 2007 08:43:59 -0400
Subject: [Tutor] Is this a good idea?
In-Reply-To: <46655518.7000906@web.de>
References: <46655518.7000906@web.de>
Message-ID: <46655A8F.2070604@tds.net>

Carlos wrote:
> Hello,
> 
> I'm trying to generate two classes, one of them is a given object and 
> the other is a 'factory' of those objects. I'm doing this because I'm 
> working with huge amounts of objects and would like to have a loop 
> generating them. The problem is that I fear that my understanding of OOP 
> is just not good enough. So what do you say, is this a good way to solve 
> this??
> 
> class objct:
> 
>    def __init__(self, name, val):
>        self.name = name
>        self.val = val
>       class collection:

This indent is funny; I assume this is a top-level class, not a nested 
class...
> 
>    def __init__(self, objcts):
>          objecList = []
> 
>        for i in range(objcts):
>            instance = 'myInst%i' %(i)
>            objecList.append(instance)
> 
>        for i in range(objcts):
>            i = objct(objecList[i], i)
>            print i.name
>            print i.val
>   myC = collection(10)

The idea is OK but the implementation is flawed. collection() can be a 
standalone factory function, it doesn't have to be a class. (You could 
make it a staticmethod if you want it to be enclosed in the objct 
namespace.)

Note that objecList is a list of instance names, not a list of objct 
instances. The objcts you create in the second loop are just thrown 
away. Actually objecList is also thrown away since it is never assigned 
to an instance variable; myC refers to an instance of collection but it 
has no instance data.

If you want to create a list of objcts you can do this in a single list 
comprehension:

myC = [ objct('myInst%i' %(i), i) for i in range(objcts) ]

You could put this in a collection() function if you like. I would write 
your example as

class objct:
    def __init__(self, name, val):
        self.name = name
        self.val = val

def objct_collection(num):
     return [ objct('myInst%i' %(i), i) for i in range(num) ]

I hope the real code uses more descriptive names than objct and 
collection...

Kent

From slewin at rogers.com  Tue Jun  5 16:08:03 2007
From: slewin at rogers.com (scott)
Date: Tue, 05 Jun 2007 10:08:03 -0400
Subject: [Tutor] i++
In-Reply-To: <f3vj9e$6t6$1@sea.gmane.org>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org>
Message-ID: <46656E43.8050206@rogers.com>

Hi,

	is there any way in Python to simply add or subtract one from a 
variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
prefer something more simple and faster.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)

From kent37 at tds.net  Tue Jun  5 16:23:06 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 05 Jun 2007 10:23:06 -0400
Subject: [Tutor] i++
In-Reply-To: <46656E43.8050206@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>	<001201c7a622$fba7de50$21137044@dunamis34752e9>	<f3vj9e$6t6$1@sea.gmane.org>
	<46656E43.8050206@rogers.com>
Message-ID: <466571CA.6080201@tds.net>

scott wrote:
> Hi,
> 
> 	is there any way in Python to simply add or subtract one from a 
> variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
> prefer something more simple and faster.

i += 1

There are no ++ or -- operators in Python.

Kent


From nuin at genedrift.org  Tue Jun  5 16:25:53 2007
From: nuin at genedrift.org (Paulo Nuin)
Date: Tue, 05 Jun 2007 10:25:53 -0400
Subject: [Tutor] i++
In-Reply-To: <46656E43.8050206@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>	<001201c7a622$fba7de50$21137044@dunamis34752e9>	<f3vj9e$6t6$1@sea.gmane.org>
	<46656E43.8050206@rogers.com>
Message-ID: <46657271.8070705@genedrift.org>

Hi

You can use

i += 1
or
i -=1

HTH

Paulo


scott wrote:
> Hi,
>
> 	is there any way in Python to simply add or subtract one from a 
> variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
> prefer something more simple and faster.
>
>   


From dyoo at cs.wpi.edu  Tue Jun  5 16:27:55 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Tue, 5 Jun 2007 10:27:55 -0400 (EDT)
Subject: [Tutor] i++
In-Reply-To: <46656E43.8050206@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
Message-ID: <Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>


> 	is there any way in Python to simply add or subtract one from a 
> variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
> prefer something more simple and faster.

Out of curiosity, why are you incrementing variables?  I know this might 
sound silly, but I'm just curious.  Are you going through a collection of 
things by explicit indexing, or something else?

From slewin at rogers.com  Tue Jun  5 17:13:06 2007
From: slewin at rogers.com (scott)
Date: Tue, 05 Jun 2007 11:13:06 -0400
Subject: [Tutor] i++
In-Reply-To: <Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
Message-ID: <46657D82.2050808@rogers.com>

Danny Yoo wrote:
> 
>>     is there any way in Python to simply add or subtract one from a 
>> variable like i++ or i--?  I don't mind doing a i = i + 1, but would 
>> prefer something more simple and faster.
> 
> Out of curiosity, why are you incrementing variables?
Actually, it is mostly just my curiosity :)  I'm designing my first 
major Python program (It will run a EnGarde PBEM for me).  I had to make 
a loop to loop around 5 times and was going to use the i += 1 when I 
remembered range :)  I did the following instead and it worked perfectly.

for l in range(1,6):
     print l

I will, eventually, be needing the i+= 1 as in the game many times I 
will needing to take away or add to attributes.  I have attached what I 
got so far if you feel like taking a look, but it is probably nasty by 
your standards :)

Thanks everyone for your answers.  I'll probably have a few more 
questions before I finish this project.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 10938 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070605/b7e07f92/attachment.py 

From dyoo at cs.wpi.edu  Tue Jun  5 17:37:58 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Tue, 5 Jun 2007 11:37:58 -0400 (EDT)
Subject: [Tutor] i++
In-Reply-To: <46657D82.2050808@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
Message-ID: <Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>



> I have attached what I got so far if you feel like taking a look, but it 
> is probably nasty by your standards :)

Good, this is exactly what I want.  Yes, there are a few things here that 
you will want to learn how to fix.  Let me point out one or two, and I'm 
sure others here on the list can chime in too.

#####################################
## within definition of char_sheet():

     if month == 1:
         month = "January"
     elif month == 2:
         month = "February"
     elif month == 3:
         month = "March"
     ...
#####################################

Make this a separate function: the essence of this block of code is pretty 
self-contained as a number-to-month-string converter.  If you need more 
information on this, please ask, and we can talk about it more.


There is also a much nicer way to express the code: rather than make it 
conditional logic, just build a data structure that naturally expresses 
the mapping from a number to a string.  There are two data structures that 
fit the above nicely: a "list" and a "hashtable".  For the above, a list 
naturally works out.

     ######################################
     ## pseudocode
     months = ["January", "February", ...]
     monthName = months[monthNumeral - 1]
     ######################################

Do this, and that block of code reduces from twenty-four lines to about 
three.



I'm looking at the number of attributes you're storing as a Player.

###########################################################################
def char_sheet(player, title, character, password, year, month, influence,
                cur_influence, sp, sl, income, funds,
                mid, mistress_name, mistress_sl, club, house, horses,
                regiment, rank, ma, appointment, strength, con,
                max_endurance, cur_endurance, rapier, dagger, sabre,
                cutlass, two_hand):
###########################################################################

All these values "belong" together.  Rather than pass them separately, 
glue them together as a "structure".  In Python, can we use a class to 
glue things together.


For example, if we have a Person with a name and address:

###################################
class Person:
     def __init__(self, name, addr):
         self.name = name
         self.addr = addr

p = Person("scott", "slewin")
print p.name
###################################

Then we can pass a whole Person object around now.


Going back to your code, as it is, if you need to talk about a character, 
you have to carry around all the attributes of your character by hand and 
hope to get the order of the attributes right in char_sheet() and 
char_save() and anything else that does character-related stuff.


Consolidating the attributes in an object will also let you take advantage 
of Python's pickling a lot better.  The pickling code knows how to 
serialize whole objects, so rather than:

#################################################################
def char_save(player, title, character, password, family, influence, 
cur_influence, sl, allowance, funds, mid,
mistress_name, mistress_sl, club, house, horses, regiment, rank, ma, 
appointment, strength, con, cur_endurance,
rapier, dagger, sabre, cutlass, two_hand):
     '''This saves the character to the harddrive'''
     path = "./characters/" + player
     cfile = open(path, "w")
     cPickle.dump(player, cfile)
     cPickle.dump(title, cfile)
     cPickle.dump(character, cfile)
     ## ...
#################################################################


the code will dissolve into something that looks like:

#############################################
def char_save(character):
     """char_save: character -> void"""
     path = "./characters/" + character.player
     cfile = open(path, "w")
     cPickle.dump(character, cfile)
#############################################

Again, a reduction from about eighty lines of code to about four.


There are a few other things to discuss about in the code, but I should 
let you take a look again and respond before going on.  If you have more 
questions, please feel free to ask the list.

From slewin at rogers.com  Tue Jun  5 18:16:40 2007
From: slewin at rogers.com (scott)
Date: Tue, 05 Jun 2007 12:16:40 -0400
Subject: [Tutor] i++
In-Reply-To: <Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
Message-ID: <46658C68.7050408@rogers.com>

Danny Yoo wrote:
> 
> 
>> I have attached what I got so far if you feel like taking a look, but 
>> it is probably nasty by your standards :)
> 
> Good, this is exactly what I want.  Yes, there are a few things here 
> that you will want to learn how to fix.  Let me point out one or two, 
> and I'm sure others here on the list can chime in too.
> 
> #####################################
> ## within definition of char_sheet():
> 
>     if month == 1:
>         month = "January"
>     elif month == 2:
>         month = "February"
>     elif month == 3:
>         month = "March"
>     ...
> #####################################
> 
> Make this a separate function: the essence of this block of code is 
> pretty self-contained as a number-to-month-string converter.
I never thought about that, I will put it into its own function.  That
makes sense because I may actually need to use that number-month
converter in another part of the program.

> There is also a much nicer way to express the code: rather than make it 
> conditional logic, just build a data structure that naturally expresses 
> the mapping from a number to a string.  There are two data structures 
> that fit the above nicely: a "list" and a "hashtable".  For the above, a 
> list naturally works out.
> 
>     ######################################
>     ## pseudocode
>     months = ["January", "February", ...]
>     monthName = months[monthNumeral - 1]
>     ######################################
> 
> Do this, and that block of code reduces from twenty-four lines to about 
> three.
Thanks, that is a great idea.  Also, this will be a good exercise for me
to learn about list.


> I'm looking at the number of attributes you're storing as a Player.
Yea, both Pychecker and pylint complained about that.

> All these values "belong" together.  Rather than pass them separately, 
> glue them together as a "structure".  In Python, can we use a class to 
> glue things together...
Okay, that makes good sense :)  This should be a good exercise for OOP
Programming :)


> There are a few other things to discuss about in the code, but I should 
> let you take a look again and respond before going on.  If you have more 
> questions, please feel free to ask the list.

Thanks, I never even expected you to go through the code :)  I will work
  at your suggestions and will get back to you if I have any problems.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)


From dyoo at cs.wpi.edu  Tue Jun  5 18:40:49 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Tue, 5 Jun 2007 12:40:49 -0400 (EDT)
Subject: [Tutor] i++
In-Reply-To: <46658B9E.7010604@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
Message-ID: <Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>

>>  All these values "belong" together.  Rather than pass them separately,
>>  glue them together as a "structure".  In Python, can we use a class to
>>  glue things together...
>
> Okay, that makes good sense :)  This should be a good exercise for OOP 
> Programming :)

Just to clarify: structures and the idea of aggregation are a general 
concept that almost all modern programming languages provide.  It's not 
OOP-specific.


>>  There are a few other things to discuss about in the code, but I
>>  should let you take a look again and respond before going on.  If you
>>  have more questions, please feel free to ask the list.
>
> Thanks, I never even expected you to go through the code :)

Code review is at the heart of learning to program better.  There's too 
much potential in writing code in isolation to do something that looks 
like it is doing work, but is either fragile or verbose (or broken!).

I guess I'm trying to make the point: there are things that are bigger and 
more important to learn than the best way to increment 'i'.  *wink*  So 
keep your eyes looking out for them.



> I will work at your suggestions and will get back to you if I have any 
> problems.

Good!  Keep the folks on Python-Tutor up to date with your progress.

From jason at asahnekec.com  Tue Jun  5 21:04:49 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Tue, 5 Jun 2007 15:04:49 -0400
Subject: [Tutor] example of spawn
Message-ID: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>

Would someone please provide me a short, simple example of the spawn statement.  I am having trouble figuring the syntax out.

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070605/63f04733/attachment.htm 

From bgailer at alum.rpi.edu  Tue Jun  5 22:47:34 2007
From: bgailer at alum.rpi.edu (Bob Gailer)
Date: Tue, 05 Jun 2007 13:47:34 -0700
Subject: [Tutor] python & google gear
In-Reply-To: <825bef0c0706050411y31173e75saa377f87bfac5196@mail.gmail.com>
References: <825bef0c0706050411y31173e75saa377f87bfac5196@mail.gmail.com>
Message-ID: <4665CBE6.1020607@alum.rpi.edu>

Picio wrote:
> Salve, qualcuno sa dirmi se esiste una API in python per google gear?
> code.google.com/apis/gears
>   
A similar question was asked on py-gwt. Here is the thread. I suggest 
you subscribe to py-gwt and follow the thread.

http://pyworks.org/mailman/listinfo/py-gwt

On Thu, 31 May 2007 16:23:41 +0200, "Hernan M Foffani"
<hfoffani at gmail.com> said:

> Have you heard of Google Gears?
> http://gears.google.com/
> According to
> http://googlewebtoolkit.blogspot.com/2007/05/gwt-gears-up.html
> Google have incorporated Gears to GWT library.
> 
> Is the same feasible in pyjamas?

It absolutely should be possible -- should be a simple port from the GWT
work.

Anyone want to take it on as a nice little project to get involved in
pyjamas?

James

-- 
Bob Gailer
510-978-4454


From slewin at rogers.com  Tue Jun  5 23:37:56 2007
From: slewin at rogers.com (scott)
Date: Tue, 05 Jun 2007 17:37:56 -0400
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
	<Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
Message-ID: <4665D7B4.5060306@rogers.com>

Danny Yoo wrote:
>> I will work at your suggestions and will get back to you if I have any 
>> problems.
> 
> Good!  Keep the folks on Python-Tutor up to date with your progress.
Here is the code changes I made based on your suggestions:

I put all the values together into a class

#######################################
class Character_stats:
     def __init__(self, player, title, name, password, family, sl_inf, 
mistress_inf, mistress2_inf, appt_inf, appt2_inf, spec_inf,  sl, 
allowance, funds, mid, mistress_name, mistress_sl, club, house, horses, 
regiment, rank, ma, appointment, strength, con, cur_endurance, rapier, 
dagger, sabre, cutlass, two_hand):
         self.player = player
         self.title = title
         self.name = name
         self.password = password
         self.family = family
         self.sl_inf = sl_inf
         self.mistress_inf = mistress_inf
         self.mistress2_inf = mistress2_inf
         self.appt_inf = appt_inf
         self.appt2_inf = appt2_inf
         self.spec_inf = spec_inf
         self.sl = sl
         self.allowance = allowance
         self.funds = funds
         self.mid = mid
         self.mistress_name = mistress_name
         self.mistress_sl = mistress_sl
         self.club = club
         self.house = house
         self.horses = horses
         self.regiment = regiment
         self.rank = rank
         self.ma = ma
         self.appointment = appointment
         self.strength = strength
         self.con = con
         self.cur_endurance = cur_endurance
         self.rapier = rapier
         self.dagger = dagger
         self.sabre = sabre
         self.cutlass = cutlass
         self.two_hand = two_hand
#############################

There where some values I did not want saved to the character file.  A 
couple where values that are for all characters, so I put them into 
their own class.

###############################
class Master_stats:
     def __init__(self, year, month):
         self.year = year
         self.month = month
###############################
There are only two values now, but that will most likely increase as I 
get further into the program.


Lastly, I put the temporary values that I did not want saved on the 
sheet into their own class.

#################################
class Character_temp:
     def __init__(self, max_endurance):
         self.sp = 0
         self.income = 0
         self.max_endurance = max_endurance
         self.bribe_inf = 0
##################################

As you mentioned, my character save file is only a few lines long now :)
##################################
def char_save(character):
     '''This saves the character to the harddrive'''
     path = "./characters/" + character.player
     cfile = open(path, "w")
     cPickle.dump(character, cfile)
     return
##################################

With the months, I used both your suggestions.  I used the list and then 
put it into a function.

###################################
def month_name(monthNumeral):
     """Returns the month name as a string"""
     months = ["January", "February", "March", "April", "May", "June", 
    "July", "August", "September", "October", "November", "December"]
     return months[monthNumeral - 1]
###################################

and I was able to call then function nicely by using:

####################################
s = "\n" + month_name(master.month) + " " + str(master.year)
cfile.write(s)

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 11667 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070605/d19d4459/attachment.py 

From alan.gauld at btinternet.com  Tue Jun  5 23:32:23 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 5 Jun 2007 22:32:23 +0100
Subject: [Tutor] example of spawn
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>
Message-ID: <f44kqk$o81$1@sea.gmane.org>

"Jason Coggins" <jason at asahnekec.com> wrote

> Would someone please provide me a short, simple 
> example of the spawn statement.  
> I am having trouble figuring the syntax out.

There are two examples in the os module documentation.

http://docs.python.org/lib/os-process.html


What part do you not understand?


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




From jason at asahnekec.com  Wed Jun  6 01:21:27 2007
From: jason at asahnekec.com (Jason Coggins)
Date: Tue, 5 Jun 2007 19:21:27 -0400
Subject: [Tutor] example of spawn
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>
	<f44kqk$o81$1@sea.gmane.org>
Message-ID: <000901c7a7c8$3fcf8190$21137044@dunamis34752e9>

In the example listed below, reproduced from the web page you recommended, 
what does `cp`, `cp` and `/dev/null` do?  I am assuming `index.html` is the 
name of the program that will be launched.

example:----------------------------------------------
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
--------------------------------------------------------

Jason

----- Original Message ----- 
From: "Alan Gauld" <alan.gauld at btinternet.com>
To: <tutor at python.org>
Sent: Tuesday, June 05, 2007 5:32 PM
Subject: Re: [Tutor] example of spawn


> "Jason Coggins" <jason at asahnekec.com> wrote
>
>> Would someone please provide me a short, simple
>> example of the spawn statement.
>> I am having trouble figuring the syntax out.
>
> There are two examples in the os module documentation.
>
> http://docs.python.org/lib/os-process.html
>
>
> What part do you not understand?
>
>
> -- 
> 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 dyoo at cs.wpi.edu  Wed Jun  6 03:14:57 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Tue, 5 Jun 2007 21:14:57 -0400 (EDT)
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <4665D7B4.5060306@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
	<Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
	<4665D7B4.5060306@rogers.com>
Message-ID: <Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>

> There where some values I did not want saved to the character file.  A couple 
> where values that are for all characters, so I put them into their own class.
>
> ###############################
> class Master_stats:
>     def __init__(self, year, month):
>         self.year = year
>         self.month = month
> ###############################
> There are only two values now, but that will most likely increase as I get 
> further into the program.


Hi Scott,


Sounds good.  Ok, let's re-review the code now.


####################################################################
def mfile_read():
     '''This will open the master file and load all the variables'''
     i = 0
     [some code cut]

     master = cPickle.load(mfile)
     mfile.close()
     return [master.year, master.month]
####################################################################

In the context of the new Master_stats class, it makes more sense for 
mfile_read() to return a Master_stats object now rather than a two-tuple 
list.  You already had instincts about bundling year and month together 
here, which is good, so if you follow through on this, it'll let you 
dissolve a few more lines of legacy code.



###################################################
def char_save(character):
     '''This saves the character to the harddrive'''
     path = "./characters/" + character.player
     cfile = open(path, "w")
     cPickle.dump(character, cfile)
     return
###################################################

To make the code a little safer, explicitely close the file here.  The 
Python language itself doesn't say that 'cfile' here will be closed at the 
end of char_save() --- the fact that it does happen is an implementation 
detail, since Jython does something different! --- so it's better just to 
avoid the possible ambiguity and explicitely close files resources.



Ok, looking at create_char() since it's one of the larger functions.  The 
value of 's' in create_char() is mixed: at one point, it's an integer, at 
other instances, a string.  There's a possible flow of control that 
doesn't make sense to me.

##########################################################
     s = 0
     while s < 1 or s > 3:
         print 'Is', player, 'the player you wanted?'
         s = raw_input()
         if s == 'y' or s == 'yes':
             break
         elif s == 'n' or s == 'no':
             return
         else:
             print '\nplease select y, n, yes, or no\n'
     while s < 1 or s > 3:
         ## code cut
##########################################################

The condition at the last line there should be a type error: 's' at the 
end is a string, and strings should not be comparable to numbers. 
Unfortunately, Python suffers a defect here: it is way too lax in this 
area, so something consistent (but meaningless!) is going to happen here.


Also, around this code, I see I lot of code duplication.

##############################################################
     while s < 1 or s > 3:
         print '\nIs', name, 'a sufficient character name?'
         s = raw_input()
         if s == "y" or s == "yes":
             break
         elif s == "n" or s == "no":

             while s < 1 or s > 3:
                 print '\nIs the alternate name', alt_name,
                 print 'a sufficient character name?'
                 s = raw_input()
                 if s == "y" or s == "yes":
                     name = alt_name
                     break
                 elif s == "n" or s == "no":
                     return
                 else:
                     print '\nplease select y, n, yes, or no\n'

             break

         else:
             print '\nplease select y, n, yes, or no\n'
##############################################################

The duplication is the logic of first prompting a question, then repeating 
the question until we get a straight yes-or-no.  The type mistake with 's' 
is probably a side effect of a bad copy-and-paste.  Let that be a lesson 
to you!  *grin*


But the fix isn't just to fix the type error everywhere: the real fix is 
to get rid of the copy-and-pasting altogether.  Make a function to handle 
the asking of yes/no style questions.  Write a function called is_yes() 
which takes in a question string, and returns True or False.  If we put on 
our "wishing makes it so" hat, here's what we'd like:

##################################
>>> is_yes("did you like this?")
did you like this?
huh?
please select y, n, yes, or no
I don't want to
please select y, n, yes, or no
oh all right
please select y, n, yes, or no
y
True
##################################

So is_yes() should be written to keep asking, and at the end, return True 
if the user affirmed the choice, and False otherwise.


If you have an is_yes() helper function, then the logic of asking all 
those questions dissolves down to:

##############################################################
if not is_yes("Is " + name + " a sufficient character name?"):
     if is_yes("Is the alternate name " + alt_name +
               " a sufficient character name?"):
          name = alt_name
     else:
         return
...
##############################################################

This should make the logic of name selection much clearer than it is right 
now.  At the moment, it's cluttered with the other auxiliary logic you're 
using to make sure the user types in "yes" or "no", and it makes it hard 
to see the intent of the code.


If you have questions about any of this, ask, and one of us here on Tutor 
will be happy to talk about this more.

From mwalsh at groktech.org  Wed Jun  6 03:58:07 2007
From: mwalsh at groktech.org (Martin Walsh)
Date: Tue, 05 Jun 2007 20:58:07 -0500
Subject: [Tutor] example of spawn
In-Reply-To: <000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>	<f44kqk$o81$1@sea.gmane.org>
	<000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
Message-ID: <466614AF.3060808@groktech.org>

Jason Coggins wrote:
> In the example listed below, reproduced from the web page you recommended, 
> what does `cp`, `cp` and `/dev/null` do?  I am assuming `index.html` is the 
> name of the program that will be launched.
> 
> example:----------------------------------------------
> os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
> --------------------------------------------------------

I don't fully understand the workings of os.spawnlp myself, but it seems
clear that the author of the example was writing it for use in a
unix/linux environment. 'cp' is a program (for copying files and
folders). And the second 'cp', 'index.html' & '/dev/null' -- the
argument list. So, the example above would seem somewhat equivalent to
the following linux shell command:

  host:~$ cp index.html /dev/null

which would copy the file 'index.html' (from the current directory) to
'/dev/null'.

'/dev/null' is a special file in a *nix environment that discards any
data written to it: http://en.wikipedia.org/wiki//dev/null
I can't think of a windows parallel to /dev/null.

I may be completely wrong, but I don't beleive os.spawnlp is available
on windows. But if you are a windows user, don't despair -- the
subprocess module equivalent should work in it's absence:
http://docs.python.org/lib/node538.html

import subprocess
# replacement for os.spawnlp(os.P_WAIT, ...)
retcode = subprocess.call(['notepad.exe', 'myfile.txt'])

In general, I believe use of the subprocess module is recommended over
os.spawn*, os.popen*, etc. -- regardless of the platform.

HTH,
Marty

From mail at timgolden.me.uk  Wed Jun  6 09:47:41 2007
From: mail at timgolden.me.uk (Tim Golden)
Date: Wed, 06 Jun 2007 08:47:41 +0100
Subject: [Tutor] example of spawn
In-Reply-To: <466614AF.3060808@groktech.org>
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>	<f44kqk$o81$1@sea.gmane.org>	<000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
	<466614AF.3060808@groktech.org>
Message-ID: <4666669D.7070101@timgolden.me.uk>

Martin Walsh wrote:
> '/dev/null' is a special file in a *nix environment that discards any
> data written to it: http://en.wikipedia.org/wiki//dev/null
> I can't think of a windows parallel to /dev/null.

Merely for completeness, the windows (sort of)
equivalent is the little-known NUL special
filename. So:

   dir > nul

has the effect of showing no output. Likewise:

   copy abc.txt nul

will do nothing. (Useful, no?)

Confusion typically arises, because the command
line will swallow any part a filename after the
NUL, so NUL, NUL: and NUL.TXT are all equivalent.

Try this:

   dir > nul.txt

No output, and no file called "nul.txt". And
again:

   copy abc.txt nul.txt

will likewise do nothing. On the other hand:

   dir > null

will generate a filename "null" with the output
of the dir command.

Bit of a sidetrack, I admit, but just in case
anyone was wondering :)

TJG

From rikard.bosnjakovic at gmail.com  Wed Jun  6 10:52:01 2007
From: rikard.bosnjakovic at gmail.com (Rikard Bosnjakovic)
Date: Wed, 6 Jun 2007 10:52:01 +0200
Subject: [Tutor] example of spawn
In-Reply-To: <466614AF.3060808@groktech.org>
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9>
	<f44kqk$o81$1@sea.gmane.org>
	<000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
	<466614AF.3060808@groktech.org>
Message-ID: <d9e88eaf0706060152x1be6412ayce303a9a6e1b0bb@mail.gmail.com>

On 6/6/07, Martin Walsh <mwalsh at groktech.org> wrote:

> I can't think of a windows parallel to /dev/null.

"nul".

Try "dir > nul" in a command shell.


-- 
- Rikard - http://bos.hack.org/cv/

From sanelson at gmail.com  Wed Jun  6 16:28:15 2007
From: sanelson at gmail.com (Stephen Nelson-Smith)
Date: Wed, 6 Jun 2007 15:28:15 +0100
Subject: [Tutor] [OT] Urgent Help Needed
Message-ID: <b6131fdc0706060728r24740cffq3e79e5bdc8050dbc@mail.gmail.com>

Hello friends,

I urgently need to get hold of someone who can help me with the
closing stages of a database project - porting data from an old system
to a completely rewritten schema.

My lead developer has suffered a bereavement, and I need a SQL expert,
or programmer who could accomplish the porting.

I've budgeted a week to get the task done, so need someone who could
join my team at this very short notice on a week's contract.

If you know anyone, or feel you fit the bill, let me know off list.
I'm based in North London.

Thanks, and sorry for taking advantage of the list - hope you al understand.

S.

From mail at timgolden.me.uk  Wed Jun  6 16:36:32 2007
From: mail at timgolden.me.uk (Tim Golden)
Date: Wed, 06 Jun 2007 15:36:32 +0100
Subject: [Tutor] [OT] Urgent Help Needed
In-Reply-To: <b6131fdc0706060728r24740cffq3e79e5bdc8050dbc@mail.gmail.com>
References: <b6131fdc0706060728r24740cffq3e79e5bdc8050dbc@mail.gmail.com>
Message-ID: <4666C670.7060006@timgolden.me.uk>

Stephen Nelson-Smith wrote:
> Hello friends,
> 
> I urgently need to get hold of someone who can help me with the
> closing stages of a database project - porting data from an old system
> to a completely rewritten schema.
> 
> My lead developer has suffered a bereavement, and I need a SQL expert,
> or programmer who could accomplish the porting.
> 
> I've budgeted a week to get the task done, so need someone who could
> join my team at this very short notice on a week's contract.
> 
> If you know anyone, or feel you fit the bill, let me know off list.
> I'm based in North London.
> 
> Thanks, and sorry for taking advantage of the list - hope you al understand.
> 
> S.

You might want to mention the database (or databases) in
question. Given the short timeframes, people'd feel more
confident if it was the system they're familiar with.

(I know, in theory SQL is SQL but...)
TJG

From sanelson at gmail.com  Wed Jun  6 17:04:02 2007
From: sanelson at gmail.com (Stephen Nelson-Smith)
Date: Wed, 6 Jun 2007 16:04:02 +0100
Subject: [Tutor] [OT] Urgent Help Needed
In-Reply-To: <4666C670.7060006@timgolden.me.uk>
References: <b6131fdc0706060728r24740cffq3e79e5bdc8050dbc@mail.gmail.com>
	<4666C670.7060006@timgolden.me.uk>
Message-ID: <b6131fdc0706060804m3ef04116g5e8d936fc30d2c2b@mail.gmail.com>

On 6/6/07, Tim Golden <mail at timgolden.me.uk> wrote:

> You might want to mention the database (or databases) in
> question. Given the short timeframes, people'd feel more
> confident if it was the system they're familiar with.

Sorry yes.  We have an old (primitive) accounts system, which is
basically one big table, effectively a log of purchases.  This is in
MySQL 4.

We have a new model, which abstracts out into half a dozen tables
representing different entities.  This is going to be in MySQL 5.

What we're trying to do is extract identities from the transaction
table, accounting for things like name changes, company changes.
We've been doing it with SQL statements, and I have some code snippets
I can show.

S.

From rh00667 at gmail.com  Wed Jun  6 17:17:05 2007
From: rh00667 at gmail.com (roberto)
Date: Wed, 6 Jun 2007 17:17:05 +0200
Subject: [Tutor] lists - append - unique and sorted
Message-ID: <67160fb20706060817m390598a7we3191977b09c4e65@mail.gmail.com>

hi,

can i append a item to a list using criterias:

- UNIQUE - if there already exist don't append

and/or

- SORTED - INSERT in the correct place using some criteria?

tks in advance

From thorsten at thorstenkampe.de  Wed Jun  6 18:01:47 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Wed, 6 Jun 2007 17:01:47 +0100
Subject: [Tutor] lists - append - unique and sorted
References: <67160fb20706060817m390598a7we3191977b09c4e65@mail.gmail.com>
Message-ID: <f46lpd$s4r$1@sea.gmane.org>

* roberto (Wed, 6 Jun 2007 17:17:05 +0200)
> can i append a item to a list using criterias:
> 
> - UNIQUE - if there already exist don't append

test whether it's already in the with "in" or use sets
 
> and/or
> 
> - SORTED - INSERT in the correct place using some criteria?

insert and then sort again by this criterion


From kent37 at tds.net  Wed Jun  6 19:38:46 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 06 Jun 2007 13:38:46 -0400
Subject: [Tutor] lists - append - unique and sorted
In-Reply-To: <67160fb20706060817m390598a7we3191977b09c4e65@mail.gmail.com>
References: <67160fb20706060817m390598a7we3191977b09c4e65@mail.gmail.com>
Message-ID: <4666F126.1040902@tds.net>

roberto wrote:
> hi,
> 
> can i append a item to a list using criterias:
> 
> - UNIQUE - if there already exist don't append

if item not in lst: lst.append(item)

"item not in lst" uses a linear search so performance deteriorates as 
len(lst) grows. If you don't care about the order of elements in lst, a 
set give better performance.

> and/or
> 
> - SORTED - INSERT in the correct place using some criteria?

Resorting is pretty fast, or see the bisect module.

Kent

From slewin at rogers.com  Wed Jun  6 20:17:49 2007
From: slewin at rogers.com (scott)
Date: Wed, 06 Jun 2007 14:17:49 -0400
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
	<Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
	<4665D7B4.5060306@rogers.com>
	<Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>
Message-ID: <4666FA4D.70603@rogers.com>

Danny Yoo wrote:
> In the context of the new Master_stats class, it makes more sense for 
> mfile_read() to return a Master_stats object now rather than a two-tuple 
> list.
I was able to change the [year, month] to just master and it worked 
fine.  I was also able to do master = mfile_read() and it worked fine as 
well.


> To make the code a little safer, explicitely close the file here.
Oh, I forgot to add in the close; I intended to have one put in.  I also 
noticed I forgot to put a close in for the char_sheet as well, so I 
added one in.  I assume that it is good programming practise to close 
all open files when they are not needed anymore?


> Ok, looking at create_char() since it's one of the larger functions.  
> The value of 's' in create_char() is mixed: at one point, it's an 
> integer, at other instances, a string.  There's a possible flow of 
> control that doesn't make sense to me...
I wrote the is_yes as follows and it seems to work fine.

###################################################
def is_yes(question):
     i = 0
     while i == 0:
         s = raw_input(question)
         if s == 'y' or s == 'yes':
             return True
         elif s == 'n' or s == 'no':
             return False
         else:
             print '\nplease select y, n, yes, or no\n'
###################################################

I was also able to shrink the code down to:

###################################################
     if not is_yes('Is ' + name + ' a sufficient character name?'):
         if is_yes('Is ' + alt_name + ' a sufficient character name?'):
             name = alt_name
         else:
             return
###################################################

You will probably notice a new unused class.  I am starting to do the 
main part of the program and the first thing I need to do is read a very 
large text file generated from a web form.  What I was thinking about 
doing was creating a function that reads the text form and then place 
all the values into variables "glued" together in a class.  I can then 
pass that class back and use the variables when I need them.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 12173 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070606/443b9086/attachment-0001.py 

From alan.gauld at btinternet.com  Wed Jun  6 21:39:14 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 6 Jun 2007 20:39:14 +0100
Subject: [Tutor] Engarde program was: i++
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu><001201c7a622$fba7de50$21137044@dunamis34752e9><f3vj9e$6t6$1@sea.gmane.org>
	<46656E43.8050206@rogers.com><Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu><46657D82.2050808@rogers.com><Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu><46658B9E.7010604@rogers.com><Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu><4665D7B4.5060306@rogers.com><Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>
	<4666FA4D.70603@rogers.com>
Message-ID: <f472ig$fa7$1@sea.gmane.org>


"scott" <slewin at rogers.com> wrote

> added one in.  I assume that it is good programming practise to 
> close
> all open files when they are not needed anymore?

Yes, its good practice.

> I wrote the is_yes as follows and it seems to work fine.

Almost, but not quite ideal, see below:

> ###################################################
> def is_yes(question):
>     i = 0
>     while i == 0:

You never change i so this is always true.
Therefore you can express that better with

while True:

>         s = raw_input(question)

One wee tweak that might be friendly to your users is to
lower-case the result from raw_input:

         s = raw_input(question).lower()

So now even if the user types 'Y' or 'Yes' it will
get converted to 'y' or 'yes' etc

>         if s == 'y' or s == 'yes':
>             return True
>         elif s == 'n' or s == 'no':
>             return False
>         else:
>             print '\nplease select y, n, yes, or no\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  Wed Jun  6 21:42:07 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 6 Jun 2007 20:42:07 +0100
Subject: [Tutor] [OT] Urgent Help Needed
References: <b6131fdc0706060728r24740cffq3e79e5bdc8050dbc@mail.gmail.com>
Message-ID: <f472nt$g09$1@sea.gmane.org>


"Stephen Nelson-Smith" <sanelson at gmail.com> wrote

> My lead developer has suffered a bereavement, and I need a SQL 
> expert,
> or programmer who could accomplish the porting.

This being the tutor list, you are more likely to get a SQL expert
on the main comp.lang,python list and of course the database
topic list too. But I'm guessing you already thought of that?

Alan G. 



From dyoo at cs.wpi.edu  Wed Jun  6 22:12:14 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Wed, 6 Jun 2007 16:12:14 -0400 (EDT)
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <4666FA4D.70603@rogers.com>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
	<Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
	<4665D7B4.5060306@rogers.com>
	<Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>
	<4666FA4D.70603@rogers.com>
Message-ID: <Pine.LNX.4.63.0706061609030.5867@cs.wpi.edu>



On Wed, 6 Jun 2007, scott wrote:

> Danny Yoo wrote:
>>  In the context of the new Master_stats class, it makes more sense for
>>  mfile_read() to return a Master_stats object now rather than a two-tuple
>>  list.
> I was able to change the [year, month] to just master and it worked fine.  I 
> was also able to do master = mfile_read() and it worked fine as well.

Hi Scott,


Double check the definition of mfile_read().  It has a possible type error 
in terms of the values it returns back to the user.

#####################################################################
def mfile_read():
     '''This will open the master file and load all the variables'''
     try:
         mfile = open("./Master/mfile", "r")
     except:
         mfile = open("./Master/mfile", "w")
         mfile.close()
         print "File could not be opened, so I created one"
         return [1631, 8]

     master = cPickle.load(mfile)
     mfile.close()
     return master
#####################################################################

From slewin at rogers.com  Wed Jun  6 23:08:04 2007
From: slewin at rogers.com (scott)
Date: Wed, 06 Jun 2007 17:08:04 -0400
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <f472ig$fa7$1@sea.gmane.org>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu><001201c7a622$fba7de50$21137044@dunamis34752e9><f3vj9e$6t6$1@sea.gmane.org>	<46656E43.8050206@rogers.com><Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu><46657D82.2050808@rogers.com><Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu><46658B9E.7010604@rogers.com><Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu><4665D7B4.5060306@rogers.com><Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>	<4666FA4D.70603@rogers.com>
	<f472ig$fa7$1@sea.gmane.org>
Message-ID: <46672234.6020703@rogers.com>

Alan Gauld wrote:
> You never change i so this is always true.
> Therefore you can express that better with...
Thanks for your suggestions, I put together the following based on them:
##############################################
def is_yes(question):
     while True:
         s = raw_input(question).lower()
         if s == 'y' or s == 'yes':
             return True
         elif s == 'n' or s == 'no':
             return False
         else:
             print '\nplease select y, n, yes, or no\n'
################################################

It seems to work perfectly :)

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)

From slewin at rogers.com  Wed Jun  6 23:17:13 2007
From: slewin at rogers.com (scott)
Date: Wed, 06 Jun 2007 17:17:13 -0400
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <Pine.LNX.4.63.0706061609030.5867@cs.wpi.edu>
References: <004501c7a612$bb583210$21137044@dunamis34752e9><46631628.3030001@alum.rpi.edu><000401c7a61c$658af890$21137044@dunamis34752e9><46632383.6030409@alum.rpi.edu>
	<001201c7a622$fba7de50$21137044@dunamis34752e9>
	<f3vj9e$6t6$1@sea.gmane.org> <46656E43.8050206@rogers.com>
	<Pine.LNX.4.63.0706051026550.1357@cs.wpi.edu>
	<46657D82.2050808@rogers.com>
	<Pine.LNX.4.63.0706051117160.3825@cs.wpi.edu>
	<46658B9E.7010604@rogers.com>
	<Pine.LNX.4.63.0706051222480.5293@cs.wpi.edu>
	<4665D7B4.5060306@rogers.com>
	<Pine.LNX.4.63.0706052019410.24980@cs.wpi.edu>
	<4666FA4D.70603@rogers.com>
	<Pine.LNX.4.63.0706061609030.5867@cs.wpi.edu>
Message-ID: <46672459.5050508@rogers.com>

Danny Yoo wrote:
> Double check the definition of mfile_read().  It has a possible type 
> error in terms of the values it returns back to the user.
Oh, I see.  I forgot to change the "if file does not exist part" when i 
changed the other half.  I have changed it and is seems to work when 
there is no file.

#################################################
def mfile_read():
     '''This will open the master file and load all the variables'''
     try:
         mfile = open("./Master/mfile", "r")
     except:
         mfile = open("./Master/mfile", "w")
         mfile.close()
         print "File could not be opened, so I created one"
         master = Master_stats(1631, 8)
         return master

     master = cPickle.load(mfile)
     mfile.close()
     return master
##################################################

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)

From David.Heiser at intelliden.com  Thu Jun  7 00:11:07 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Wed, 6 Jun 2007 16:11:07 -0600
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <46672234.6020703@rogers.com>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3A4@csoexc02.intelliden.net>

or..

def is_yes(question):
     while True:
         try:
             s = raw_input(question).lower()[0]
             if s == 'y':
                 return True
             elif s == 'n':
                 return False
         except:
             pass     ## This traps the condition where a user just
presses enter
         print '\nplease select y, n, yes, or no\n'


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of scott
Sent: Wednesday, June 06, 2007 3:08 PM
To: tutor at python.org
Subject: Re: [Tutor] Engarde program was: i++


Alan Gauld wrote:
> You never change i so this is always true.
> Therefore you can express that better with...
Thanks for your suggestions, I put together the following based on them:
##############################################
def is_yes(question):
     while True:
         s = raw_input(question).lower()
         if s == 'y' or s == 'yes':
             return True
         elif s == 'n' or s == 'no':
             return False
         else:
             print '\nplease select y, n, yes, or no\n'
################################################

It seems to work perfectly :)

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty
Fawn) _______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

From bradleytompkins at gmail.com  Thu Jun  7 01:41:31 2007
From: bradleytompkins at gmail.com (Brad Tompkins)
Date: Wed, 6 Jun 2007 16:41:31 -0700
Subject: [Tutor] Multi-line comments?
Message-ID: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>

Hello everyone,

This may seem like a pretty basic question but it's driving me crazy.

Is there a way to make use of multi-line comments when programming using
python?  Having to stick a # in front of every line gets pretty tedious when
I want to make a comment more detailed than I normally would.

If there isn't a way, can someone recommend a text editor (I know emacs and
probably vi can do this, but they seem difficult to use) that will comment
out blocks of text automatically for me?

Thanks,

Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070606/1d0fbd63/attachment.html 

From nuin at genedrift.org  Thu Jun  7 01:44:58 2007
From: nuin at genedrift.org (Paulo Nuin)
Date: Wed, 06 Jun 2007 19:44:58 -0400
Subject: [Tutor] Multi-line comments?
In-Reply-To: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
Message-ID: <466746FA.1070408@genedrift.org>

Hi Brad

Use something like this

'''your
comments
here'''

Three single quotes will do it.

HTH

Paulo

Brad Tompkins wrote:
> Hello everyone,
>
> This may seem like a pretty basic question but it's driving me crazy.
>
> Is there a way to make use of multi-line comments when programming 
> using python?  Having to stick a # in front of every line gets pretty 
> tedious when I want to make a comment more detailed than I normally 
> would.
>
> If there isn't a way, can someone recommend a text editor (I know 
> emacs and probably vi can do this, but they seem difficult to use) 
> that will comment out blocks of text automatically for me?
>
> Thanks,
>
> Brad
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


From john at fouhy.net  Thu Jun  7 01:54:31 2007
From: john at fouhy.net (John Fouhy)
Date: Thu, 7 Jun 2007 11:54:31 +1200
Subject: [Tutor] Multi-line comments?
In-Reply-To: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
Message-ID: <5e58f2e40706061654w7774ad41y9d6e9c944cca1c05@mail.gmail.com>

On 07/06/07, Brad Tompkins <bradleytompkins at gmail.com> wrote:
> Is there a way to make use of multi-line comments when programming using
> python?  Having to stick a # in front of every line gets pretty tedious when
> I want to make a comment more detailed than I normally would.
>
> If there isn't a way, can someone recommend a text editor (I know emacs and
> probably vi can do this, but they seem difficult to use) that will comment
> out blocks of text automatically for me?

With emacs, you can highlight a region and choose "Comment out region"
from the menu bar.  With vi, to comment out the current line and the
next n, type   :,+ns/^/#/

But the real answer to your question is to use docstrings.  A
docstring is a multiline string (delimited by """ """) at the start of
a block of code.  A typical python module might look like this:

--- foo.py ---
""" Module for working with foos.

This module adds foo support to python.
etc.
"""

class Foo(object):
   """ Main foo class.

   More stuff.
   """

   def useBar(self, bar):
      """ Apply this foo to a bar. """
-------

Python's help system can then pick up the docstrings automatically.
eg, if I started the interpreter and typed 'import Foo', then
'help(Foo)' would give me the module docstring, 'help(Foo.Foo)' would
give me the class docstring, and so on.

Check out the source code for python modules on your system (in the
lib directory of your install) for lots of examples.

-- 
John.

From rh00667 at gmail.com  Thu Jun  7 06:50:56 2007
From: rh00667 at gmail.com (roberto)
Date: Thu, 7 Jun 2007 06:50:56 +0200
Subject: [Tutor] Multi-line comments?
In-Reply-To: <5e58f2e40706061654w7774ad41y9d6e9c944cca1c05@mail.gmail.com>
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
	<5e58f2e40706061654w7774ad41y9d6e9c944cca1c05@mail.gmail.com>
Message-ID: <67160fb20706062150t6dc7c486u6c4cc29099274ea2@mail.gmail.com>

take care about the first """" MUST be indented at the appropiated
level, the end one and the comment body may be placed where u want

http://softwareetal.blogspot.com/2007/06/python-comments.html

From khamid.nurdiev at gmail.com  Thu Jun  7 08:56:37 2007
From: khamid.nurdiev at gmail.com (Khamid Nurdiev)
Date: Thu, 7 Jun 2007 11:56:37 +0500
Subject: [Tutor] Multi-line comments?
In-Reply-To: <67160fb20706062150t6dc7c486u6c4cc29099274ea2@mail.gmail.com>
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
	<5e58f2e40706061654w7774ad41y9d6e9c944cca1c05@mail.gmail.com>
	<67160fb20706062150t6dc7c486u6c4cc29099274ea2@mail.gmail.com>
Message-ID: <af33d0680706062356p706a690cj73736d9865da0543@mail.gmail.com>

You could use Kwrite and select the to be commented part and use the keys
Ctrl + D and to uncomment Ctrl + Shift + D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070607/c90433c0/attachment.html 

From alan.gauld at btinternet.com  Thu Jun  7 09:44:39 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 7 Jun 2007 08:44:39 +0100
Subject: [Tutor] Engarde program was: i++
References: <46672234.6020703@rogers.com>
	<DB30DA681DB9544886EA69FE9082737CCAF3A4@csoexc02.intelliden.net>
Message-ID: <f48d18$19b$1@sea.gmane.org>


"David Heiser" <David.Heiser at intelliden.com> wrote 
> 
> def is_yes(question):
>     while True:
>         try:
>             s = raw_input(question).lower()[0]
>             if s == 'y':
>                 return True
>             elif s == 'n':
>                 return False
>         except:
>             pass     ## This traps the condition where a user just
> presses enter
>         print '\nplease select y, n, yes, or no\n'

What value do you think the pass adds over just having 
the print statement inside the except block? So far as I can 
tell they will both do exactly the same so the pass is 
not needed. Or am I missing something here?

Alan G.


From alan.gauld at btinternet.com  Thu Jun  7 09:51:12 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 7 Jun 2007 08:51:12 +0100
Subject: [Tutor] Multi-line comments?
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
Message-ID: <f48ddg$2g9$1@sea.gmane.org>

"Brad Tompkins" <bradleytompkins at gmail.com> wrote

> If there isn't a way, can someone recommend a text editor (I know 
> emacs and
> probably vi can do this, but they seem difficult to use) that will 
> comment
> out blocks of text automatically for me?

The Pythonwin IDE has the Edit->Source->Comment out region command
IDLE has Format->Comment out region

Both use the shortcut Alt+3

But usually long comments are better exposed as doc strings.
Comments should be reserved for explaining why you wrote
the code the way you did - unusual constructs etc, use docstrings to
explain what the code is for.

HTH,


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



From thorsten at thorstenkampe.de  Thu Jun  7 11:01:08 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Thu, 7 Jun 2007 10:01:08 +0100
Subject: [Tutor] Multi-line comments?
References: <f1b5123f0706061641t6817cacfmb64a4ca2e5fbf30c@mail.gmail.com>
Message-ID: <f48hgl$c7h$1@sea.gmane.org>

* Brad Tompkins (Wed, 6 Jun 2007 16:41:31 -0700)
> Is there a way to make use of multi-line comments when programming using
> python?  Having to stick a # in front of every line gets pretty tedious when
> I want to make a comment more detailed than I normally would.
> 
> If there isn't a way, can someone recommend a text editor (I know emacs and
> probably vi can do this, but they seem difficult to use) that will comment
> out blocks of text automatically for me?

EditPad Pro under Windows and Komodo Edit from ActiveState...


From ramanuj.p at gmail.com  Thu Jun  7 12:07:43 2007
From: ramanuj.p at gmail.com (Ramanuj Pandey)
Date: Thu, 07 Jun 2007 15:37:43 +0530
Subject: [Tutor] How to Embed Python code in C
Message-ID: <4667D8EF.2040402@gmail.com>

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

Hi all,
i want to embed Python code in C code, need any tutorial for starting.
Ramanuj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFGZ9jvp6Ts2SMzgZoRAkhrAJ9YZ2JB2n/McMsGnOHxmglaDZHmYACgrk1U
MJCMrnGKdzpKtmws7HYcF8s=
=bNmX
-----END PGP SIGNATURE-----

From dyoo at cs.wpi.edu  Thu Jun  7 01:52:41 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Wed, 6 Jun 2007 19:52:41 -0400 (EDT)
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <DB30DA681DB9544886EA69FE9082737CCAF3A4@csoexc02.intelliden.net>
References: <DB30DA681DB9544886EA69FE9082737CCAF3A4@csoexc02.intelliden.net>
Message-ID: <Pine.LNX.4.63.0706061938300.14215@cs.wpi.edu>



On Wed, 6 Jun 2007, David Heiser wrote:

> or..
>
> def is_yes(question):
>     while True:
>         try:
>             s = raw_input(question).lower()[0]
>             if s == 'y':
>                 return True
>             elif s == 'n':
>                 return False
>         except:
>             pass     ## This traps the condition where a user just
> presses enter
>         print '\nplease select y, n, yes, or no\n'

Hi David,

This does have a different functionality and is is more permissive than 
the original code.  What if the user types in "yoo-hoo"?  The original 
code would reject this, but the function above will treat it as as yes. 
It does depend on what one wants.

Since there is no comment or documentation on is_yes() that says how it 
should behave, I guess we can say that anything goes, but that's probably 
a situation we should fix.


For this particular situation, I'd avoid the try/except block that is used 
for catching array-out-of-bounds errors.  If we do want the above 
functionality, we can take advantage of string slicing to similar effect:

###################################################
def is_yes(question):
     """Asks for a response until the user presses something beginning
     either with 'y' or 'n'.  Returns True if 'y', False otherwise."""
     while True:
         s = raw_input(question).lower()
         if s[:1] == 'y':
             return True
         elif s[:1] == 'n':
             return False
         print '\nplease select y, n, yes, or no\n'
###################################################

From David.Heiser at intelliden.com  Thu Jun  7 15:37:40 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Thu, 7 Jun 2007 07:37:40 -0600
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <f48d18$19b$1@sea.gmane.org>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3A8@csoexc02.intelliden.net>


What if the user enters "maybe".


-----Original Message-----
From: tutor-bounces+david.heiser=intelliden.com at python.org
[mailto:tutor-bounces+david.heiser=intelliden.com at python.org] On Behalf
Of Alan Gauld
Sent: Thursday, June 07, 2007 1:45 AM
To: tutor at python.org
Subject: Re: [Tutor] Engarde program was: i++



"David Heiser" <David.Heiser at intelliden.com> wrote 
> 
> def is_yes(question):
>     while True:
>         try:
>             s = raw_input(question).lower()[0]
>             if s == 'y':
>                 return True
>             elif s == 'n':
>                 return False
>         except:
>             pass     ## This traps the condition where a user just
> presses enter
>         print '\nplease select y, n, yes, or no\n'

What value do you think the pass adds over just having 
the print statement inside the except block? So far as I can 
tell they will both do exactly the same so the pass is 
not needed. Or am I missing something here?

Alan G.

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

From David.Heiser at intelliden.com  Thu Jun  7 15:58:53 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Thu, 7 Jun 2007 07:58:53 -0600
Subject: [Tutor] Engarde program was: i++
In-Reply-To: <Pine.LNX.4.63.0706061938300.14215@cs.wpi.edu>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3A9@csoexc02.intelliden.net>


Very nice trick. Thanks.

P.S.  You can still use:

      s = raw_input(question).lower()[:1]
      if s == ...:


-----Original Message-----
From: Danny Yoo [mailto:dyoo at cs.wpi.edu] 
Sent: Wednesday, June 06, 2007 5:53 PM
To: David Heiser
Cc: tutor at python.org
Subject: Re: [Tutor] Engarde program was: i++




On Wed, 6 Jun 2007, David Heiser wrote:

> or..
>
> def is_yes(question):
>     while True:
>         try:
>             s = raw_input(question).lower()[0]
>             if s == 'y':
>                 return True
>             elif s == 'n':
>                 return False
>         except:
>             pass     ## This traps the condition where a user just
> presses enter
>         print '\nplease select y, n, yes, or no\n'

Hi David,

This does have a different functionality and is is more permissive than 
the original code.  What if the user types in "yoo-hoo"?  The original 
code would reject this, but the function above will treat it as as yes. 
It does depend on what one wants.

Since there is no comment or documentation on is_yes() that says how it 
should behave, I guess we can say that anything goes, but that's
probably 
a situation we should fix.


For this particular situation, I'd avoid the try/except block that is
used 
for catching array-out-of-bounds errors.  If we do want the above 
functionality, we can take advantage of string slicing to similar
effect:

###################################################
def is_yes(question):
     """Asks for a response until the user presses something beginning
     either with 'y' or 'n'.  Returns True if 'y', False otherwise."""
     while True:
         s = raw_input(question).lower()
         if s[:1] == 'y':
             return True
         elif s[:1] == 'n':
             return False
         print '\nplease select y, n, yes, or no\n'
###################################################

From john.ertl at navy.mil  Thu Jun  7 17:22:44 2007
From: john.ertl at navy.mil (Ertl, John C CIV 63134)
Date: Thu, 7 Jun 2007 08:22:44 -0700
Subject: [Tutor] Best way to POST XML to CGI
In-Reply-To: <000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9><f44kqk$o81$1@sea.gmane.org>
	<000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
Message-ID: <642C9439121B2D48AC0117320B040D21170F082A@NAWEMUGUEX02VA.nadsuswe.nads.navy.mil>

All,

I have a Python program that makes images of data and I want to be able to make these via a web interface.  I want to keep it simple so I thought I would send an XML file to a cgi program (XML is what I am supposed to use).  I have the parsing of the XML all figured out but the way I am sending the XML and receiving it does not look like they are the best ways.

I have an HTML form that I use to collect input on what kind of image.   I then take that form input and make it into an XML string.  I then take that XML string and POST it to a CGI script.

I am using cgi to retrieve the XML string.  Once I have the string I get the needed info and make an image.  The Part that just does not look right to me is using form = cgi.FieldStorage()

Of someone else wanted to just post an XML string they would have to have the same form name "XMLhttp" that is not very user friendly.   My guess is I am missing something about how cgi can work.

I bet Python has a simple way to receive a XML post so I do not have to look for a specific form name?

Any help would be appreciated.

Thanks,

John 

 

Web page code to post XML in a text area

<form action="http://......../cgi-bin/parsXML2.py" target=text/xml method=post>
<TEXTAREA cols=60 name="XMLhttp" rows=20 wrap=Real>

<?xml version="1.0" ?>

<StatRequest requestID="user-20070531-Time"> 

</StatRequest>


</TEXTAREA> <INPUT type=submit value="Submit Query">
</FORM>

Code that receives the XML POST

    form = cgi.FieldStorage()
    if not (form.has_key("XMLhttp")):
        print "content-type: text/html\n\n"
        print "<H1>Error</H1>"


   else:
        xmlString = form["XMLhttp"].value
        print "content-type: text/html\n\n"
        req = ParseXML()


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070607/07331bce/attachment.htm 

From alan.gauld at btinternet.com  Thu Jun  7 18:21:48 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 7 Jun 2007 17:21:48 +0100
Subject: [Tutor] Engarde program was: i++
References: <f48d18$19b$1@sea.gmane.org>
	<DB30DA681DB9544886EA69FE9082737CCAF3A8@csoexc02.intelliden.net>
Message-ID: <f49bat$ef5$1@sea.gmane.org>

> What if the user enters "maybe".

Sorry, I said the except block i meant the else block of
the original posters code.

In both his case and yours the message gets printed.
But as Danny pointed out you need the try/except in
your case because you are indexing a potentially
empty string. The OP didn't have that limitation to
deal with.

Alan G.

>
>
> -----Original Message-----
> From: tutor-bounces+david.heiser=intelliden.com at python.org
> [mailto:tutor-bounces+david.heiser=intelliden.com at python.org] On 
> Behalf
> Of Alan Gauld
> Sent: Thursday, June 07, 2007 1:45 AM
> To: tutor at python.org
> Subject: Re: [Tutor] Engarde program was: i++
>
>
>
> "David Heiser" <David.Heiser at intelliden.com> wrote
>>
>> def is_yes(question):
>>     while True:
>>         try:
>>             s = raw_input(question).lower()[0]
>>             if s == 'y':
>>                 return True
>>             elif s == 'n':
>>                 return False
>>         except:
>>             pass     ## This traps the condition where a user just
>> presses enter
>>         print '\nplease select y, n, yes, or no\n'
>
> What value do you think the pass adds over just having
> the print statement inside the except block? So far as I can
> tell they will both do exactly the same so the pass is
> not needed. Or am I missing something here?
>
> Alan G.
>
> _______________________________________________
> 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  Thu Jun  7 18:30:11 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 7 Jun 2007 17:30:11 +0100
Subject: [Tutor] Best way to POST XML to CGI
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9><f44kqk$o81$1@sea.gmane.org><000901c7a7c8$3fcf8190$21137044@dunamis34752e9>
	<642C9439121B2D48AC0117320B040D21170F082A@NAWEMUGUEX02VA.nadsuswe.nads.navy.mil>
Message-ID: <f49bqk$g9g$1@sea.gmane.org>

"Ertl, John C CIV 63134" <john.ertl at navy.mil> wrote 

> I have a Python program that makes images of data 
> and I want to be able to make these via a web interface.  

Fair enough.

> I want to keep it simple so I thought I would send 
> an XML file to a cgi program 

But thats not simple. CGI is not really designed to deal with XML, 
they are almost complementary technologies. CGI sends 
name/value pairs either in GET or POST format. XML encodes 
the values into a text file. Different things. XML tends to be used 
for RPC or B2B type applications, CGI is typically used for basic 
form submissions.

Sure you can do it, but I'm not sure there is much point!
I'd probably look to use CGI to capture the details then 
create the XML file at the server end. Its a lot more efficient 
in terms of network bandwidth too. XML is about the most 
inefficient network "protocol" ever invented.

> I have an HTML form that I use to collect input on what 
> kind of image.   I then take that form input and make it 
> into an XML string.  I then take that XML string and POST 
> it to a CGI script.

As I say, a pretty complex process compared to a simple 
CGI submit action.

> I bet Python has a simple way to receive a XML post 
> so I do not have to look for a specific form name?

Python offers many ways to deal with XML file transmissions, 
including XML/RPC and SOAP. But CGI is probably not the 
best approach for XML IMHO. It can be done in the same way 
as posting a normal text file but its pretty much turning an 
easy job into a hard one for no benefit.

Alan G.


From evenson at gmail.com  Thu Jun  7 20:33:17 2007
From: evenson at gmail.com (Eric Evenson)
Date: Thu, 7 Jun 2007 11:33:17 -0700
Subject: [Tutor] Engarde program was: i++
Message-ID: <7b7c86290706071133n66e7bdf0h5aa572a1741ff22a@mail.gmail.com>

How about doing it this way:
def is_yes(question):
    yn = { 'y':True, 'yes':True, 'n':False, 'no':False }
    while True:
        try:
            return yn[raw_input(question).lower().strip()]
        except KeyError:
            print '\nplease select y, n, yes, or no\n'

From john.ertl at navy.mil  Thu Jun  7 20:55:15 2007
From: john.ertl at navy.mil (Ertl, John C CIV 63134)
Date: Thu, 7 Jun 2007 11:55:15 -0700
Subject: [Tutor] Best way to POST XML to CGI
References: <008101c7a7a4$681f5ef0$21137044@dunamis34752e9><f44kqk$o81$1@sea.gmane.org><000901c7a7c8$3fcf8190$21137044@dunamis34752e9><642C9439121B2D48AC0117320B040D21170F082A@NAWEMUGUEX02VA.nadsuswe.nads.navy.mil>
	<f49bqk$g9g$1@sea.gmane.org>
Message-ID: <2B3C3C2EA721A04191268CE74039414101814FA3@NAWEMUGUEX02VA.nadsuswe.nads.navy.mil>

Alan,
 
Thanks for the input.  I am trying to make something that is capable of being a bit more B2B than a standard HTML form...but be able to have a friendly interface for a person.  I have not liked SOAP in the past...way to much extra stuff.  I was trying to think REST but I have to admit I am missing some pieces.  Maybe XML/RPC.
 
Thanks again for the advice...I will rethink how I am doing this.
 
John Ertl
Meteorologist
 
FNMOC
7 Grace Hopper Ave.
Monterey, CA 93943
(831) 656-5704
john.ertl at navy.mil

________________________________

From: tutor-bounces at python.org on behalf of Alan Gauld
Sent: Thu 6/7/2007 9:30 AM
To: tutor at python.org
Subject: Re: [Tutor] Best way to POST XML to CGI



"Ertl, John C CIV 63134" <john.ertl at navy.mil> wrote

> I have a Python program that makes images of data
> and I want to be able to make these via a web interface. 

Fair enough.

> I want to keep it simple so I thought I would send
> an XML file to a cgi program

But thats not simple. CGI is not really designed to deal with XML,
they are almost complementary technologies. CGI sends
name/value pairs either in GET or POST format. XML encodes
the values into a text file. Different things. XML tends to be used
for RPC or B2B type applications, CGI is typically used for basic
form submissions.

Sure you can do it, but I'm not sure there is much point!
I'd probably look to use CGI to capture the details then
create the XML file at the server end. Its a lot more efficient
in terms of network bandwidth too. XML is about the most
inefficient network "protocol" ever invented.

> I have an HTML form that I use to collect input on what
> kind of image.   I then take that form input and make it
> into an XML string.  I then take that XML string and POST
> it to a CGI script.

As I say, a pretty complex process compared to a simple
CGI submit action.

> I bet Python has a simple way to receive a XML post
> so I do not have to look for a specific form name?

Python offers many ways to deal with XML file transmissions,
including XML/RPC and SOAP. But CGI is probably not the
best approach for XML IMHO. It can be done in the same way
as posting a normal text file but its pretty much turning an
easy job into a hard one for no benefit.

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/20070607/be233925/attachment.htm 

From gslindstrom at gmail.com  Thu Jun  7 22:25:22 2007
From: gslindstrom at gmail.com (Greg Lindstrom)
Date: Thu, 7 Jun 2007 15:25:22 -0500
Subject: [Tutor] Properties
Message-ID: <a9f39a410706071325s51121faege543adf8a6de3826@mail.gmail.com>

Hello, and I apologize in advance for the question.

I have decided to publish a class I use to handle data segments to Google
Code for the world to see (I plan to make millions off training classes,
books and lectures :-).  I need to make it a bit more 'generic' than the
class I have been using, and while I'm working the rewrite I thought it
would be cool to add unit tests and use properties.  The problem is, I only
recall that properties are 'cool'.  I can't locate the documentation on why
or how to use them.  If you could point me to the proper documentation I
would be most appreciative.

Also, I plan to use unittest to write my unit tests.  Is this module still
considered acceptable, or has something else taken it's place?

Thanks for your help,

--greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070607/827c97c2/attachment.htm 

From kent37 at tds.net  Thu Jun  7 22:50:32 2007
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 07 Jun 2007 16:50:32 -0400
Subject: [Tutor] Properties
In-Reply-To: <a9f39a410706071325s51121faege543adf8a6de3826@mail.gmail.com>
References: <a9f39a410706071325s51121faege543adf8a6de3826@mail.gmail.com>
Message-ID: <46686F98.7030503@tds.net>

Greg Lindstrom wrote:
> Hello, and I apologize in advance for the question.

No apologies needed, this list would be quite boring without any 
questions :-)
> 
> I have decided to publish a class I use to handle data segments to 
> Google Code for the world to see (I plan to make millions off training 
> classes, books and lectures :-).  I need to make it a bit more 'generic' 
> than the class I have been using, and while I'm working the rewrite I 
> thought it would be cool to add unit tests and use properties.  The 
> problem is, I only recall that properties are 'cool'.  I can't locate 
> the documentation on why or how to use them.  If you could point me to 
> the proper documentation I would be most appreciative.

Hmmm...if that is all you can remember about properties, then maybe you 
don't need them, many programs don't...even cool programs :-)

I don't know of any good introductory material on properties but here 
are some starting points:
http://www.python.org/download/releases/2.2/descrintro/#property
http://docs.python.org/lib/built-in-funcs.html#l2h-57

> Also, I plan to use unittest to write my unit tests.  Is this module 
> still considered acceptable, or has something else taken it's place?

unittest is fine. There are a few other unit test frameworks that are 
also popular but unittest and doctest are the only ones in the standard 
library.

Kent

From matt at mattanddawn.orangehome.co.uk  Fri Jun  8 00:06:08 2007
From: matt at mattanddawn.orangehome.co.uk (Matt Smith)
Date: Thu, 07 Jun 2007 23:06:08 +0100
Subject: [Tutor] Invoking Python from Vim
Message-ID: <1181253968.11858.8.camel@computer>

Hi,

Bit of a Vim specific question this one but I hope someone might have an
answer. I currently have the following line in my .gvimrc file (I'm
using Ubuntu Linux):

map <F2> :!gnome-terminal -e=python\ -i\ %<CR>

This opens a window and runs the Python program I am working on. I don't
really like the fact I can't do anything else in vim until I close the
window and I don't really need the interactive prompt that I am left
with. If I invoke Python without the -i then I don't get to see the
error message if my program exits with an error.

In 'normal' vim I use:

map <f2> :w\|!python %<cr>

This doesn't work for GVim which I prefer to use.

Do any Vim users have a better way of running a Python program while it
is being edited in Vim?

Thanks,

Matt



From tim at johnsons-web.com  Fri Jun  8 00:49:34 2007
From: tim at johnsons-web.com (Tim Johnson)
Date: Thu, 7 Jun 2007 14:49:34 -0800
Subject: [Tutor] Invoking Python from Vim
In-Reply-To: <1181253968.11858.8.camel@computer>
References: <1181253968.11858.8.camel@computer>
Message-ID: <200706071449.34610.tim@johnsons-web.com>

On Thursday 07 June 2007, Matt Smith wrote:
> Hi,
>
> Bit of a Vim specific question this one but I hope someone might have an
> answer. I currently have the following line in my .gvimrc file (I'm
> using Ubuntu Linux):
>
> map <F2> :!gnome-terminal -e=python\ -i\ %<CR>
>
> This opens a window and runs the Python program I am working on. I don't
> really like the fact I can't do anything else in vim until I close the
> window and I don't really need the interactive prompt that I am left
> with. If I invoke Python without the -i then I don't get to see the
> error message if my program exits with an error.
>
> In 'normal' vim I use:
>
> map <f2> :w\|!python %<cr>
>
> This doesn't work for GVim which I prefer to use.
  Hi Matt:
     I've just started using gvim for python after several years
     of using xemacs for python programming.
     Currently I'm using vim.python on kubuntu 7.04 with the
     python interpreter embedded, along with the taglist.vim
     and python_box.vim plugins. They go a long way towards
     an "IDE" for python. python_box has two methods to test
     and execute whole files. You can also test simple python
     code snippets from ex as in
     :python help(dict)

and I've barely begun to scratch the surface .....
Tim


From alan.gauld at btinternet.com  Fri Jun  8 01:19:39 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 8 Jun 2007 00:19:39 +0100
Subject: [Tutor] Invoking Python from Vim
References: <1181253968.11858.8.camel@computer>
Message-ID: <f4a3qc$2u6$1@sea.gmane.org>


"Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote

> Do any Vim users have a better way of running a Python program while 
> it
> is being edited in Vim?

My personal preference is to have 3 windows open:

1) gvim for editing the files
2) a console for running the files using command recall to do so
3) a console running a python shell prompt
    (actually nowadays I'm using a a PyCrust shell)

And I alt-tab between the windows.

This way I can experiment in PyCrust, copy the resultant experiments
into gvim and run the program, keeping the error messages etc
visible without sacrificing gvim window space.

The downside is the alt-tab required to switch to the right window
and an up-arrow press to recall the python command to re-execute
each time.

Alan G. 



From bejarar at sbcglobal.net  Fri Jun  8 08:00:57 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Fri, 8 Jun 2007 01:00:57 -0500
Subject: [Tutor] Questions about easygui and compiling
Message-ID: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>

Hello,

I am very new to python and have a couple of questions, to which I  
would very much appreciate answers from the members of this list.

First, I am trying to learn to use easygui to present simple dialogs  
and get input from the user. To this end, I wrote a very short test  
program, just to make sure I new how to use easygui. Although I get  
no error messages when I run it, the dialog boxes do not appear. What  
might I be doing wrong? It may be helpful to know (a) that I am  
learning python on a Mac iBook g4 (running OS 10.4), (b) that I wrote  
the test program using the Smultron text editor, and (c) that I am  
using python launcher to run the program. I would be only too happy  
to send a copy of the program as an attachment or pasted in the body  
of a future e-mail message, should someone on this list feel that  
doing so would be helpful in answering my question.

Second, how does one compile python programs?

Cordially,
Rafael Bejarano

From chaosweevil42 at gmail.com  Fri Jun  8 08:49:12 2007
From: chaosweevil42 at gmail.com (Gordon)
Date: Thu, 07 Jun 2007 23:49:12 -0700
Subject: [Tutor] Questions about easygui and compiling
In-Reply-To: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>
References: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>
Message-ID: <4668FBE8.9000903@gmail.com>

I have no experience with EasyGUI, but to answer your other question, 
you do not "compile" Python in the way you compile C or Java.

Python can be compiled into a .pyc file, which is slightly faster to 
start running and obfuscates the source, but it doesn't really do much, 
practically.  You can also use Py2EXE or PyInstaller to make standalone 
executables for Windows.

Simply running a script through the Python interpreter is as far as you 
can get for now, although there is a project, name "Psycho", which 
translates Python to x86 Assembly, though it is only available for 
Windows and Linux, and doesn't always speed things up.

Hope that helps!

Rafael Bejarano wrote:
> Hello,
>
> I am very new to python and have a couple of questions, to which I  
> would very much appreciate answers from the members of this list.
>
> First, I am trying to learn to use easygui to present simple dialogs  
> and get input from the user. To this end, I wrote a very short test  
> program, just to make sure I new how to use easygui. Although I get  
> no error messages when I run it, the dialog boxes do not appear. What  
> might I be doing wrong? It may be helpful to know (a) that I am  
> learning python on a Mac iBook g4 (running OS 10.4), (b) that I wrote  
> the test program using the Smultron text editor, and (c) that I am  
> using python launcher to run the program. I would be only too happy  
> to send a copy of the program as an attachment or pasted in the body  
> of a future e-mail message, should someone on this list feel that  
> doing so would be helpful in answering my question.
>
> Second, how does one compile python programs?
>
> Cordially,
> Rafael Bejarano
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   

From alan.gauld at btinternet.com  Fri Jun  8 09:23:21 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 8 Jun 2007 08:23:21 +0100
Subject: [Tutor] Questions about easygui and compiling
References: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>
Message-ID: <f4b05b$5p3$1@sea.gmane.org>


"Rafael Bejarano" <bejarar at sbcglobal.net> wrote

> First, I am trying to learn to use easygui to present simple dialogs
> and get input from the user. To this end, I wrote a very short test
> program, just to make sure I new how to use easygui. Although I get
> no error messages when I run it, the dialog boxes do not appear.
> ...
> using python launcher to run the program.

Don;t do that until you are sure the program works.
Instead open a Terminal window and run your program
from the command line by typing

python myprog.py

That way you will be able to see any errors or warnings
more easily.

> I would be only too happy  to send a copy of the program
> as an attachment or pasted in the body

If its just a short program then thats probably a good idea.
Although I personal;ly don't know much about EasyGUI
there are some on the list who use it.

> Second, how does one compile python programs?

Python modules are compiled into byte code when you import
them. If  a compiled version exists then it is loaded instead
which slightly improves load time. But Python is an interpreted
language like Perl or Applescript and is not compiled in the
same way as C++ or Objective C. In practice this makes
little difference since in most cases the bulk of the time is
spent executing functions that are written inn C (and thus
compiled) and on a Mac you can use the python launcher
to build application bundles for convenient distribution.

HTH,

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



From kent37 at tds.net  Fri Jun  8 14:58:52 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 08 Jun 2007 08:58:52 -0400
Subject: [Tutor] Properties
In-Reply-To: <46686F98.7030503@tds.net>
References: <a9f39a410706071325s51121faege543adf8a6de3826@mail.gmail.com>
	<46686F98.7030503@tds.net>
Message-ID: <4669528C.4020406@tds.net>

Kent Johnson wrote:
> I don't know of any good introductory material on properties but here 
> are some starting points:
> http://www.python.org/download/releases/2.2/descrintro/#property
> http://docs.python.org/lib/built-in-funcs.html#l2h-57

Here is another:
http://users.rcn.com/python/download/Descriptor.htm#properties

Kent


From rikard.bosnjakovic at gmail.com  Fri Jun  8 17:36:03 2007
From: rikard.bosnjakovic at gmail.com (Rikard Bosnjakovic)
Date: Fri, 8 Jun 2007 17:36:03 +0200
Subject: [Tutor] How to Embed Python code in C
In-Reply-To: <4667D8EF.2040402@gmail.com>
References: <4667D8EF.2040402@gmail.com>
Message-ID: <d9e88eaf0706080836g658c0c5fncec71c9644ead029@mail.gmail.com>

On 6/7/07, Ramanuj Pandey <ramanuj.p at gmail.com> wrote:

> i want to embed Python code in C code, need any tutorial for starting.

http://www.codeproject.com/cpp/embedpython_1.asp

-- 
- Rikard - http://bos.hack.org/cv/

From Barry.Carroll at datalogic.com  Fri Jun  8 17:02:46 2007
From: Barry.Carroll at datalogic.com (Carroll, Barry)
Date: Fri, 8 Jun 2007 08:02:46 -0700
Subject: [Tutor] Invoking Python from Vim
In-Reply-To: <mailman.28844.1181285361.32030.tutor@python.org>
Message-ID: <2BBAEE949D384D40A2B851287ADB6A4304595BAF@eugsrv400.psc.pscnet.com>


> -----Original Message-----
> Date: Fri, 8 Jun 2007 00:19:39 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Invoking Python from Vim
> To: tutor at python.org
> Message-ID: <f4a3qc$2u6$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> 	reply-type=original
> 
> 
> "Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote
> 
> > Do any Vim users have a better way of running a Python program while
> > it
> > is being edited in Vim?
> 
> My personal preference is to have 3 windows open:
> 
> 1) gvim for editing the files
> 2) a console for running the files using command recall to do so
> 3) a console running a python shell prompt
>     (actually nowadays I'm using a a PyCrust shell)
> 
> And I alt-tab between the windows.
> 
> This way I can experiment in PyCrust, copy the resultant experiments
> into gvim and run the program, keeping the error messages etc
> visible without sacrificing gvim window space.
> 
> The downside is the alt-tab required to switch to the right window
> and an up-arrow press to recall the python command to re-execute
> each time.
> 
> Alan G.
> 
My setup is similar to Alan's:

	* Windows XP 
	* Python Enthought Edition
	* Iron Python shell for experimenting/prototyping
	* GviM for editing
	* Standard Command prompt window for execution

It isn't a sophisticated, "integrated" solution, but it works quite
well.  Sometimes the simple ideas are the best.  Remember this famous
exchange:

     Devil:   "Take the easy path. I brought you a suite of applications

               that all work together."
     Dilbert: "That's unnatural!!!  Be gone!!!"

Regards,
 
Barry
barry.carroll at datalogic.com
541-302-1107
________________________
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed
 


From Mike.Hansen at atmel.com  Fri Jun  8 19:35:20 2007
From: Mike.Hansen at atmel.com (Mike Hansen)
Date: Fri, 8 Jun 2007 11:35:20 -0600
Subject: [Tutor] Invoking Python from Vim
In-Reply-To: <2BBAEE949D384D40A2B851287ADB6A4304595BAF@eugsrv400.psc.pscnet.com>
References: <mailman.28844.1181285361.32030.tutor@python.org>
	<2BBAEE949D384D40A2B851287ADB6A4304595BAF@eugsrv400.psc.pscnet.com>
Message-ID: <57B026980605A64F9B23484C5659E32E852426@poccso.US.ad.atmel.com>

 

> > -----Original Message-----
> > Date: Fri, 8 Jun 2007 00:19:39 +0100
> > From: "Alan Gauld" <alan.gauld at btinternet.com>
> > Subject: Re: [Tutor] Invoking Python from Vim
> > To: tutor at python.org
> > Message-ID: <f4a3qc$2u6$1 at sea.gmane.org>
> > Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> > 	reply-type=original
> > 
> > 
> > "Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote
> > 
> > > Do any Vim users have a better way of running a Python 
> program while
> > > it
> > > is being edited in Vim?
> > 
> > My personal preference is to have 3 windows open:
> > 
> > 1) gvim for editing the files
> > 2) a console for running the files using command recall to do so
> > 3) a console running a python shell prompt
> >     (actually nowadays I'm using a a PyCrust shell)
> > 
> > And I alt-tab between the windows.

I also use the three window solution(VIM, IPython, and shell to run
program.)

You might look at Pida which turns VIM into a IDE. I'm not sure, but I
think it's Python friendly since it's written in Python.

http://pida.co.uk/

Mike

From chaosweevil42 at gmail.com  Fri Jun  8 23:21:29 2007
From: chaosweevil42 at gmail.com (Gordon)
Date: Fri, 08 Jun 2007 14:21:29 -0700
Subject: [Tutor] Questions about easygui and compiling
In-Reply-To: <F0F96C62-F2E7-4F91-A46D-823E9B2FD463@sbcglobal.net>
References: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>
	<4668FBE8.9000903@gmail.com>
	<F0F96C62-F2E7-4F91-A46D-823E9B2FD463@sbcglobal.net>
Message-ID: <4669C859.1050702@gmail.com>

Yes, I can.  But first, make sure to hit"Reply All" to send replies to 
the list, rather than just me :)

Anyhow, there are a couple ways, but I think the easiest is to make a 
one-line script that imports the file you want to make a .pyc out of.  
You'll end up with 3 versions of the file, a .py, a .pyc, and a .pyo.  
You can then take the .pyc and run it in any compatible Python interpreter.

There are ways to make multiple files into .pyc all at once with the 
"compileall" module, which you can find more about at in the Python 
documentation.

Rafael Bejarano wrote:
> That is helpful. Thank you.
>
> Can you tell me how to convert a script to a .pyc file?
>
> Rafael
> On Jun 8, 2007, at 1:49 AM, Gordon wrote:
>
>> I have no experience with EasyGUI, but to answer your other question, 
>> you do not "compile" Python in the way you compile C or Java.
>>
>> Python can be compiled into a .pyc file, which is slightly faster to 
>> start running and obfuscates the source, but it doesn't really do 
>> much, practically.  You can also use Py2EXE or PyInstaller to make 
>> standalone executables for Windows.
>>
>> Simply running a script through the Python interpreter is as far as 
>> you can get for now, although there is a project, name "Psycho", 
>> which translates Python to x86 Assembly, though it is only available 
>> for Windows and Linux, and doesn't always speed things up.
>>
>> Hope that helps!
>>
>> Rafael Bejarano wrote:
>>> Hello,
>>>
>>> I am very new to python and have a couple of questions, to which I  
>>> would very much appreciate answers from the members of this list.
>>>
>>> First, I am trying to learn to use easygui to present simple 
>>> dialogs  and get input from the user. To this end, I wrote a very 
>>> short test  program, just to make sure I new how to use easygui. 
>>> Although I get  no error messages when I run it, the dialog boxes do 
>>> not appear. What  might I be doing wrong? It may be helpful to know 
>>> (a) that I am  learning python on a Mac iBook g4 (running OS 10.4), 
>>> (b) that I wrote  the test program using the Smultron text editor, 
>>> and (c) that I am  using python launcher to run the program. I would 
>>> be only too happy  to send a copy of the program as an attachment or 
>>> pasted in the body  of a future e-mail message, should someone on 
>>> this list feel that  doing so would be helpful in answering my 
>>> question.
>>>
>>> Second, how does one compile python programs?
>>>
>>> Cordially,
>>> Rafael Bejarano
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>
>


From bejarar at sbcglobal.net  Sat Jun  9 00:31:29 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Fri, 8 Jun 2007 17:31:29 -0500
Subject: [Tutor] Questions about easygui and compiling
In-Reply-To: <4669C859.1050702@gmail.com>
References: <933DFAF2-98A2-434A-9377-F957E41EB205@sbcglobal.net>
	<4668FBE8.9000903@gmail.com>
	<F0F96C62-F2E7-4F91-A46D-823E9B2FD463@sbcglobal.net>
	<4669C859.1050702@gmail.com>
Message-ID: <80987655-54FA-4FA5-A486-DCC5E4C6DD62@sbcglobal.net>

Thanks. I'll definitely try out your instructions.

Rafael
On Jun 8, 2007, at 4:21 PM, Gordon wrote:

> Yes, I can.  But first, make sure to hit"Reply All" to send replies  
> to the list, rather than just me :)
>
> Anyhow, there are a couple ways, but I think the easiest is to make  
> a one-line script that imports the file you want to make a .pyc out  
> of.  You'll end up with 3 versions of the file, a .py, a .pyc, and  
> a .pyo.  You can then take the .pyc and run it in any compatible  
> Python interpreter.
>
> There are ways to make multiple files into .pyc all at once with  
> the "compileall" module, which you can find more about at in the  
> Python documentation.
>
> Rafael Bejarano wrote:
>> That is helpful. Thank you.
>>
>> Can you tell me how to convert a script to a .pyc file?
>>
>> Rafael
>> On Jun 8, 2007, at 1:49 AM, Gordon wrote:
>>
>>> I have no experience with EasyGUI, but to answer your other  
>>> question, you do not "compile" Python in the way you compile C or  
>>> Java.
>>>
>>> Python can be compiled into a .pyc file, which is slightly faster  
>>> to start running and obfuscates the source, but it doesn't really  
>>> do much, practically.  You can also use Py2EXE or PyInstaller to  
>>> make standalone executables for Windows.
>>>
>>> Simply running a script through the Python interpreter is as far  
>>> as you can get for now, although there is a project, name  
>>> "Psycho", which translates Python to x86 Assembly, though it is  
>>> only available for Windows and Linux, and doesn't always speed  
>>> things up.
>>>
>>> Hope that helps!
>>>
>>> Rafael Bejarano wrote:
>>>> Hello,
>>>>
>>>> I am very new to python and have a couple of questions, to which  
>>>> I  would very much appreciate answers from the members of this  
>>>> list.
>>>>
>>>> First, I am trying to learn to use easygui to present simple  
>>>> dialogs  and get input from the user. To this end, I wrote a  
>>>> very short test  program, just to make sure I new how to use  
>>>> easygui. Although I get  no error messages when I run it, the  
>>>> dialog boxes do not appear. What  might I be doing wrong? It may  
>>>> be helpful to know (a) that I am  learning python on a Mac iBook  
>>>> g4 (running OS 10.4), (b) that I wrote  the test program using  
>>>> the Smultron text editor, and (c) that I am  using python  
>>>> launcher to run the program. I would be only too happy  to send  
>>>> a copy of the program as an attachment or pasted in the body  of  
>>>> a future e-mail message, should someone on this list feel that   
>>>> doing so would be helpful in answering my question.
>>>>
>>>> Second, how does one compile python programs?
>>>>
>>>> Cordially,
>>>> Rafael Bejarano
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>>
>>
>>
>


From bejarar at sbcglobal.net  Sat Jun  9 08:24:12 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sat, 9 Jun 2007 01:24:12 -0500
Subject: [Tutor] easygui question, again
Message-ID: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>

Hello,

According to the instructions that I received when I subscribed to  
this list, one should re-post a question that has not been adequately  
addressed in a day or so since the first post. As this is my  
situation, I would like to ask once more for your assistance with  
easygui, which is supposed to be ideal for use by people like me, who  
are new to python.

My problem is that, although I get no error messages when I run a  
program that calls the functions from the easygui module, the dialog  
boxes do not appear on the screen. I am using a Macintosh iBook G4  
with OS 10.4 installed, and am invoking the python interpreter with  
python launcher.

If anyone on this list can help me with this problem, I would be most  
grateful.

Cordially,
Rafael Bejarano

From alan.gauld at btinternet.com  Sat Jun  9 09:28:54 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 9 Jun 2007 08:28:54 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
Message-ID: <f4dkro$2cq$1@sea.gmane.org>


"Rafael Bejarano" <bejarar at sbcglobal.net> wrote

> this list, one should re-post a question that has not been 
> adequately
> addressed in a day or so since the first post. As this is my
> situation, I would like to ask once more for your assistance

I thought we were waiting for you to post your code? :-)

> My problem is that, although I get no error messages when I run a
> program that calls the functions from the easygui module, the dialog
> boxes do not appear on the screen.

Alan G. 



From kent37 at tds.net  Sat Jun  9 12:26:39 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 09 Jun 2007 06:26:39 -0400
Subject: [Tutor] easygui question, again
In-Reply-To: <f4dkro$2cq$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org>
Message-ID: <466A805F.4070501@tds.net>

Alan Gauld wrote:
> "Rafael Bejarano" <bejarar at sbcglobal.net> wrote
> 
>> this list, one should re-post a question that has not been 
>> adequately
>> addressed in a day or so since the first post. As this is my
>> situation, I would like to ask once more for your assistance
> 
> I thought we were waiting for you to post your code? :-)

Also please confirm that you are running from a Terminal window and show 
any output you get to Terminal when you run your program.

You could try running the easygui demo - just type
python easygui.py
on the command line from the directory containing easygui.

Kent

From jped.aru at gmail.com  Sun Jun 10 06:43:01 2007
From: jped.aru at gmail.com (Adam Urbas)
Date: Sat, 9 Jun 2007 23:43:01 -0500
Subject: [Tutor] Calculator research
In-Reply-To: <f3r9i9$eoi$1@sea.gmane.org>
References: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com>
	<f3r9i9$eoi$1@sea.gmane.org>
Message-ID: <ef52818c0706092143t45aaabd3pf2ab87d02a894f07@mail.gmail.com>

Ok then Alan, I'll be sure to check that out.  I wasn't sure that what
a GUI was so now I know.  I haven't been able to mess around with
python for a while, so I haven't gotten any further on your tutorial.
The problem I had before was that I was really excited to create
something original or better or ,you know, anything, that I wasn't
really willing to just slow down and take the time to actually learn
python.  Something has changed since then.  So I will probably not be
messaging again for a while, because I'll be reading the tutorial.

Thanks,
Au

On 6/2/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Adam Urbas" <jped.aru at gmail.com> wrote
>
> > Ok, this is my research for a better calculator.  I want to make a
> > calculator that is much less lame than the one that comes standard
>
> Thats a good beginners project. But you should go through
> one of the tutorials first because you are still asking a lot of
> very basic questions. A few hours going through the
> rudimentary things will speed up your project a lot.
>
> > Also, I'd like to know how to make my program have visual qualities,
> > like the standard calculator.
>
> I assume you want it to have a GUI fron end with buttons etc?
> Yes thats possible and my tutorial includes a topic to get you
> started plus some example programs. but it is a more advanced
> topic that really requires you to know about OOP and event-driven
> style programs first.
>
>
> --
> 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 bejarar at sbcglobal.net  Sun Jun 10 08:26:01 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 01:26:01 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4dkro$2cq$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org>
Message-ID: <B9ED5661-4135-4666-A9D5-A432B90F951D@sbcglobal.net>

Thanks for reminding me to post my code. Here it is.

#easygui test program
import easygui
import sys
msg = "What do you prefer?"
choices = ["$50.00 now", "$100.00 in 6 months"]
choice = easygui.buttonbox(msg, "", choices)
print choice

On Jun 9, 2007, at 2:28 AM, Alan Gauld wrote:

>
> "Rafael Bejarano" <bejarar at sbcglobal.net> wrote
>
>> this list, one should re-post a question that has not been
>> adequately
>> addressed in a day or so since the first post. As this is my
>> situation, I would like to ask once more for your assistance
>
> I thought we were waiting for you to post your code? :-)
>
>> My problem is that, although I get no error messages when I run a
>> program that calls the functions from the easygui module, the dialog
>> boxes do not appear on the screen.
>
> Alan G.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From bejarar at sbcglobal.net  Sun Jun 10 08:40:14 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 01:40:14 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <466A805F.4070501@tds.net>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
Message-ID: <59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net>

I wrote the script in the Smultron test editor. To open it, I've  
first been selecting it and then selecting python launcher from the  
"Open with" submenu, whicch is under the "Open" menu. Opening the  
script file in this way brings up the terminal window. Here is the  
output I get.

Last login: Sun Jun 10 01:38:22 on ttyp1
Welcome to Darwin!
rafael-bejaranos-ibook-g4:~ Rafael$ cd '/Volumes/UNTITLED/Programming  
stuff/My python stuff/' && '/usr/local/bin/pythonw'  '/Volumes/ 
UNTITLED/Programming stuff/My python stuff/codetester.py'  && echo  
Exit status: $? && exit 1



















On Jun 9, 2007, at 5:26 AM, Kent Johnson wrote:

> Alan Gauld wrote:
>> "Rafael Bejarano" <bejarar at sbcglobal.net> wrote
>>
>>> this list, one should re-post a question that has not been
>>> adequately
>>> addressed in a day or so since the first post. As this is my
>>> situation, I would like to ask once more for your assistance
>>
>> I thought we were waiting for you to post your code? :-)
>
> Also please confirm that you are running from a Terminal window and  
> show
> any output you get to Terminal when you run your program.
>
> You could try running the easygui demo - just type
> python easygui.py
> on the command line from the directory containing easygui.
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From alan.gauld at btinternet.com  Sun Jun 10 09:19:41 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 08:19:41 +0100
Subject: [Tutor] Calculator research
References: <ef52818c0706012252i294011aesd1bd60b56d0f75ad@mail.gmail.com><f3r9i9$eoi$1@sea.gmane.org>
	<ef52818c0706092143t45aaabd3pf2ab87d02a894f07@mail.gmail.com>
Message-ID: <f4g8mg$blq$1@sea.gmane.org>

"Adam Urbas" <jped.aru at gmail.com> wrote

> The problem I had before was that I was really excited to create
> something original or better or ,you know, anything, that I wasn't
> really willing to just slow down and take the time to actually learn
> python.

Yes, thats always a temptation, but its usually better to learn
to walk before trying to run. And hopefully it won;t be too boring :-)


> Something has changed since then.  So I will probably not be
> messaging again for a while, because I'll be reading the tutorial.

You will probably find plenty things to ask questins about
even in the tutorial so you shouldn't be in any danger of losing
your emailing skills for a while yet!

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



From bejarar at sbcglobal.net  Sun Jun 10 09:24:56 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 02:24:56 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <466A805F.4070501@tds.net>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
Message-ID: <C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>


On Jun 9, 2007, at 5:26 AM, Kent Johnson wrote:
>
> You could try running the easygui demo - just type
> python easygui.py
> on the command line from the directory containing easygui.

At your convenience, please explain the above statement. I don't know  
what "from the command line" means.

Rafael

From alan.gauld at btinternet.com  Sun Jun 10 09:22:45 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 08:22:45 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<466A805F.4070501@tds.net>
	<59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net>
Message-ID: <f4g8s8$c1b$1@sea.gmane.org>


"Rafael Bejarano" <bejarar at sbcglobal.net> wrote in message 
news:59FAEDFD-E096-4974-BE8E-BF23E15125DF at sbcglobal.net...
>I wrote the script in the Smultron test editor. To open it, I've
> first been selecting it and then selecting python launcher from the
> "Open with" submenu, whicch is under the "Open" menu. Opening the
> script file in this way brings up the terminal window. Here is the
> output I get.
>
> Last login: Sun Jun 10 01:38:22 on ttyp1
> Welcome to Darwin!
> rafael-bejaranos-ibook-g4:~ Rafael$ cd 
> '/Volumes/UNTITLED/Programming
> stuff/My python stuff/' && '/usr/local/bin/pythonw'  '/Volumes/
> UNTITLED/Programming stuff/My python stuff/codetester.py'  && echo
> Exit status: $? && exit 1

OK, Now, just to humour us, open a terminal window and go
to the directory with your python file and type

python codetester.py

I suspect it should be more helpful.

Alan G 



From bejarar at sbcglobal.net  Sun Jun 10 09:41:11 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 02:41:11 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4g8s8$c1b$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<466A805F.4070501@tds.net>
	<59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net>
	<f4g8s8$c1b$1@sea.gmane.org>
Message-ID: <988E9BC6-23A3-4206-A1ED-41C9B3739AE9@sbcglobal.net>


On Jun 10, 2007, at 2:22 AM, Alan Gauld wrote:
>
> open a terminal window and go
> to the directory with your python file and type
>
> python codetester.py

Please advise me as to how to go to the directory containing the  
python file from within the terminal window.

Thanks.
Rafael


From alan.gauld at btinternet.com  Sun Jun 10 09:48:15 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 08:48:15 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<B9ED5661-4135-4666-A9D5-A432B90F951D@sbcglobal.net>
Message-ID: <f4gac2$euk$1@sea.gmane.org>

"Rafael Bejarano" <bejarar at sbcglobal.net> wrote 
> Thanks for reminding me to post my code. Here it is.
> 
> #easygui test program
> import easygui
> import sys
> msg = "What do you prefer?"
> choices = ["$50.00 now", "$100.00 in 6 months"]
> choice = easygui.buttonbox(msg, "", choices)
> print choice

Ok, That worked perfectly for me after I installed easygui.

How/where did you install easygui.py? 
Does the easygui test program run OK?
  - Kent already asked you this but I don't remember a reply

>>> import easygui as ez
	>>> ez._test()

Alan G.


From alan.gauld at btinternet.com  Sun Jun 10 16:20:24 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 15:20:24 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org><466A805F.4070501@tds.net><59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net><f4g8s8$c1b$1@sea.gmane.org>
	<988E9BC6-23A3-4206-A1ED-41C9B3739AE9@sbcglobal.net>
Message-ID: <f4h1bb$8c8$1@sea.gmane.org>

"Rafael Bejarano" <bejarar at sbcglobal.net> wrote 

> On Jun 10, 2007, at 2:22 AM, Alan Gauld wrote:
>>
>> open a terminal window and go
>> to the directory with your python file and type
>>
>> python codetester.py
> 
> Please advise me as to how to go to the directory containing the  
> python file from within the terminal window.

Type, on one line:

cd  '/Volumes/UNTITLED/Programming  stuff/My python stuff/'

cd is the Change Directory command in Unix.

If you want to learn to program your Mac I really urge you to 
invest some time in learning how to drive MacOS X via 
the Terminal. It's much more powerful than using the GUI for 
everything and if you ever have to use a Linux box the skills 
will be transferrable.

Apple have some tutorials on their web site on using the 
Terminal, they are as  good a start as any.

Alan G.


From dsh0105 at comcast.net  Sun Jun 10 16:20:28 2007
From: dsh0105 at comcast.net (David Hamilton)
Date: Sun, 10 Jun 2007 09:20:28 -0500
Subject: [Tutor] Correct use of range function..
Message-ID: <466C08AC.2030201@comcast.net>

I just finished doing an exercise in a tutorial on the range function 
and while I got it to work, my answer seems ugly. I'm wondering if I'm 
missing something in the way I'm using the range function.
The tutorial ask me to print a string backwards. My solution works, but 
it it just doesn't "feel" right :).  My result is difficult to read and 
I feel like I'm probably over complicating the solution. Suggestions?

word="reverse"
#Start at the end of the string, count back to the start, printing each 
letter
for  i in range(len(word)-1,-1,-1):
    print word[i],






From alan.gauld at btinternet.com  Sun Jun 10 17:20:13 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 16:20:13 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
Message-ID: <f4h4rg$jfa$1@sea.gmane.org>


"Rafael Bejarano" <bejarar at sbcglobal.net> wrote

>> You could try running the easygui demo - just type
>> python easygui.py
>> on the command line from the directory containing easygui.
>
> At your convenience, please explain the above statement. I don't 
> know
> what "from the command line" means.

Kent is referring to the Unix command line in the Terminal window.

If you start Terminal then move to the folder where you
installed easygui.py (using the cd command I showed you earlier)
you can type the above command to execute the easygui test
program. This will prove that easygui is installed and working
correctly.

Alternatively, just start Python in Terminal and at
the >>> prompt type:

>>> import easygui as ez
>>> ez._test()   # note the . after ez...

Alan G 



From kent37 at tds.net  Sun Jun 10 17:31:44 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 10 Jun 2007 11:31:44 -0400
Subject: [Tutor] Correct use of range function..
In-Reply-To: <466C08AC.2030201@comcast.net>
References: <466C08AC.2030201@comcast.net>
Message-ID: <466C1960.9040108@tds.net>

David Hamilton wrote:
> I just finished doing an exercise in a tutorial on the range function 
> and while I got it to work, my answer seems ugly. I'm wondering if I'm 
> missing something in the way I'm using the range function.
> The tutorial ask me to print a string backwards. My solution works, but 
> it it just doesn't "feel" right :).  My result is difficult to read and 
> I feel like I'm probably over complicating the solution. Suggestions?
> 
> word="reverse"
> #Start at the end of the string, count back to the start, printing each 
> letter
> for  i in range(len(word)-1,-1,-1):
>     print word[i],

That's probably the best you can do using range(). You could write
ln = len(word)
for i in range(ln):
   print word[ln-i-1],

but that is not much different.

You can do better without using range; you can directly iterate the 
letters in reverse:

for c in word[::-1]:
   print c,

Kent

From jped.aru at gmail.com  Sun Jun 10 18:01:29 2007
From: jped.aru at gmail.com (Adam Urbas)
Date: Sun, 10 Jun 2007 11:01:29 -0500
Subject: [Tutor] Correct use of range function..
In-Reply-To: <466C1960.9040108@tds.net>
References: <466C08AC.2030201@comcast.net> <466C1960.9040108@tds.net>
Message-ID: <ef52818c0706100901y7516eac8t5a5f70bf4578958d@mail.gmail.com>

I discovered something about your revers word program here.  I used
the "for c in word" one.
if you type an indented print after print c, then it will print the
words vertically.  Just thought I'd share that with you.

On 6/10/07, Kent Johnson <kent37 at tds.net> wrote:
> David Hamilton wrote:
> > I just finished doing an exercise in a tutorial on the range function
> > and while I got it to work, my answer seems ugly. I'm wondering if I'm
> > missing something in the way I'm using the range function.
> > The tutorial ask me to print a string backwards. My solution works, but
> > it it just doesn't "feel" right :).  My result is difficult to read and
> > I feel like I'm probably over complicating the solution. Suggestions?
> >
> > word="reverse"
> > #Start at the end of the string, count back to the start, printing each
> > letter
> > for  i in range(len(word)-1,-1,-1):
> >     print word[i],
>
> That's probably the best you can do using range(). You could write
> ln = len(word)
> for i in range(ln):
>    print word[ln-i-1],
>
> but that is not much different.
>
> You can do better without using range; you can directly iterate the
> letters in reverse:
>
> for c in word[::-1]:
>    print c,
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From chi at chimeric.de  Sun Jun 10 18:31:39 2007
From: chi at chimeric.de (Michael Klier)
Date: Sun, 10 Jun 2007 18:31:39 +0200
Subject: [Tutor] looking for some general advice
Message-ID: <20070610163139.GD2538@shipdown.de>

Hi everyone,

I`ve started to dive into python a few weeks ago and am about to finish
my first script that surves a purpose, namely fetching podcasts on a
headless machine on a daily basis (fired up via cron). I use the pickle
module to save the information about the podcasts feeds and the script
provides some cli options to add/del feeds a.s.o.. It`s not object
oriented.

ATM I am looking for some general advice/hints, ie. if the stuff I wrote
makes sense. I am pretty sure most of it could be done in a smarter more
python like way ;). The code is available at:

http://nopaste.info/071ce76105.html

Maybe someone likes to have a quick look at it. 

Thanks in advance for all feedback.

Michael

-- 
Michael Klier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070610/9c2b1ffa/attachment.pgp 

From alan.gauld at btinternet.com  Sun Jun 10 19:14:08 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 18:14:08 +0100
Subject: [Tutor] Correct use of range function..
References: <466C08AC.2030201@comcast.net> <466C1960.9040108@tds.net>
Message-ID: <f4hbh4$900$1@sea.gmane.org>

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

> You can do better without using range; you can directly iterate the
> letters in reverse:
>
> for c in word[::-1]:
>   print c,

Or even just

print word[::-1]

:-)

Alan G. 



From alan.gauld at btinternet.com  Sun Jun 10 19:16:00 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 18:16:00 +0100
Subject: [Tutor] Correct use of range function..
References: <466C08AC.2030201@comcast.net> <466C1960.9040108@tds.net>
	<ef52818c0706100901y7516eac8t5a5f70bf4578958d@mail.gmail.com>
Message-ID: <f4hbkj$9ca$1@sea.gmane.org>


"Adam Urbas" <jped.aru at gmail.com> wrote
>I discovered something about your revers word program here.  I used
> the "for c in word" one.
> if you type an indented print after print c, then it will print the
> words vertically.  Just thought I'd share that with you.

You can achieve the same by missing out the comma at the end
of the print statement too. The comma suppresses a newline
character. By using a second print you put it back! So just
missing the comma achieves the same end result.

Alan G.

> On 6/10/07, Kent Johnson <kent37 at tds.net> wrote:
>> David Hamilton wrote:
>> > I just finished doing an exercise in a tutorial on the range 
>> > function
>> > and while I got it to work, my answer seems ugly. I'm wondering 
>> > if I'm
>> > missing something in the way I'm using the range function.
>> > The tutorial ask me to print a string backwards. My solution 
>> > works, but
>> > it it just doesn't "feel" right :).  My result is difficult to 
>> > read and
>> > I feel like I'm probably over complicating the solution. 
>> > Suggestions?
>> >
>> > word="reverse"
>> > #Start at the end of the string, count back to the start, 
>> > printing each
>> > letter
>> > for  i in range(len(word)-1,-1,-1):
>> >     print word[i],
>>
>> That's probably the best you can do using range(). You could write
>> ln = len(word)
>> for i in range(ln):
>>    print word[ln-i-1],
>>
>> but that is not much different.
>>
>> You can do better without using range; you can directly iterate the
>> letters in reverse:
>>
>> for c in word[::-1]:
>>    print c,
>>
>> Kent
>> _______________________________________________
>> 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  Sun Jun 10 19:32:54 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 10 Jun 2007 18:32:54 +0100
Subject: [Tutor] looking for some general advice
References: <20070610163139.GD2538@shipdown.de>
Message-ID: <f4hcka$chm$1@sea.gmane.org>

Michael,

That's a fairly big project for a first timer, its obvious that you 
are new to Python rather than to programming. It looks 
pretty good to be honest, the main things I'd flag are:

1) Best to be specific in your except clauses. Generic 
catch-anything type clauses can lead to misleading error 
messages. They are OKmat the top level of a program for 
distribution as a way of shielding innocent users from stack 
traces but during development and especially inside your 
code its better to catch specific exceptions.

2) Rather than putting the exception name in quotes 
"IndexError" just leave the quotes off and raise/catch the 
error class directly.

3) argv = sys.argv 
Doesn't really achieve much, you might as well just use sys.argv, 
it's not much extra typing! nit-picking...

4) For completeness you could avoid the os.system call to 
wget and implement it as a Python function using the ftplib 
library... (But to be honest wget is a lot easier!) Or maybe 
use the new subprocess module instead of os.system.
You might also want to check that wget executed successfully.

Othewise I don't see too much to complain about.

Well done, a good first program.


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




From bejarar at sbcglobal.net  Sun Jun 10 19:43:25 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 12:43:25 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4gac2$euk$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<B9ED5661-4135-4666-A9D5-A432B90F951D@sbcglobal.net>
	<f4gac2$euk$1@sea.gmane.org>
Message-ID: <C78D3B2A-D8EE-4B79-893D-C3BCB85094DA@sbcglobal.net>

On Jun 10, 2007, at 2:48 AM, Alan Gauld wrote:
>
> How/where did you install easygui.py?

I installed it by copying easygui.py from the downloaded folder,  
which was on my desktop, into the folder in which the test program is  
stored. Was that not okay?
> Does the easygui test program run OK?
>   - Kent already asked you this but I don't remember a reply

No, although no error messages appear, the program does not display  
dialog boxes. Here is the demo program I ran:

from easygui import *
import sys

while 1:
	msgbox("Hello, world!")

	msg ="What is your favorite flavor?"
	title = "Ice Cream Survey"
	choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
	choice = choicebox(msg, title, choices)

	# note that we convert choice to string, in case
	# the user cancelled the choice, and we got None.
	msgbox("You chose: " + str(choice), "Survey Result")

	msg = "Do you want to continue?"
	title = "Please Confirm"
	if ccbox(msg, title):     # show a Continue/Cancel dialog
		pass  # user chose Continue
	else:
		sys.exit(0)           # user chose Cancel

From chi at chimeric.de  Sun Jun 10 21:19:39 2007
From: chi at chimeric.de (Michael Klier)
Date: Sun, 10 Jun 2007 21:19:39 +0200
Subject: [Tutor] looking for some general advice
In-Reply-To: <f4hcka$chm$1@sea.gmane.org>
References: <20070610163139.GD2538@shipdown.de> <f4hcka$chm$1@sea.gmane.org>
Message-ID: <20070610191939.GE2538@shipdown.de>

Alan Gauld wrote:
> 1) Best to be specific in your except clauses. Generic 
> catch-anything type clauses can lead to misleading error 
> messages. They are OKmat the top level of a program for 
> distribution as a way of shielding innocent users from stack 
> traces but during development and especially inside your 
> code its better to catch specific exceptions.
> 
> 2) Rather than putting the exception name in quotes 
> "IndexError" just leave the quotes off and raise/catch the 
> error class directly.

Ah, ok. I already wondered why one "IndexError" wasn`t caught even
though I tried to access a list item which was out of range. After
removing the quotes it worked.

Also, what would be the right exception to raise if not enough arguments
were passed to a programm?

> 3) argv = sys.argv 
> Doesn't really achieve much, you might as well just use sys.argv, 
> it's not much extra typing! nit-picking...

You`re right, it`s not much extra typing :).

> 4) For completeness you could avoid the os.system call to 
> wget and implement it as a Python function using the ftplib 
> library... (But to be honest wget is a lot easier!) Or maybe 
> use the new subprocess module instead of os.system.
> You might also want to check that wget executed successfully.

I`ll take your advice about checking wegts exist status and thanks for
the tip with ftplib, although I think it`s a bit too much for my state
of python knowledge right now.

> Othewise I don't see too much to complain about.
> 
> Well done, a good first program.

Thank you, and thanks for the reply.

Regards
Michael

-- 
Michael Klier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070610/26bfa850/attachment.pgp 

From kent37 at tds.net  Sun Jun 10 21:19:42 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 10 Jun 2007 15:19:42 -0400
Subject: [Tutor] easygui question, again
In-Reply-To: <C78D3B2A-D8EE-4B79-893D-C3BCB85094DA@sbcglobal.net>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>	<B9ED5661-4135-4666-A9D5-A432B90F951D@sbcglobal.net>	<f4gac2$euk$1@sea.gmane.org>
	<C78D3B2A-D8EE-4B79-893D-C3BCB85094DA@sbcglobal.net>
Message-ID: <466C4ECE.5010406@tds.net>

Rafael Bejarano wrote:
> On Jun 10, 2007, at 2:48 AM, Alan Gauld wrote:
>> How/where did you install easygui.py?
> 
> I installed it by copying easygui.py from the downloaded folder,  
> which was on my desktop, into the folder in which the test program is  
> stored. Was that not okay?

That should work if you run from the same directory.

>> Does the easygui test program run OK?
>>   - Kent already asked you this but I don't remember a reply
> 
> No, although no error messages appear, the program does not display  
> dialog boxes. 

Did you run this from Terminal or Smultron? Probably the program is 
displaying an error but you are not seeing it. Running from Terminal is 
the best way to ensure that you see all the program output. Once we see 
an error message we can help find the problem.

Try this:
- Open Terminal (from Applications/Utilities)
- Type
cd '/Volumes/UNTITLED/Programming stuff/My python stuff/'

(or whatever the correct directory is)
- Type
python demo.py

(or whatever you called your demo program)

Copy the output, paste it into an email and send to the list.

Kent
> Here is the demo program I ran:
> 
> from easygui import *
> import sys
> 
> while 1:
> 	msgbox("Hello, world!")
> 
> 	msg ="What is your favorite flavor?"
> 	title = "Ice Cream Survey"
> 	choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
> 	choice = choicebox(msg, title, choices)
> 
> 	# note that we convert choice to string, in case
> 	# the user cancelled the choice, and we got None.
> 	msgbox("You chose: " + str(choice), "Survey Result")
> 
> 	msg = "Do you want to continue?"
> 	title = "Please Confirm"
> 	if ccbox(msg, title):     # show a Continue/Cancel dialog
> 		pass  # user chose Continue
> 	else:
> 		sys.exit(0)           # user chose Cancel
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From bejarar at sbcglobal.net  Sun Jun 10 22:48:26 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 15:48:26 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4h1bb$8c8$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org><466A805F.4070501@tds.net><59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net><f4g8s8$c1b$1@sea.gmane.org>
	<988E9BC6-23A3-4206-A1ED-41C9B3739AE9@sbcglobal.net>
	<f4h1bb$8c8$1@sea.gmane.org>
Message-ID: <D22DB2EE-9A58-44BD-90F9-EF8FC5CDDCFA@sbcglobal.net>

Okay. I typed the following two lines

cd  '/Volumes/UNTITLED/Programming  stuff/My python stuff/
python codetester.py

This is the output I got:

Last login: Sun Jun 10 15:44:42 on ttyp1
Welcome to Darwin!
rafael-bejaranos-ibook-g4:~ Rafael$ cd  '/Volumes/UNTITLED/ 
Programming  stuff/My python stuff/
 > python codetester.py
 >



















From bejarar at sbcglobal.net  Sun Jun 10 23:14:50 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 16:14:50 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4h1bb$8c8$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org><466A805F.4070501@tds.net><59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net><f4g8s8$c1b$1@sea.gmane.org>
	<988E9BC6-23A3-4206-A1ED-41C9B3739AE9@sbcglobal.net>
	<f4h1bb$8c8$1@sea.gmane.org>
Message-ID: <15193BBB-4346-4106-A474-0FCBFA1DB833@sbcglobal.net>


On Jun 10, 2007, at 9:20 AM, Alan Gauld wrote:
>
> Type, on one line:
>
> cd  '/Volumes/UNTITLED/Programming  stuff/My python stuff/'

I copied the above line from your e-mail and pasted it into the  
terminal window. When I hit enter, I got the following output:

Last login: Sun Jun 10 16:09:10 on ttyp1
Welcome to Darwin!
rafael-bejaranos-ibook-g4:~ Rafael$ cd  '/Volumes/UNTITLED/ 
Programming  stuff/My python stuff/'
-bash: cd: /Volumes/UNTITLED/Programming  stuff/My python stuff/: No  
such file or directory
rafael-bejaranos-ibook-g4:~ Rafael$



















From thorsten at thorstenkampe.de  Mon Jun 11 00:00:58 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Sun, 10 Jun 2007 23:00:58 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
Message-ID: <f4hsar$qa9$1@sea.gmane.org>

* Rafael Bejarano (Sun, 10 Jun 2007 02:24:56 -0500)
> On Jun 9, 2007, at 5:26 AM, Kent Johnson wrote:
> > You could try running the easygui demo - just type
> > python easygui.py
> > on the command line from the directory containing easygui.
> 
> At your convenience, please explain the above statement. I don't know  
> what "from the command line" means.

It would really make sense if you learn a bit of the basics before you 
start doing the advanced stuff like (Python) programming...


From kent37 at tds.net  Mon Jun 11 00:59:16 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 10 Jun 2007 18:59:16 -0400
Subject: [Tutor] easygui question, again
In-Reply-To: <15193BBB-4346-4106-A474-0FCBFA1DB833@sbcglobal.net>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org><466A805F.4070501@tds.net><59FAEDFD-E096-4974-BE8E-BF23E15125DF@sbcglobal.net><f4g8s8$c1b$1@sea.gmane.org>	<988E9BC6-23A3-4206-A1ED-41C9B3739AE9@sbcglobal.net>	<f4h1bb$8c8$1@sea.gmane.org>
	<15193BBB-4346-4106-A474-0FCBFA1DB833@sbcglobal.net>
Message-ID: <466C8244.9040809@tds.net>

Rafael Bejarano wrote:
> On Jun 10, 2007, at 9:20 AM, Alan Gauld wrote:
>> Type, on one line:
>>
>> cd  '/Volumes/UNTITLED/Programming  stuff/My python stuff/'
> 
> I copied the above line from your e-mail and pasted it into the  
> terminal window. When I hit enter, I got the following output:
> 
> Last login: Sun Jun 10 16:09:10 on ttyp1
> Welcome to Darwin!
> rafael-bejaranos-ibook-g4:~ Rafael$ cd  '/Volumes/UNTITLED/ 
> Programming  stuff/My python stuff/'
> -bash: cd: /Volumes/UNTITLED/Programming  stuff/My python stuff/: No  
> such file or directory
> rafael-bejaranos-ibook-g4:~ Rafael$

OK, the path '/Volumes/UNTITLED/Programming  stuff/My python stuff/' was 
copied out of *your* email. Change it to the correct path for the folder 
containing your program and try again.

Kent


From Joel.Levine at Dartmouth.EDU  Mon Jun 11 00:55:20 2007
From: Joel.Levine at Dartmouth.EDU (Joel Levine)
Date: 10 Jun 2007 18:55:20 -0400
Subject: [Tutor] easygui question, again
Message-ID: <86984323@newdancer.Dartmouth.EDU>

A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 342 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070610/708f3bcc/attachment.bin 

From alan.gauld at btinternet.com  Mon Jun 11 01:43:23 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 11 Jun 2007 00:43:23 +0100
Subject: [Tutor] looking for some general advice
References: <20070610163139.GD2538@shipdown.de> <f4hcka$chm$1@sea.gmane.org>
	<20070610191939.GE2538@shipdown.de>
Message-ID: <f4i2av$bqd$1@sea.gmane.org>


"Michael Klier" <chi at chimeric.de> wrote 

I'm not surecwhy but your messages are coming through to me 
as text attachments which makes quoting them tricky...

> Also, what would be the right exception to raise if not 
> enough arguments were passed to a programm?

I don't think there is a right answer, you can decide 
for yourself, buty in general I try using the >>> prompt 
with a deliberate error to see what Python does, thus:

>>> range()
Traceback (most recent call last):
  File "<input>", line 1, in ?
TypeError: range expected at least 1 arguments, got 0

So it looks like TypeError but personally I'm not so sure 
that works for argv... I think a simple usage message and 
exit with non zero is fine.

Alan G.






From kent37 at tds.net  Mon Jun 11 02:16:43 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 10 Jun 2007 20:16:43 -0400
Subject: [Tutor] looking for some general advice
In-Reply-To: <f4i2av$bqd$1@sea.gmane.org>
References: <20070610163139.GD2538@shipdown.de>
	<f4hcka$chm$1@sea.gmane.org>	<20070610191939.GE2538@shipdown.de>
	<f4i2av$bqd$1@sea.gmane.org>
Message-ID: <466C946B.5080004@tds.net>

Alan Gauld wrote:
> "Michael Klier" <chi at chimeric.de> wrote 
> 
> I'm not surecwhy but your messages are coming through to me 
> as text attachments which makes quoting them tricky...
> 
>> Also, what would be the right exception to raise if not 
>> enough arguments were passed to a programm?
> 
> I don't think there is a right answer, you can decide 
> for yourself, buty in general I try using the >>> prompt 
> with a deliberate error to see what Python does

I look at the docs for built-in exceptions to see which might apply:
http://docs.python.org/lib/module-exceptions.html

> I think a simple usage message and 
> exit with non zero is fine.

I agree with that...

Kent

From bejarar at sbcglobal.net  Mon Jun 11 02:35:32 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 19:35:32 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4hsar$qa9$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
	<f4hsar$qa9$1@sea.gmane.org>
Message-ID: <1DC3BF47-91B7-49CA-A166-D06C6F56676C@sbcglobal.net>


On Jun 10, 2007, at 5:00 PM, Thorsten Kampe wrote:
>
> It would really make sense if you learn a bit of the basics before you
> start doing the advanced stuff like (Python) programming...

What do you mean by "a bit of the basics?"

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


From bejarar at sbcglobal.net  Mon Jun 11 02:48:42 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 19:48:42 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <86984323@newdancer.Dartmouth.EDU>
References: <86984323@newdancer.Dartmouth.EDU>
Message-ID: <22334466-ECD1-41B0-A137-03667ACC32A2@sbcglobal.net>

Thanks for the suggestion. I think it is a good idea to learn unix  
for the Mac, and I definitely plan to do that. I thought, though,  
that it would be a relatively simple matter to import the easygui  
module and call its functions using the terminal window, especially  
given that I have had success in the past importing other modules and  
calling their functions.

cordially,
Rafael
On Jun 10, 2007, at 5:55 PM, Joel Levine wrote:

> Suggestion: Consider
>
> Unix for Mac
> Wiley Publishing & maranGraphics.
>
> also
>
> Python Programming for the absolute beginner by Michael Dawson
> ... and don't be offended if it looks too simple.
>
> The problem with 'beginning' a  computer language is that few  
> people agree where the beginning is.  We come from many different  
> backgrounds.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From thorsten at thorstenkampe.de  Mon Jun 11 03:27:23 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 11 Jun 2007 02:27:23 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
	<f4hsar$qa9$1@sea.gmane.org>
	<1DC3BF47-91B7-49CA-A166-D06C6F56676C@sbcglobal.net>
Message-ID: <f4i8ds$o97$1@sea.gmane.org>

* Rafael Bejarano (Sun, 10 Jun 2007 19:35:32 -0500)
> On Jun 10, 2007, at 5:00 PM, Thorsten Kampe wrote:
> > It would really make sense if you learn a bit of the basics before you
> > start doing the advanced stuff like (Python) programming...
> 
> What do you mean by "a bit of the basics?"

Well, like - what is a command line, how do I change from one 
directory to another and stuff. The basics...


From bejarar at sbcglobal.net  Mon Jun 11 03:49:40 2007
From: bejarar at sbcglobal.net (Rafael Bejarano)
Date: Sun, 10 Jun 2007 20:49:40 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <f4i8ds$o97$1@sea.gmane.org>
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
	<f4hsar$qa9$1@sea.gmane.org>
	<1DC3BF47-91B7-49CA-A166-D06C6F56676C@sbcglobal.net>
	<f4i8ds$o97$1@sea.gmane.org>
Message-ID: <874CC19E-8A86-4C35-BF0E-1765D024F2B4@sbcglobal.net>

As I understand it from the description of this list, that is exactly  
its purpose--to help people who no relatively little python. As it  
happens, I have been moderately successful in running other modules,  
so I think it is not inappropriate for me to have posted the  
questions that I have posted to date.

Naturally, if the list collectively deems my questions inappropriate,  
I will stop asking them. I appreciate the time that several of its  
members have taken to try to help me with my problem, even though I  
haven't been successful in getting easygui to work.

Rafael Bejarano
On Jun 10, 2007, at 8:27 PM, Thorsten Kampe wrote:

> * Rafael Bejarano (Sun, 10 Jun 2007 19:35:32 -0500)
>> On Jun 10, 2007, at 5:00 PM, Thorsten Kampe wrote:
>>> It would really make sense if you learn a bit of the basics  
>>> before you
>>> start doing the advanced stuff like (Python) programming...
>>
>> What do you mean by "a bit of the basics?"
>
> Well, like - what is a command line, how do I change from one
> directory to another and stuff. The basics...
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


From alan.gauld at btinternet.com  Mon Jun 11 09:36:13 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 11 Jun 2007 08:36:13 +0100
Subject: [Tutor] easygui question, again
References: <86984323@newdancer.Dartmouth.EDU>
	<22334466-ECD1-41B0-A137-03667ACC32A2@sbcglobal.net>
Message-ID: <f4iu1h$adh$1@sea.gmane.org>


"Rafael Bejarano" <bejarar at sbcglobal.net> wrote

> that it would be a relatively simple matter to import the easygui
> module and call its functions using the terminal window, especially
> given that I have had success in the past importing other modules 
> and
> calling their functions.

I suspect that this is because you have been using
the standard library modules which Python knows how to find.
When you add a downloaded module, like easygui, you need
to let Python know how to find it. This is done in one of
three ways:
1) Put it in the same folder from which you run python
2) Put it in <PYTHON>/lib/site-packages
3) Put in in some other folder and add that folder to
    your PYTHONPATH environment variable setting

The easiest way for you is probably number 2.

Try following this procedure:

1) Start Python to get a >>> prompt
2) import sys
3) print sys.path
4) use the mouse to select one of the lines that contains 
"site-packages"
5) Open a Finder window
6) Navigate in Finder to the folder highlighted in your Python window
7) If necessary navigate back up to site-packages itself
8) Create a new sub folder and name it EasyGui
9) Copy easygui.py into the new folder
10) Create a new text file called EasyGui.pth
11) enter the single line "EasyGui" (without the quotes) and save/exit 
the editor
12) exit python and enter it again.
13) type import easygui at the Python prompt.

If no error messages appear you should have installed easygui
where python can see it.

NB I typed that at my PC so its from memory and untested but
hopefully its close enough that you can figure out any discrepancies.

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 Jun 11 09:45:53 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 11 Jun 2007 08:45:53 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net><f4dkro$2cq$1@sea.gmane.org>
	<466A805F.4070501@tds.net><C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net><f4hsar$qa9$1@sea.gmane.org><1DC3BF47-91B7-49CA-A166-D06C6F56676C@sbcglobal.net><f4i8ds$o97$1@sea.gmane.org>
	<874CC19E-8A86-4C35-BF0E-1765D024F2B4@sbcglobal.net>
Message-ID: <f4iujl$c52$1@sea.gmane.org>

"Rafael Bejarano" <bejarar at sbcglobal.net> wrote

> As I understand it from the description of this list, that is 
> exactly
> its purpose--to help people who no relatively little python.

That's true, but usually the folks asking questions are
fairly expert at using their computers so they are familiar
with concepts like command lines, changing directories,
creating text files, setting environment variables etc.
I suspect you are too within the  confines of the MacOS GUI,
the problem is that MacOS is such a good GUI that Mac
users rarely need to use a command line!

Unfortunately programming on any computer requires a
reasonable knowledge of the technical underpinnings of
how the computer works, something many Mac users
don't necessarily have. The easiest way to access
these things is via the Terminal application and the
Unix command prompt. The others are suggesting
that before progressing further you should invest the
time to learn the basics of using the MacOS Unix
command prompt.

In fact I think the only problem here is that you are trying
to use a non-standard module and something is wrong
with how it is set up. (See my other post). If you stick to
the standard Python modules you will be fine.

> Naturally, if the list collectively deems my questions 
> inappropriate,

The questions are fine, unfortunately the solutions require
some skills and knowledge that you apparently don't
possess yet. That's OK but this list is not the best place
to learn how to drive MacOS since most members don't
use it. But enough of us do that we should be able to give
you some pointers at least.

Regards,

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



From thorsten at thorstenkampe.de  Mon Jun 11 10:23:24 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 11 Jun 2007 09:23:24 +0100
Subject: [Tutor] easygui question, again
References: <287533BD-E7F6-4F95-A531-FABC3B367BAF@sbcglobal.net>
	<f4dkro$2cq$1@sea.gmane.org> <466A805F.4070501@tds.net>
	<C9D6A22A-B842-4DEF-AC7F-ED7A59F9D05F@sbcglobal.net>
	<f4hsar$qa9$1@sea.gmane.org>
	<1DC3BF47-91B7-49CA-A166-D06C6F56676C@sbcglobal.net>
	<f4i8ds$o97$1@sea.gmane.org>
	<874CC19E-8A86-4C35-BF0E-1765D024F2B4@sbcglobal.net>
Message-ID: <f4j0pv$i38$1@sea.gmane.org>

* Rafael Bejarano (Sun, 10 Jun 2007 20:49:40 -0500)
> As I understand it from the description of this list, that is exactly  
> its purpose--to help people who no relatively little python.

That's correct. But your problem (or the solution to your problem) is 
more related to _Operating System_ basics as to Python basics (see 
also Alan Gaulds response).

And please don't send me private email.

Thanks, Thorsten


From chi at chimeric.de  Mon Jun 11 10:58:40 2007
From: chi at chimeric.de (Michael Klier)
Date: Mon, 11 Jun 2007 10:58:40 +0200
Subject: [Tutor] looking for some general advice
In-Reply-To: <f4i2av$bqd$1@sea.gmane.org>
References: <20070610163139.GD2538@shipdown.de> <f4hcka$chm$1@sea.gmane.org>
	<20070610191939.GE2538@shipdown.de> <f4i2av$bqd$1@sea.gmane.org>
Message-ID: <20070611085839.GF2538@shipdown.de>

Alan Gauld wrote:
> I'm not surecwhy but your messages are coming through to me 
> as text attachments which makes quoting them tricky...

Hmmm, I did a group reply in mutt the last time, lets see if a direct
reply and manuall CC: works right.

> > Also, what would be the right exception to raise if not 
> > enough arguments were passed to a programm?
> 
> I don't think there is a right answer, you can decide 
> for yourself, buty in general I try using the >>> prompt 
> with a deliberate error to see what Python does, thus:
> 
> >>> range()
> Traceback (most recent call last):
>   File "<input>", line 1, in ?
> TypeError: range expected at least 1 arguments, got 0

That`s a very useful hint :) (makes me ask myself why I didn`t thought
about that yet ;)).

> So it looks like TypeError but personally I'm not so sure 
> that works for argv... I think a simple usage message and 
> exit with non zero is fine.

Well, that`s an option I didn`t thought of yet, I think I`ll do it that
way then.

Thanks or all your feedback.

Best Regards
Michael

-- 
Michael Klier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070611/549809d0/attachment.pgp 

From kent37 at tds.net  Mon Jun 11 12:26:26 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 11 Jun 2007 06:26:26 -0400
Subject: [Tutor] easygui question, again
In-Reply-To: <f4iu1h$adh$1@sea.gmane.org>
References: <86984323@newdancer.Dartmouth.EDU>	<22334466-ECD1-41B0-A137-03667ACC32A2@sbcglobal.net>
	<f4iu1h$adh$1@sea.gmane.org>
Message-ID: <466D2352.9040004@tds.net>

Alan Gauld wrote:
> "Rafael Bejarano" <bejarar at sbcglobal.net> wrote
> 
>> that it would be a relatively simple matter to import the easygui
>> module and call its functions using the terminal window, especially
>> given that I have had success in the past importing other modules 
>> and
>> calling their functions.
> 
> I suspect that this is because you have been using
> the standard library modules which Python knows how to find.
> When you add a downloaded module, like easygui, you need
> to let Python know how to find it. This is done in one of
> three ways:
> 1) Put it in the same folder from which you run python
> 2) Put it in <PYTHON>/lib/site-packages
> 3) Put in in some other folder and add that folder to
>     your PYTHONPATH environment variable setting
> 
> The easiest way for you is probably number 2.
> 
> Try following this procedure:
> 
> 1) Start Python to get a >>> prompt

Which means,
1a) Open Terminal
1b) type python and press return

> 2) import sys
> 3) print sys.path
> 4) use the mouse to select one of the lines that contains 
> "site-packages"

It won't be a line, it will be a long list. Depending on how your Python 
is installed site-packages will be at a location like
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages
or
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
> 5) Open a Finder window
> 6) Navigate in Finder to the folder highlighted in your Python window
> 7) If necessary navigate back up to site-packages itself
> 8) Create a new sub folder and name it EasyGui
> 9) Copy easygui.py into the new folder
> 10) Create a new text file called EasyGui.pth
> 11) enter the single line "EasyGui" (without the quotes) and save/exit 
> the editor

This will work but instead of 8-11 I would just copy easygui.py into 
site-packages.

Kent

> 12) exit python and enter it again.
> 13) type import easygui at the Python prompt.
> 
> If no error messages appear you should have installed easygui
> where python can see it.
> 
> NB I typed that at my PC so its from memory and untested but
> hopefully its close enough that you can figure out any discrepancies.
> 
> HTH,
> 


From Andy.cheesman at bristol.ac.uk  Mon Jun 11 13:55:03 2007
From: Andy.cheesman at bristol.ac.uk (Andy Cheesman)
Date: Mon, 11 Jun 2007 12:55:03 +0100
Subject: [Tutor] Ipython and refreshing changed modules
Message-ID: <466D3817.7040004@bristol.ac.uk>

Dear People

Silly question, I'm using Ipython and importing python modules  which
I've written. After a code modification, is there an easy, quick way to
refresh changed modules?
I've googled for the solutions but the answers does not seem clear!

Andy

From alan.gauld at btinternet.com  Mon Jun 11 14:27:41 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 11 Jun 2007 13:27:41 +0100
Subject: [Tutor] Ipython and refreshing changed modules
References: <466D3817.7040004@bristol.ac.uk>
Message-ID: <f4jf41$5e2$1@sea.gmane.org>


"Andy Cheesman" <Andy.cheesman at bristol.ac.uk> wrote

> I've written. After a code modification, is there an easy, quick way 
> to
> refresh changed modules?

Look at the reload() function.

Alan G 



From thorsten at thorstenkampe.de  Mon Jun 11 15:07:38 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Mon, 11 Jun 2007 14:07:38 +0100
Subject: [Tutor] Ipython and refreshing changed modules
References: <466D3817.7040004@bristol.ac.uk> <f4jf41$5e2$1@sea.gmane.org>
Message-ID: <f4jher$dk6$1@sea.gmane.org>

* Alan Gauld (Mon, 11 Jun 2007 13:27:41 +0100)
> "Andy Cheesman" <Andy.cheesman at bristol.ac.uk> wrote
> 
> > I've written. After a code modification, is there an easy, quick way 
> > to
> > refresh changed modules?
> 
> Look at the reload() function.

...and the deep reload option (which is the primary functional 
enhancement to the standard Python console)...

(Of course that's all pretty much documented in IPython's docs)


From adamurbas at hotmail.com  Mon Jun 11 17:04:29 2007
From: adamurbas at hotmail.com (adam urbas)
Date: Mon, 11 Jun 2007 10:04:29 -0500
Subject: [Tutor] Correct use of range function..
Message-ID: <BAY103-W143CFA933900E5CAD8A54AB11A0@phx.gbl>

I see... Very Intriguing.> To: tutor at python.org> From: alan.gauld at btinternet.com> Date: Sun, 10 Jun 2007 18:16:00 +0100> Subject: Re: [Tutor] Correct use of range function..> > > "Adam Urbas" <jped.aru at gmail.com> wrote> >I discovered something about your revers word program here.  I used> > the "for c in word" one.> > if you type an indented print after print c, then it will print the> > words vertically.  Just thought I'd share that with you.> > You can achieve the same by missing out the comma at the end> of the print statement too. The comma suppresses a newline> character. By using a second print you put it back! So just> missing the comma achieves the same end result.> > Alan G.> > > On 6/10/07, Kent Johnson <kent37 at tds.net> wrote:> >> David Hamilton wrote:> >> > I just finished doing an exercise in a tutorial on the range > >> > function> >> > and while I got it to work, my answer seems ugly. I'm wondering > >> > if I'm> >> > missing something in the way I'm using the range function.> >> > The tutorial ask me to print a string backwards. My solution > >> > works, but> >> > it it just doesn't "feel" right :).  My result is difficult to > >> > read and> >> > I feel like I'm probably over complicating the solution. > >> > Suggestions?> >> >> >> > word="reverse"> >> > #Start at the end of the string, count back to the start, > >> > printing each> >> > letter> >> > for  i in range(len(word)-1,-1,-1):> >> >     print word[i],> >>> >> That's probably the best you can do using range(). You could write> >> ln = len(word)> >> for i in range(ln):> >>    print word[ln-i-1],> >>> >> but that is not much different.> >>> >> You can do better without using range; you can directly iterate the> >> letters in reverse:> >>> >> for c in word[::-1]:> >>    print c,> >>> >> Kent> >> _______________________________________________> >> 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> > > > > _______________________________________________> Tutor maillist  -  Tutor at python.org> http://mail.python.org/mailman/listinfo/tutor
_________________________________________________________________
Hotmail to go? Get your Hotmail, news, sports and much more! Check out the New MSN Mobile! 
http://mobile.msn.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070611/643fadeb/attachment.html 

From simon at partex.co.uk  Mon Jun 11 16:52:16 2007
From: simon at partex.co.uk (Simon Hooper)
Date: Mon, 11 Jun 2007 15:52:16 +0100
Subject: [Tutor] Off-Topic - Mutt and mailing lists
In-Reply-To: <20070611085839.GF2538@shipdown.de>
References: <20070610163139.GD2538@shipdown.de> <f4hcka$chm$1@sea.gmane.org>
	<20070610191939.GE2538@shipdown.de> <f4i2av$bqd$1@sea.gmane.org>
	<20070611085839.GF2538@shipdown.de>
Message-ID: <20070611145215.GB8386@partex.co.uk>

Hi Michael,

* On 11/06/07, Michael Klier wrote:
> Alan Gauld wrote:
> > I'm not surecwhy but your messages are coming through to me 
> > as text attachments which makes quoting them tricky...
> 
> Hmmm, I did a group reply in mutt the last time, lets see if a direct
> reply and manuall CC: works right.

I don't know if you are aware, but mutt has a great list-reply command
(bound to L by default) which "does the right thing" for mailing lists.
Look up list-reply in the mutt manual.

HTH

Simon.

-- 
Simon Hooper

From jped.aru at gmail.com  Mon Jun 11 17:21:10 2007
From: jped.aru at gmail.com (Adam Urbas)
Date: Mon, 11 Jun 2007 10:21:10 -0500
Subject: [Tutor] easygui question, again
In-Reply-To: <466D2352.9040004@tds.net>
References: <86984323@newdancer.Dartmouth.EDU>
	<22334466-ECD1-41B0-A137-03667ACC32A2@sbcglobal.net>
	<f4iu1h$adh$1@sea.gmane.org> <466D2352.9040004@tds.net>
Message-ID: <ef52818c0706110821v296bfdbbsb9d008d8941469f2@mail.gmail.com>

Where did you get this easygui thing you are trying to install.  Is it
the thing that says Compiled Python File?  If so I have it.  I've
kinda been following your little chat here about it.  I want to see if
I could do it.

On 6/11/07, Kent Johnson <kent37 at tds.net> wrote:
> Alan Gauld wrote:
> > "Rafael Bejarano" <bejarar at sbcglobal.net> wrote
> >
> >> that it would be a relatively simple matter to import the easygui
> >> module and call its functions using the terminal window, especially
> >> given that I have had success in the past importing other modules
> >> and
> >> calling their functions.
> >
> > I suspect that this is because you have been using
> > the standard library modules which Python knows how to find.
> > When you add a downloaded module, like easygui, you need
> > to let Python know how to find it. This is done in one of
> > three ways:
> > 1) Put it in the same folder from which you run python
> > 2) Put it in <PYTHON>/lib/site-packages
> > 3) Put in in some other folder and add that folder to
> >     your PYTHONPATH environment variable setting
> >
> > The easiest way for you is probably number 2.
> >
> > Try following this procedure:
> >
> > 1) Start Python to get a >>> prompt
>
> Which means,
> 1a) Open Terminal
> 1b) type python and press return
>
> > 2) import sys
> > 3) print sys.path
> > 4) use the mouse to select one of the lines that contains
> > "site-packages"
>
> It won't be a line, it will be a long list. Depending on how your Python
> is installed site-packages will be at a location like
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages
> or
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
> > 5) Open a Finder window
> > 6) Navigate in Finder to the folder highlighted in your Python window
> > 7) If necessary navigate back up to site-packages itself
> > 8) Create a new sub folder and name it EasyGui
> > 9) Copy easygui.py into the new folder
> > 10) Create a new text file called EasyGui.pth
> > 11) enter the single line "EasyGui" (without the quotes) and save/exit
> > the editor
>
> This will work but instead of 8-11 I would just copy easygui.py into
> site-packages.
>
> Kent
>
> > 12) exit python and enter it again.
> > 13) type import easygui at the Python prompt.
> >
> > If no error messages appear you should have installed easygui
> > where python can see it.
> >
> > NB I typed that at my PC so its from memory and untested but
> > hopefully its close enough that you can figure out any discrepancies.
> >
> > HTH,
> >
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From kent37 at tds.net  Mon Jun 11 17:23:36 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 11 Jun 2007 11:23:36 -0400
Subject: [Tutor] easygui question, again
In-Reply-To: <ef52818c0706110821v296bfdbbsb9d008d8941469f2@mail.gmail.com>
References: <86984323@newdancer.Dartmouth.EDU>	
	<22334466-ECD1-41B0-A137-03667ACC32A2@sbcglobal.net>	
	<f4iu1h$adh$1@sea.gmane.org> <466D2352.9040004@tds.net>
	<ef52818c0706110821v296bfdbbsb9d008d8941469f2@mail.gmail.com>
Message-ID: <466D68F8.40403@tds.net>

Adam Urbas wrote:
> Where did you get this easygui thing you are trying to install.  Is it
> the thing that says Compiled Python File?  If so I have it.  I've
> kinda been following your little chat here about it.  I want to see if
> I could do it.

Google 'python easygui'

You probably want the .py file and the readme, not just the .pyc 
(compiled) file. Though it should work with just the .pyc file you won't 
have docs or the source to look at.

Kent

From chi at chimeric.de  Mon Jun 11 17:41:25 2007
From: chi at chimeric.de (Michael Klier)
Date: Mon, 11 Jun 2007 17:41:25 +0200
Subject: [Tutor] Off-Topic - Mutt and mailing lists
In-Reply-To: <20070611145215.GB8386@partex.co.uk>
References: <20070610163139.GD2538@shipdown.de> <f4hcka$chm$1@sea.gmane.org>
	<20070610191939.GE2538@shipdown.de> <f4i2av$bqd$1@sea.gmane.org>
	<20070611085839.GF2538@shipdown.de>
	<20070611145215.GB8386@partex.co.uk>
Message-ID: <20070611154125.GK2538@shipdown.de>

Simon Hooper wrote:
> Hi Michael,
> 
> * On 11/06/07, Michael Klier wrote:
> > Alan Gauld wrote:
> > > I'm not surecwhy but your messages are coming through to me 
> > > as text attachments which makes quoting them tricky...
> > 
> > Hmmm, I did a group reply in mutt the last time, lets see if a direct
> > reply and manuall CC: works right.
> 
> I don't know if you are aware, but mutt has a great list-reply command
> (bound to L by default) which "does the right thing" for mailing lists.
> Look up list-reply in the mutt manual.

Actually I wasn`t aware of "L", so thanks for the tip :D (mutt has a
monster of a manpage ;) I am not surprised I missed that). I always use
"r" which works with mailing lists that have the "Reply-To" header set
(I know that`s not preferred, and I understand why ;)). I think there
was a long thread about this topic a while ago on this list (could be
another one too, can`t rember that on top of my head). And, maybe I got
it wrong, I thought it would be preferred on this list to use the
senders mail in To: and CC: to the list?

Best Regards
Michael

-- 
Michael Klier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070611/3e793ed1/attachment.pgp 

From slewin at rogers.com  Mon Jun 11 22:01:42 2007
From: slewin at rogers.com (scott)
Date: Mon, 11 Jun 2007 16:01:42 -0400
Subject: [Tutor] Python IDE
Message-ID: <466DAA26.8030200@rogers.com>

Hi,

	I have been using Kdevelop so far to develop and a few bugs it inherits 
from Kate/Kwrite are really annoying me.  It does not collapse quotes 
properly and there are other graphical glitches as well.

	Could someone suggest a few good IDE's for me to look at.  I would need 
a IDE that haves syntax highlighting and I also really like type 
completion where the IDE gives you suggestions as you type.

	Extras like a good built in dictionary and anything else that makes 
coding faster or easier would be great.  I also prefer a IDE that is for 
multiple languages, but I am willing to use a IDE that is only Python 
for now until those bugs get fixed in Kdevelop.

	Lastly, I am a Linux user, so the IDE would need to run natively on 
Linux.  Thanks.


-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)

From nephish at gmail.com  Mon Jun 11 22:08:57 2007
From: nephish at gmail.com (shawn bright)
Date: Mon, 11 Jun 2007 15:08:57 -0500
Subject: [Tutor] Python IDE
In-Reply-To: <466DAA26.8030200@rogers.com>
References: <466DAA26.8030200@rogers.com>
Message-ID: <384c93600706111308r5076f42bq2c470c7babc13254@mail.gmail.com>

you can use gedit with some plugins that make it pretty much like an ide,
and its really fast.
another really cool one is JEdit. That is what i used before i switched to
vim to do everything.
runs on everything, has what you are looking for. Eclipse with PyDev is
cool, too. But a little heavy for me.

hth


On 6/11/07, scott <slewin at rogers.com> wrote:
>
> Hi,
>
>         I have been using Kdevelop so far to develop and a few bugs it
> inherits
> from Kate/Kwrite are really annoying me.  It does not collapse quotes
> properly and there are other graphical glitches as well.
>
>         Could someone suggest a few good IDE's for me to look at.  I would
> need
> a IDE that haves syntax highlighting and I also really like type
> completion where the IDE gives you suggestions as you type.
>
>         Extras like a good built in dictionary and anything else that
> makes
> coding faster or easier would be great.  I also prefer a IDE that is for
> multiple languages, but I am willing to use a IDE that is only Python
> for now until those bugs get fixed in Kdevelop.
>
>         Lastly, I am a Linux user, so the IDE would need to run natively
> on
> Linux.  Thanks.
>
>
> --
> Your friend,
> Scott
>
> Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
> _______________________________________________
> 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/20070611/43d25688/attachment.htm 

From chaosweevil42 at gmail.com  Mon Jun 11 22:38:26 2007
From: chaosweevil42 at gmail.com (Gordon)
Date: Mon, 11 Jun 2007 13:38:26 -0700
Subject: [Tutor] Python IDE
In-Reply-To: <466DAA26.8030200@rogers.com>
References: <466DAA26.8030200@rogers.com>
Message-ID: <466DB2C2.3020002@gmail.com>

Try Komodo Edit from ActiveState.  It's free (as in beer), it's 
cross-platform, and it's pretty darn good.  I haven't used it on Linux 
myself, but it does have a Linux download.

If being closed-source bothers you, Eclipse+PyDev might be your best option.

scott wrote:
> Hi,
>
> 	I have been using Kdevelop so far to develop and a few bugs it inherits 
> from Kate/Kwrite are really annoying me.  It does not collapse quotes 
> properly and there are other graphical glitches as well.
>
> 	Could someone suggest a few good IDE's for me to look at.  I would need 
> a IDE that haves syntax highlighting and I also really like type 
> completion where the IDE gives you suggestions as you type.
>
> 	Extras like a good built in dictionary and anything else that makes 
> coding faster or easier would be great.  I also prefer a IDE that is for 
> multiple languages, but I am willing to use a IDE that is only Python 
> for now until those bugs get fixed in Kdevelop.
>
> 	Lastly, I am a Linux user, so the IDE would need to run natively on 
> Linux.  Thanks.
>
>
>   


From alan.gauld at btinternet.com  Mon Jun 11 22:42:53 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 11 Jun 2007 21:42:53 +0100
Subject: [Tutor] Python IDE
References: <466DAA26.8030200@rogers.com>
Message-ID: <f4kc4i$n4m$1@sea.gmane.org>

"scott" <slewin at rogers.com> wrote

> Could someone suggest a few good IDE's for me to look at.

If you want to standardise on one environment that is industrial
strength and multi platform go for eclipse. its heavyweight
but does it all.

Not only is it open source IDE king but several commercial
companies are moving their in-house IDEs to it as well - Oracle,
Borland and IBM to name but three.

With pydev installed its pretty impressive, so far as I can tell
the only missing feature is a GUI builder!

> a IDE that haves syntax highlighting and I also really like type
> completion where the IDE gives you suggestions as you type.

Yep, Eclipse does both.

> Extras like a good built in dictionary

Not quite sure what you mean by that one.
Can you illustrate?

> coding faster or easier would be great.

It does folding, has a built in debugger and class browser.

> multiple languages, but I am willing to use a IDE
> that is only Python

It supports Java and C++ out of the box but there are
plug-ins for everything from SQL to UML and Lisp.

> Lastly, I am a Linux user, so the IDE would need to run natively on
> Linux.

It runs on most platforms so you can take your skills with you.

The only snag is that it is big asnd beefy and needs a powerful
box to run it well.

If you want something lighter then try SPE, or even Pythonwin.
I'm playing with wxPython's tools at the moment and ALa Mode
looks promising too. But ulitimately I'm a long term vim user
so tend to stick to the traditional Unix toolset personally...

HTH,

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



From andreas at kostyrka.org  Mon Jun 11 23:25:30 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Mon, 11 Jun 2007 23:25:30 +0200
Subject: [Tutor] Python IDE
In-Reply-To: <f4kc4i$n4m$1@sea.gmane.org>
References: <466DAA26.8030200@rogers.com> <f4kc4i$n4m$1@sea.gmane.org>
Message-ID: <466DBDCA.1060107@kostyrka.org>

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



Alan Gauld wrote:
> "scott" <slewin at rogers.com> wrote
> 
>> Could someone suggest a few good IDE's for me to look at.
> 
> If you want to standardise on one environment that is industrial
> strength and multi platform go for eclipse. its heavyweight
> but does it all.
> 
> Not only is it open source IDE king but several commercial
> companies are moving their in-house IDEs to it as well - Oracle,
> Borland and IBM to name but three.
> 
> With pydev installed its pretty impressive, so far as I can tell
> the only missing feature is a GUI builder!

Well, the Subversion support is painful. Dogslow. Eclipse is slow, but
the svn plugin that I've seen my colleagues use was IMHO (a Linux based
developer, emacs + commandline svk, who complains that svk is painful
slow *g*) unuseable for work.

(With unusable I mean, that I was able to branch trunk, fix some small
errors, run the unittests, merge the branch with svk while eclipse was
still running an "Update Workspace" command.)

Andreas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGbb3KHJdudm4KnO0RAkqDAJ4p0z+7KNm09jCgxp1CPnAI1AjatACfV0xn
Hn9Au6XYc/71zLRyBoEukGE=
=QzeR
-----END PGP SIGNATURE-----

From rob.andrews at gmail.com  Mon Jun 11 23:28:02 2007
From: rob.andrews at gmail.com (Rob Andrews)
Date: Mon, 11 Jun 2007 16:28:02 -0500
Subject: [Tutor] Python IDE
In-Reply-To: <466DAA26.8030200@rogers.com>
References: <466DAA26.8030200@rogers.com>
Message-ID: <8d757d2e0706111428p6793a029x5d48b84235aae2e9@mail.gmail.com>

Personally, I use and love Komodo (the full version, although Komodo
Edit is nice). I didn't *expect* to like it, but it won me over with
ease.

On 6/11/07, scott <slewin at rogers.com> wrote:
>        Could someone suggest a few good IDE's for me to look at.

From alan.gauld at btinternet.com  Tue Jun 12 01:48:22 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 12 Jun 2007 00:48:22 +0100
Subject: [Tutor] Python IDE
References: <466DAA26.8030200@rogers.com> <f4kc4i$n4m$1@sea.gmane.org>
	<466DBDCA.1060107@kostyrka.org>
Message-ID: <f4kn0b$pv6$1@sea.gmane.org>

"Andreas Kostyrka" <andreas at kostyrka.org> wrote in

> Well, the Subversion support is painful. Dogslow. Eclipse is slow, 
> but
> the svn plugin that I've seen my colleagues use was IMHO (a Linux 
> based
> developer, emacs + commandline svk, who complains that svk is 
> painful
> slow *g*) unuseable for work.

Haven't used it with subversion, in fact I've never used subversion!
(We use Borland tools at work)

But I did say eclipse was heavyweight and needed a big PC. :-)

My old laptop didn't like it at all and my 600MHz G3 iBook goes
to sleep with it. but my nice new 3GHz dual core with 2G Ram
seems perfectly happy running it. So if you have a PC with that
general kind of spec Eclipse is worth a try.

Alan G. 



From alan.gauld at btinternet.com  Tue Jun 12 01:50:12 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 12 Jun 2007 00:50:12 +0100
Subject: [Tutor] Python IDE
References: <466DAA26.8030200@rogers.com> <f4kc4i$n4m$1@sea.gmane.org>
Message-ID: <f4kn3p$q7r$1@sea.gmane.org>


"Alan Gauld" <alan.gauld at btinternet.com> wrote 

> It supports Java and C++ out of the box but there are

Actually C++ is a plug-in too, but free ones are available...

Alan G.



From jfabiani at yolo.com  Tue Jun 12 01:59:48 2007
From: jfabiani at yolo.com (johnf)
Date: Mon, 11 Jun 2007 16:59:48 -0700
Subject: [Tutor] Python IDE
In-Reply-To: <466DAA26.8030200@rogers.com>
References: <466DAA26.8030200@rogers.com>
Message-ID: <200706111659.48780.jfabiani@yolo.com>

On Monday 11 June 2007 13:01, scott wrote:
> Hi,
>
> 	I have been using Kdevelop so far to develop and a few bugs it inherits
> from Kate/Kwrite are really annoying me.  It does not collapse quotes
> properly and there are other graphical glitches as well.
>
> 	Could someone suggest a few good IDE's for me to look at.  I would need
> a IDE that haves syntax highlighting and I also really like type
> completion where the IDE gives you suggestions as you type.
>
> 	Extras like a good built in dictionary and anything else that makes
> coding faster or easier would be great.  I also prefer a IDE that is for
> multiple languages, but I am willing to use a IDE that is only Python
> for now until those bugs get fixed in Kdevelop.
>
> 	Lastly, I am a Linux user, so the IDE would need to run natively on
> Linux.  Thanks.
Others have suggested free IDE's.  But I like 'wing'.  Cost a little but works 
very well.
-- 
John Fabiani

From hokkakada at khmeros.info  Tue Jun 12 05:09:09 2007
From: hokkakada at khmeros.info (hok kakada)
Date: Tue, 12 Jun 2007 10:09:09 +0700
Subject: [Tutor] cannot pickle instancemethod objects
Message-ID: <200706121009.10756.hokkakada@khmeros.info>

Dear everyone,

I got a problem while pickling a class object. I have done something as below:
        pickleFile = open(filename, 'wb')
        pickle.dump(matcher, pickleFile)
        pickleFile.close()

where matcher is  class object and I got the follow errors:
Traceback (most recent call last):
  File "/usr/lib/python2.5/pickle.py", line 1362, in dump
    Pickler(file, protocol).dump(obj)
  File "/usr/lib/python2.5/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/lib/python2.5/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.5/pickle.py", line 725, in save_inst
    save(stuff)
  File "/usr/lib/python2.5/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.5/pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/usr/lib/python2.5/pickle.py", line 663, in _batch_setitems
    save(v)
  File "/usr/lib/python2.5/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.5/pickle.py", line 725, in save_inst
    save(stuff)
  File "/usr/lib/python2.5/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.5/pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "/usr/lib/python2.5/pickle.py", line 663, in _batch_setitems
    save(v)
  File "/usr/lib/python2.5/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle instancemethod objects

Does anybody please point me what could be a problem here?

Thanks very much for your help!
da

From preecha88 at gmail.com  Tue Jun 12 05:34:04 2007
From: preecha88 at gmail.com (Preecha Bundrikwong)
Date: Tue, 12 Jun 2007 10:34:04 +0700
Subject: [Tutor] Python IDE
In-Reply-To: <200706111659.48780.jfabiani@yolo.com>
References: <466DAA26.8030200@rogers.com>
	<200706111659.48780.jfabiani@yolo.com>
Message-ID: <30c6012b0706112034p314c70a0oe047313fc5901b62@mail.gmail.com>

Hi,

I'm supporting John's opinion. WingIDE rocks!! I use Linux at work, Windows
& Mac at home, I notice the Python editor on Windows also hints you the
syntax as you type.

Enjoy!
PB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070612/b8cc90e1/attachment.html 

From mailchansek at yahoo.com  Tue Jun 12 08:16:37 2007
From: mailchansek at yahoo.com (Chandrashekar)
Date: Mon, 11 Jun 2007 23:16:37 -0700 (PDT)
Subject: [Tutor] clarification on os.path.walk
Message-ID: <965688.79338.qm@web58709.mail.re1.yahoo.com>

Hi,

I have a program like this.

import os,os.path
import re

def print_files(arg,dir,files):
    '''print 'arg', arg
    print 'dir', dir
    print 'files',files'''
    for file in files:
        path = os.path.join(dir,file)
        path = os.path.normcase(path)
        if re.search(r".*\.txt",path):
            print path
 

os.path.walk('.',print_files,1)

My doubt is that what does the argument stand for in this program?
os.path.walk('.',print_files,0)
os.path.walk('.',print_files,1)
os.path.walk('.',print_files,2)

all seems to be rendering the same output. Can anyone clarify when this argument is used.

Thanks,
Chandru



 
---------------------------------
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070611/7cc119aa/attachment.html 

From rabidpoobear at gmail.com  Tue Jun 12 08:32:37 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 12 Jun 2007 01:32:37 -0500
Subject: [Tutor] clarification on os.path.walk
In-Reply-To: <965688.79338.qm@web58709.mail.re1.yahoo.com>
References: <965688.79338.qm@web58709.mail.re1.yahoo.com>
Message-ID: <466E3E05.2080801@gmail.com>

Chandrashekar wrote:
> Hi,
>
> I have a program like this.
>
> import os,os.path
> import re
>
> def print_files(arg,dir,files):
>     '''print 'arg', arg
>     print 'dir', dir
>     print 'files',files'''
>     for file in files:
>         path = os.path.join(dir,file)
>         path = os.path.normcase(path)
>         if re.search(r".*\.txt",path):
>             print path
>  
>
> os.path.walk('.',print_files,1)
>
> My doubt is that what does the argument stand for in this program?
> os.path.walk('.',print_files,0)
> os.path.walk('.',print_files,1)
> os.path.walk('.',print_files,2)
>
> all seems to be rendering the same output. Can anyone clarify when 
> this argument is used.
 >>> import os
 >>> help(os.path.walk)
Help on function walk in module ntpath:

walk(top, func, arg)
    Directory tree walk with callback function.
   
    For each directory in the directory tree rooted at top (including top
    itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
    dirname is the name of the directory, and fnames a list of the names of
    the files and subdirectories in dirname (excluding '.' and '..').  func
    may modify the fnames list in-place (e.g. via del or slice assignment),
    and walk will only recurse into the subdirectories whose names remain in
    fnames; this can be used to implement a filter, or to impose a specific
    order of visiting.  No semantics are defined for, or required of, arg,
    beyond that arg is always passed to func.  It can be used, e.g., to pass
    a filename pattern, or a mutable object designed to accumulate
    statistics.  Passing None for arg is common.


HTH,
-Luke

From alan.gauld at btinternet.com  Tue Jun 12 09:24:46 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 12 Jun 2007 08:24:46 +0100
Subject: [Tutor] clarification on os.path.walk
References: <965688.79338.qm@web58709.mail.re1.yahoo.com>
	<466E3E05.2080801@gmail.com>
Message-ID: <f4lho3$n5o$1@sea.gmane.org>

"Luke Paireepinart" <rabidpoobear at gmail.com> wrote
> Chandrashekar wrote:
>> I have a program like this.
>> def print_files(arg,dir,files):
>>     for file in files:
>>         path = os.path.join(dir,file)
>>         path = os.path.normcase(path)
>>         if re.search(r".*\.txt",path):
>>             print path

>> My doubt is that what does the argument stand for in this program?
>> os.path.walk('.',print_files,0)
>> os.path.walk('.',print_files,1)
>> os.path.walk('.',print_files,2)
>>
>> all seems to be rendering the same output. Can anyone clarify when
>> this argument is used.

> Help on function walk in module ntpath:
>
> walk(top, func, arg)
> .....
>    order of visiting.  No semantics are defined for, or required of, 
> arg,
>    beyond that arg is always passed to func.  It can be used, e.g., 
> to pass
>    a filename pattern, or a mutable object designed to accumulate
>    statistics.  Passing None for arg is common.

So, inapplying this to the OPs case, you pass the values of 0,1,2 in
but then never use them in your print_files function. You could have
used it to pass in the required extension like this:

def print_files(arg,dir,files):
     for file in files:
         path = os.path.join(dir,file)
         path = os.path.normcase(path)
         regex = r".*%s" % arg    # <--- Use arg to change the regex
         if re.search(regex, path):
             print path

And then called it with different values like:

os.path.walk('.',print_files,"\.txt")
os.path.walk('.',print_files,"\.py")
os.path.walk('.',print_files,"\.doc")

If you try that you should see a difference.

Personally I prefer using the slightly simpler os.walk() for
this kind of thing.

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 Jun 12 12:20:11 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 12 Jun 2007 06:20:11 -0400
Subject: [Tutor] cannot pickle instancemethod objects
In-Reply-To: <200706121009.10756.hokkakada@khmeros.info>
References: <200706121009.10756.hokkakada@khmeros.info>
Message-ID: <466E735B.8090808@tds.net>

hok kakada wrote:
> Dear everyone,
> 
> I got a problem while pickling a class object. I have done something as below:
>         pickleFile = open(filename, 'wb')
>         pickle.dump(matcher, pickleFile)
>         pickleFile.close()
> 
> where matcher is  class object and I got the follow errors:
> TypeError: can't pickle instancemethod objects

What kind of object is matcher? Does it have any attributes that are 
functions? (Not methods you defined for the class, but functions or 
methods that you assign to attributes of self.)

Kent

From andreas at kostyrka.org  Tue Jun 12 12:51:36 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Tue, 12 Jun 2007 12:51:36 +0200
Subject: [Tutor] cannot pickle instancemethod objects
In-Reply-To: <200706121009.10756.hokkakada@khmeros.info>
References: <200706121009.10756.hokkakada@khmeros.info>
Message-ID: <466E7AB8.2010903@kostyrka.org>

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

pickle is not capable of pickling class objects. Only instances of the
class.

Actually, pickle only records the name of the class an object belongs
to, so renaming or moving pickled classes means additional work, to map
old to new names.

Andreas

hok kakada wrote:
> Dear everyone,
> 
> I got a problem while pickling a class object. I have done something as below:
>         pickleFile = open(filename, 'wb')
>         pickle.dump(matcher, pickleFile)
>         pickleFile.close()
> 
> where matcher is  class object and I got the follow errors:
> Traceback (most recent call last):
>   File "/usr/lib/python2.5/pickle.py", line 1362, in dump
>     Pickler(file, protocol).dump(obj)
>   File "/usr/lib/python2.5/pickle.py", line 224, in dump
>     self.save(obj)
>   File "/usr/lib/python2.5/pickle.py", line 286, in save
>     f(self, obj) # Call unbound method with explicit self
>   File "/usr/lib/python2.5/pickle.py", line 725, in save_inst
>     save(stuff)
>   File "/usr/lib/python2.5/pickle.py", line 286, in save
>     f(self, obj) # Call unbound method with explicit self
>   File "/usr/lib/python2.5/pickle.py", line 649, in save_dict
>     self._batch_setitems(obj.iteritems())
>   File "/usr/lib/python2.5/pickle.py", line 663, in _batch_setitems
>     save(v)
>   File "/usr/lib/python2.5/pickle.py", line 286, in save
>     f(self, obj) # Call unbound method with explicit self
>   File "/usr/lib/python2.5/pickle.py", line 725, in save_inst
>     save(stuff)
>   File "/usr/lib/python2.5/pickle.py", line 286, in save
>     f(self, obj) # Call unbound method with explicit self
>   File "/usr/lib/python2.5/pickle.py", line 649, in save_dict
>     self._batch_setitems(obj.iteritems())
>   File "/usr/lib/python2.5/pickle.py", line 663, in _batch_setitems
>     save(v)
>   File "/usr/lib/python2.5/pickle.py", line 306, in save
>     rv = reduce(self.proto)
>   File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex
>     raise TypeError, "can't pickle %s objects" % base.__name__
> TypeError: can't pickle instancemethod objects
> 
> Does anybody please point me what could be a problem here?
> 
> Thanks very much for your help!
> da
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGbnq4HJdudm4KnO0RAstPAKCTAi8vAGak79KDNtJGqZFq27Hr7ACfeIFq
w5kcsggZZCnJDJWWk1bTOb8=
=aWNx
-----END PGP SIGNATURE-----

From vishnu at montalvosystems.com  Tue Jun 12 13:01:49 2007
From: vishnu at montalvosystems.com (Vishnu Mohan)
Date: Tue, 12 Jun 2007 16:31:49 +0530
Subject: [Tutor] Tutor Digest, Vol 40, Issue 25
In-Reply-To: <mailman.29048.1181497415.32030.tutor@python.org>
References: <mailman.29048.1181497415.32030.tutor@python.org>
Message-ID: <466E7D1D.7090404@montalvosystems.com>


>
> Message: 2
> Date: Sun, 10 Jun 2007 09:20:28 -0500
> From: David Hamilton <dsh0105 at comcast.net>
> Subject: [Tutor] Correct use of range function..
> To: tutor at python.org
> Message-ID: <466C08AC.2030201 at comcast.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> I just finished doing an exercise in a tutorial on the range function 
> and while I got it to work, my answer seems ugly. I'm wondering if I'm 
> missing something in the way I'm using the range function.
> The tutorial ask me to print a string backwards. My solution works, but 
> it it just doesn't "feel" right :).  My result is difficult to read and 
> I feel like I'm probably over complicating the solution. Suggestions?
>
> word="reverse"
> #Start at the end of the string, count back to the start, printing each 
> letter
> for  i in range(len(word)-1,-1,-1):
>     print word[i],
>
>   


Another best way of doing it is:

word = 'reverse'
rev    = ''
for i in range(len(word)):
     print word[-(i+1)]
     rev += word[-(i+1)]
print rev


    

From slewin at rogers.com  Tue Jun 12 14:23:13 2007
From: slewin at rogers.com (scott)
Date: Tue, 12 Jun 2007 08:23:13 -0400
Subject: [Tutor] Python IDE
In-Reply-To: <30c6012b0706112034p314c70a0oe047313fc5901b62@mail.gmail.com>
References: <466DAA26.8030200@rogers.com>	<200706111659.48780.jfabiani@yolo.com>
	<30c6012b0706112034p314c70a0oe047313fc5901b62@mail.gmail.com>
Message-ID: <466E9031.6010508@rogers.com>

Preecha Bundrikwong wrote:
> Hi,
> 
> I'm supporting John's opinion. WingIDE rocks!! I use Linux at work, 
> Windows & Mac at home, I notice the Python editor on Windows also hints 
> you the syntax as you type.

Thank you everyone for your help.  I'm going to try out eclipse because 
I have a newer computer that should not have any problem running it and 
many people seem to suggest it.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)

From mailinglistmatt at gmail.com  Tue Jun 12 15:00:57 2007
From: mailinglistmatt at gmail.com (Matt Erasmus)
Date: Tue, 12 Jun 2007 13:00:57 +0000
Subject: [Tutor] Python IDE
In-Reply-To: <466DAA26.8030200@rogers.com>
References: <466DAA26.8030200@rogers.com>
Message-ID: <ad53d62e0706120600u6fb22473t542ac5455b5d96ad@mail.gmail.com>

Check out geany. It's fairly simple but I've found it very neat and simple.

http://geany.uvena.de/

On 6/11/07, scott <slewin at rogers.com> wrote:

>         Could someone suggest a few good IDE's for me to look at.  I would
> need
> a IDE that haves syntax highlighting and I also really like type
> completion where the IDE gives you suggestions as you type.


-m
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070612/4751fd67/attachment.html 

From kent37 at tds.net  Wed Jun 13 14:09:26 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 13 Jun 2007 08:09:26 -0400
Subject: [Tutor] cannot pickle instancemethod objects
In-Reply-To: <200706131840.35440.hokkakada@khmeros.info>
References: <200706121009.10756.hokkakada@khmeros.info>
	<466E735B.8090808@tds.net>
	<200706131840.35440.hokkakada@khmeros.info>
Message-ID: <466FDE76.2030509@tds.net>

hok kakada wrote:

>> What kind of object is matcher? Does it have any attributes that are
>> functions? (Not methods you defined for the class, but functions or
>> methods that you assign to attributes of self.)

> Actually, I use the translate-toolkit from 
> http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/
> in translate/search/match.py:
>         if comparer is None:
>             comparer = lshtein.LevenshteinComparer(max_length)
 >         self.comparer = comparer

> I just found the problem that it is because of the LevenshteinComparer. Once I 
> assign self.comparer = None, the I can dump the matcher successfully.
> However, I still don't understand what could be wrong with 
> LevenshteinComparer. 

I think the problem is this code in LevenshteinComparer.__init__():

         if Levenshtein:
             self.distance = self.native_distance
         else:
             self.distance = self.python_distance

which assigns an instance method to an instance attribute; this is the 
instancemethod that can't be pickled.

Kent

PS Please use Reply All to reply to the list.

From jeffpeery at yahoo.com  Wed Jun 13 16:32:27 2007
From: jeffpeery at yahoo.com (Jeff Peery)
Date: Wed, 13 Jun 2007 07:32:27 -0700 (PDT)
Subject: [Tutor] locking files
Message-ID: <791760.11994.qm@web43145.mail.sp1.yahoo.com>

does anyone know if there is a way in python to lock a file so others cannot open it, or can only read it? I have a program that read/writes to a file and I would like to lock others out of it while I'm operating on it. 
   
  thanks.
   
  Jeff

 
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070613/65014019/attachment.htm 

From mi1492 at cox.net  Wed Jun 13 12:30:09 2007
From: mi1492 at cox.net (lucio arteaga)
Date: Wed, 13 Jun 2007 05:30:09 -0500
Subject: [Tutor] using zip
Message-ID: <000801c7ada5$d1c02c70$6400a8c0@bilbilis>

I am trying to learn using zip in combination of if statemeny. , If I do not make mistakes the program runs wll. Otherwise very bad?
Can any one help
Best wishes
Lucio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070613/e43edbbc/attachment.htm 

From mi1492 at cox.net  Wed Jun 13 15:54:28 2007
From: mi1492 at cox.net (lucio arteaga)
Date: Wed, 13 Jun 2007 08:54:28 -0500
Subject: [Tutor] using zip
Message-ID: <000f01c7adc2$5c299c40$6400a8c0@bilbilis>

I am trying to learn using zip in combination with if statements. , If I do not make mistakes the program runs wlel. Otherwise very bad?
Can anyone help
Best wishes
Lucio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070613/3f9c81c2/attachment.html 

From alan.gauld at btinternet.com  Wed Jun 13 18:23:26 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 13 Jun 2007 17:23:26 +0100
Subject: [Tutor] locking files
References: <791760.11994.qm@web43145.mail.sp1.yahoo.com>
Message-ID: <f4p5m4$fs8$1@sea.gmane.org>

"Jeff Peery" <jeffpeery at yahoo.com> wrote

> does anyone know if there is a way in python to lock 
> a file so others cannot open it, or can only read it? 

Thats normally controlled by your OS and the rules vary 
slightly between them. In general if you open a file for 
writing the OS should lock it against writing (and in 
some cases against reading too!). So if you want to 
lock an existing file while you read and write you could use 
a mode string of 'r+'. If you want to create a new locked 
file use 'w+''. BUT remember that its up to you to manage 
where the cursor is, otherwise you could wind up overwriting 
your data.

Another way to protect access, but less reliable, is 
to change the file permissions (using os.chmod()) 
at the start of the operation and change themback at 
the end. But that will only protect ahainst access by 
other users not against access by other programs that 
you might be running! Also you need to have 
permission to change permissions in the first place!

HTH,


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


From carloslara at web.de  Wed Jun 13 19:48:12 2007
From: carloslara at web.de (Carlos)
Date: Wed, 13 Jun 2007 19:48:12 +0200
Subject: [Tutor] Get max quantity
Message-ID: <46702DDC.8040804@web.de>

Hello,

If I have a dictionary like:

inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

How can I get the item with the largest quantity? I tried:

max(inventory)

but got:

'pears'

What I would like to get is 'oranges', at least in this case.

Thanks,
Carlos


From kent37 at tds.net  Wed Jun 13 20:20:09 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 13 Jun 2007 14:20:09 -0400
Subject: [Tutor] Get max quantity
In-Reply-To: <46702DDC.8040804@web.de>
References: <46702DDC.8040804@web.de>
Message-ID: <46703559.9080103@tds.net>

Carlos wrote:
> Hello,
> 
> If I have a dictionary like:
> 
> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
> 
> How can I get the item with the largest quantity? I tried:
> 
> max(inventory)
> 
> but got:
> 
> 'pears'
> 
> What I would like to get is 'oranges', at least in this case.

In Python 2.5, you can use the key= parameter to max:
In [3]: inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 
'pears': 217}
In [4]: max(inventory, key=inventory.__getitem__)
Out[4]: 'oranges'

In older Pythons, convert the dict to a list of (value, key) pairs and 
find the max of that:

In [5]: max((value, key) for key, value in inventory.iteritems())[1]
Out[5]: 'oranges'

Kent

From jason.massey at gmail.com  Wed Jun 13 20:27:58 2007
From: jason.massey at gmail.com (Jason Massey)
Date: Wed, 13 Jun 2007 13:27:58 -0500
Subject: [Tutor] Get max quantity
In-Reply-To: <46702DDC.8040804@web.de>
References: <46702DDC.8040804@web.de>
Message-ID: <7e3eab2c0706131127ua42bb22kb269a1054ead3fe2@mail.gmail.com>

More than one way to skin a cat:

>>> import operator
>>> sort_key = operator.itemgetter(1)
>>> sorted(inventory.items(),key=sort_key)[-1]
('oranges',525)

or...

>>> inventory.items()
[('pears', 217), ('apples', 430), ('oranges', 525), ('bananas', 312)]
>>> count_first = [(count,fruit) for fruit,count in inventory.items()]
>>> count_first
[(217, 'pears'), (430, 'apples'), (525, 'oranges'), (312, 'bananas')]
>>> max(count_first)
(525, 'oranges')

And then of course you could iterate over the dictionary setting up
variables that hold the highest fruit and count found so far.



On 6/13/07, Carlos <carloslara at web.de> wrote:
>
> Hello,
>
> If I have a dictionary like:
>
> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
>
> How can I get the item with the largest quantity? I tried:
>
> max(inventory)
>
> but got:
>
> 'pears'
>
> What I would like to get is 'oranges', at least in this case.
>
> Thanks,
> Carlos
>
> _______________________________________________
> 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/20070613/8479aa28/attachment.htm 

From brian.wisti at gmail.com  Wed Jun 13 20:34:11 2007
From: brian.wisti at gmail.com (Brian Wisti)
Date: Wed, 13 Jun 2007 11:34:11 -0700
Subject: [Tutor] Get max quantity
In-Reply-To: <46702DDC.8040804@web.de>
References: <46702DDC.8040804@web.de>
Message-ID: <d5506a9f0706131134v510d526bsf0556cc03519e9ef@mail.gmail.com>

Hi Carlos,

On 6/13/07, Carlos <carloslara at web.de> wrote:
> Hello,
>
> If I have a dictionary like:
>
> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
>
> How can I get the item with the largest quantity? I tried:
>
> max(inventory)
>
> but got:
>
> 'pears'
>
> What I would like to get is 'oranges', at least in this case.
>
> Thanks,
> Carlos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

There are indeed several ways to sort this particular cat. Here's my
own favorite:

# Sort the list of keys by inventory count, from high to low
>>> inventory
{'pears': 217, 'apples': 430, 'oranges': 525, 'bananas': 312}
>>> items = inventory.keys()
>>> items
['pears', 'apples', 'oranges', 'bananas']
>>> items.sort(cmp=lambda a,b: cmp(inventory[b], inventory[a]))
>>> items
['oranges', 'apples', 'bananas', 'pears']
>>> items[0]
'oranges'

It does result in another list, same as the the approaches listed by
Kent and Jason. If *all* you were interested was the key associated
with the greatest inventory count, you could wrap your favorite
solution in a function and return the key from that.

Kind Regards,

Brian Wisti
http://coolnamehere.com/

From alan.gauld at btinternet.com  Wed Jun 13 22:08:36 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 13 Jun 2007 21:08:36 +0100
Subject: [Tutor] wxPython GUI builders?
Message-ID: <f4pisa$4bi$1@sea.gmane.org>

What's available and in what state of readiness?

I tried Boa Constructor but after half a dozen code tweaks 
I was still running into compatibility errors with the latest 
wxPython and gave up. 

I know that Glade is out there, but what state is it in?
And PythonCard offers another approach but I haven't 
looked at it for about 3 years.

Are there any others? And which ones do people 
actually use? Commercial or Freeware.

Alan G.


From clsdaniel at gmail.com  Thu Jun 14 00:45:55 2007
From: clsdaniel at gmail.com (Carlos Daniel Ruvalcaba Valenzuela)
Date: Wed, 13 Jun 2007 15:45:55 -0700
Subject: [Tutor] wxPython GUI builders?
In-Reply-To: <f4pisa$4bi$1@sea.gmane.org>
References: <f4pisa$4bi$1@sea.gmane.org>
Message-ID: <4fae7dfa0706131545u5b4c1c78vcad25f1ab4d76b2e@mail.gmail.com>

wxGlade is a good GUI builder, very much like Glade, however it may o
may not integrate with your coding style but you should definitively
give it a try.

PythonCard is a nice concept I personally do something similar but
with XML, parse and build the GUI from it, then tweak the layout
manually, with PythonCard this is easier to do since it has a resource
editor.

Personally I would like an IDE + wxPython GUI editor integrated, that
would help a lot, I'm starting to work on that myself.

Good luck!

On 6/13/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
> What's available and in what state of readiness?
>
> I tried Boa Constructor but after half a dozen code tweaks
> I was still running into compatibility errors with the latest
> wxPython and gave up.
>
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't
> looked at it for about 3 years.
>
> Are there any others? And which ones do people
> actually use? Commercial or Freeware.
>
> Alan G.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From rdm at rcblue.com  Thu Jun 14 00:58:37 2007
From: rdm at rcblue.com (Dick Moores)
Date: Wed, 13 Jun 2007 15:58:37 -0700
Subject: [Tutor] wxPython GUI builders?
In-Reply-To: <f4pisa$4bi$1@sea.gmane.org>
References: <f4pisa$4bi$1@sea.gmane.org>
Message-ID: <20070613225843.3C0431E4002@bag.python.org>

At 01:08 PM 6/13/2007, Alan Gauld wrote:
>What's available and in what state of readiness?

I don't have the details you want, but you might look at SPE. 
<http://pythonide.blogspot.com/>

Dick Moores



From spmcinerney at hotmail.com  Thu Jun 14 01:48:42 2007
From: spmcinerney at hotmail.com (Stephen McInerney)
Date: Wed, 13 Jun 2007 16:48:42 -0700
Subject: [Tutor] Table of replacements for deprecated fns from 'string'
	module?
Message-ID: <BAY111-F16CE77DCF4D5910E0A56A8A0180@phx.gbl>

Hi,

Where is there a table of replacements for the deprecated 'string' fns
esp. the basic common ones e.g. string.split(), join(), replace(), find(), 
index() ?
http://docs.python.org/lib/node42.html

Are we supposed to use 're' fns even for very simple operations?
that seems like way overkill.
This stuff is badly covered by the docpages.

(the deprecated fns from 'string' module will finally go away in Python 3.0)

Thanks,
Stephen

[This is a repost - I had to resubscribe to the list]

_________________________________________________________________
Get a preview of Live Earth, the hottest event this summer - only on MSN 
http://liveearth.msn.com?source=msntaglineliveearthhm


From john at fouhy.net  Thu Jun 14 02:03:00 2007
From: john at fouhy.net (John Fouhy)
Date: Thu, 14 Jun 2007 12:03:00 +1200
Subject: [Tutor] Table of replacements for deprecated fns from 'string'
	module?
In-Reply-To: <BAY111-F16CE77DCF4D5910E0A56A8A0180@phx.gbl>
References: <BAY111-F16CE77DCF4D5910E0A56A8A0180@phx.gbl>
Message-ID: <5e58f2e40706131703k324a1574k6d0c421eaabe078@mail.gmail.com>

On 14/06/07, Stephen McInerney <spmcinerney at hotmail.com> wrote:
> Where is there a table of replacements for the deprecated 'string' fns
> esp. the basic common ones e.g. string.split(), join(), replace(), find(),
> index() ?
> http://docs.python.org/lib/node42.html

They've basically all moved into the string type.

e.g. instead of typing "string.split(foo, sep)", you would now type
"foo.split(sep)".

Hence the leading comment on the page you cite: "The following list of
functions are also defined as methods of string and Unicode objects;
see ``String Methods'' (section 3.6.1) for more information on those.
"

-- 
John.

From keridee at jayco.net  Wed Jun 13 22:53:46 2007
From: keridee at jayco.net (Jacob S.)
Date: Wed, 13 Jun 2007 20:53:46 -0000
Subject: [Tutor]  capwords, maketrans
Message-ID: <000b01c7adfc$f2b8a720$4cfce004@JSLAPTOP>

Hi guys.
    I was just wondering what's going to happen to capwords and maketrans
when the string module is finally terminated. Is python just not going to
support those to functions anymore? Or are they going to suddenly be
implemented as string methods at the last minute? Or are they on the list to
be phased out because no one uses them? Lack of use? Just wondering.


From john at fouhy.net  Thu Jun 14 03:30:42 2007
From: john at fouhy.net (John Fouhy)
Date: Thu, 14 Jun 2007 13:30:42 +1200
Subject: [Tutor] capwords, maketrans
In-Reply-To: <000b01c7adfc$f2b8a720$4cfce004@JSLAPTOP>
References: <000b01c7adfc$f2b8a720$4cfce004@JSLAPTOP>
Message-ID: <5e58f2e40706131830o24cbacbapc98ee59f2bbd035b@mail.gmail.com>

On 14/06/07, Jacob S. <keridee at jayco.net> wrote:
> Hi guys.
>     I was just wondering what's going to happen to capwords and maketrans
> when the string module is finally terminated.

As far as I know, the string module as a whole is not going away.  In
particular, the string module supplies various constants that are
quite useful.  Only those string functions that exist as string
methods (and are on the deprecated list) will eventually die.

-- 
John.

From ranpra at gmail.com  Thu Jun 14 07:10:34 2007
From: ranpra at gmail.com (Pradeep Kumar)
Date: Thu, 14 Jun 2007 09:10:34 +0400
Subject: [Tutor] Componentone - TrueDBGrid Control
Message-ID: <76b198110706132210y32b5d7d5pe85f03ccc87d8577@mail.gmail.com>

Hi,

Is wxPython have Componentone Trudbgrid like control. If yes,
Please inform. if No, how we can made one.

Pradeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070614/97e5fde2/attachment.html 

From spmcinerney at hotmail.com  Thu Jun 14 08:52:16 2007
From: spmcinerney at hotmail.com (Stephen McInerney)
Date: Wed, 13 Jun 2007 23:52:16 -0700
Subject: [Tutor] capwords, maketrans
In-Reply-To: <5e58f2e40706131830o24cbacbapc98ee59f2bbd035b@mail.gmail.com>
Message-ID: <BAY111-F8DDA850745D9193C07DBFA01F0@phx.gbl>

Ok thanks all.

The doucmentation is confusing on that point.
Also when it refers to the methods becoming methods
of string objects a link would be nice.

Regards,
Stephen



>From: "John Fouhy" <john at fouhy.net>
>To: "Jacob S." <keridee at jayco.net>
>CC: tutor at python.org
>Subject: Re: [Tutor] capwords, maketrans
>Date: Thu, 14 Jun 2007 13:30:42 +1200
>
>On 14/06/07, Jacob S. <keridee at jayco.net> wrote:
> > Hi guys.
> >     I was just wondering what's going to happen to capwords and 
>maketrans
> > when the string module is finally terminated.
>
>As far as I know, the string module as a whole is not going away.  In
>particular, the string module supplies various constants that are
>quite useful.  Only those string functions that exist as string
>methods (and are on the deprecated list) will eventually die.
>
>--
>John.
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Hotmail to go? Get your Hotmail, news, sports and much more! 
http://mobile.msn.com


From alan.gauld at btinternet.com  Thu Jun 14 09:43:47 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 14 Jun 2007 08:43:47 +0100
Subject: [Tutor] Table of replacements for deprecated fns from
	'string'module?
References: <BAY111-F16CE77DCF4D5910E0A56A8A0180@phx.gbl>
Message-ID: <f4qrjk$fo4$1@sea.gmane.org>


"Stephen McInerney" <spmcinerney at hotmail.com> wrote

> Where is there a table of replacements for the deprecated 'string' 
> fns

I'm not sure exactly what you are after but comparing these lists 
might help:

import string
dir(string)
['Template', '_TemplateMetaclass', '__builtins__', '__doc__', 
'__file__', '__name__', '_float', '_idmap', '_idmapL', '_int', 
'_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 
'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 
'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 
'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 
'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 
'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 
'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 
'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 
'whitespace', 'zfill']

dir('')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', 
'__eq__', '__ge__', '__getattribute__', '__getitem__', 
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', 
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', 
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 
'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 
'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 
'zfill']

Notice the long list of predicate methods that largely replace the
idiom of looking for a match in the string constants. ie instead of:

if char in string.lowercase:

you can use

if char.islower():

The only missing function I can see is maketrans().
(capwords seems to be replaced with title, and the type
conversions are now in their type objects)

The list of predicates is not complete however.

But of course the string objects add a number of extra methods
too. (eg startwith, endswith, and a bunch of operators etc)

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 Jun 14 09:50:33 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 14 Jun 2007 08:50:33 +0100
Subject: [Tutor] Componentone - TrueDBGrid Control
References: <76b198110706132210y32b5d7d5pe85f03ccc87d8577@mail.gmail.com>
Message-ID: <f4qs09$h1r$1@sea.gmane.org>

"Pradeep Kumar" <ranpra at gmail.com> wrote 

> Is wxPython have Componentone Trudbgrid like control. If yes,
> Please inform. if No, how we can made one.

I've no idea what a Trudbgrid is but assuming it's a bit like 
the live data grids used in Delphi then the answer is no, 
not as far as I can tell. However is an approximation in 
the form of a wx.grid.PyGridTableBase which you can 
subclass to connect to a database and then connect 
to a grid object using grid.SetTable()

Probably better asking on the wxPython mailing list 
though, they are more expert in wxPython matters.

HTH,

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


From emilia12 at mail.bg  Thu Jun 14 12:14:13 2007
From: emilia12 at mail.bg (emilia12 at mail.bg)
Date: Thu, 14 Jun 2007 13:14:13 +0300
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <mailman.29516.1181765640.32030.tutor@python.org>
References: <mailman.29516.1181765640.32030.tutor@python.org>
Message-ID: <1181816053.e051f8f93c8aa@mail.bg>

hi list,

how to choose between "#!/usr/bin/env python" and
"#!/usr/local/bin/python" in the beginning of the script ?
e.



-----------------------------

SCENA - ???????????? ????????? ???????? ?? ??????? ??????????? ? ??????????.
http://www.bgscena.com/


From thorsten at thorstenkampe.de  Thu Jun 14 12:29:04 2007
From: thorsten at thorstenkampe.de (Thorsten Kampe)
Date: Thu, 14 Jun 2007 11:29:04 +0100
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
Message-ID: <f4r59h$h10$1@sea.gmane.org>

*  (Thu, 14 Jun 2007 13:14:13 +0300)
> how to choose between "#!/usr/bin/env python" and
> "#!/usr/local/bin/python" in the beginning of the script ?

Just choose. Say "I want" to the script. Say "I want '#!/usr/bin/env 
python'"


From Andy.cheesman at bristol.ac.uk  Thu Jun 14 13:24:15 2007
From: Andy.cheesman at bristol.ac.uk (Andy Cheesman)
Date: Thu, 14 Jun 2007 12:24:15 +0100
Subject: [Tutor] Automatic generation of an "all possible combinations" array
Message-ID: <4671255F.9080808@bristol.ac.uk>

Hi people

I am trying to generate an array of all possible combinations of 1, and
zeros (see example data) for a rather nice Kinetic mote Carlo program
which I am writing python. So far, I've been working out for
combinations for 4 or less species by hand as it is quick! but I am
looking to automate the process so I can compute combinations for large
  numbers of possible species.
I could automate the generation of the array by the use of multiple
loops but that doesn't seem rather pythonic. I was wondering if anyone
had any sensible suggestions or pointers for efficient mechanisms for
the array.

Many Thanks
Andy

Example Data
3 species
array([[1, 1, 1],
       [1, 1, 0],
       [1, 0, 1],
       [0, 1, 1],
       [1, 0, 0],
       [0, 1, 0],
       [0, 0, 1],
       [0, 0, 0]])
4 species
array([[1, 1, 1, 1],
       [0, 1, 1, 1],
       [1, 0, 1, 1],
       [1, 1, 0, 1],
       [1, 1, 1, 0],
       [1, 1, 0, 0],
       [1, 0, 1, 0],
       [1, 0, 0, 1],
       [0, 1, 1, 0],
       [0, 1, 0, 1],
       [0, 0, 1, 1],
       [1, 0, 0, 0],
       [0, 1, 0, 0],
       [0, 0, 1, 0],
       [0, 0, 0, 1],
       [0, 0, 0, 0]])


From hyoogle at gmail.com  Thu Jun 14 15:06:39 2007
From: hyoogle at gmail.com (Hugh M)
Date: Thu, 14 Jun 2007 09:06:39 -0400
Subject: [Tutor] Automatic generation of an "all possible combinations"
	array
In-Reply-To: <4671255F.9080808@bristol.ac.uk>
References: <4671255F.9080808@bristol.ac.uk>
Message-ID: <f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>

The 2**n different lists that you are seeking have a direct association to
the binary representation of the integers 0 through (2**n)-1.
You can use this fact and the "repeated division method" for converting
numbers between different bases to generate these lists and form the desired
list of lists:

def bit_list_maker(n):
    x = 2**n
    solution_set = []
    for i in range(x):
        this_answer = []
        while i>0:
            this_answer.append(i%2)
            i=i/2
        while len(this_answer)<n:
            this_answer.append(0)
        this_answer.reverse()
        solution_set.append(this_answer)
    return solution_set
*
*
Another fun way to do it is to build up the lists recursively.  The
possibilities for n bits can be built from the possibilities for n-1 bits by
adding a 1 and a 0 to each possibility (ending up with twice as many
elements):

def recursive_bit_list(n):
    if n==1:
        return [[0],[1]]
    else:
        return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
               map(lambda x: x+[1], recursive_bit_list(n-1))

Hope this helps!

-Hugh


On 6/14/07, Andy Cheesman <Andy.cheesman at bristol.ac.uk > wrote:
>
> Hi people
>
> I am trying to generate an array of all possible combinations of 1, and
> zeros (see example data) for a rather nice Kinetic mote Carlo program
> which I am writing python. So far, I've been working out for
> combinations for 4 or less species by hand as it is quick! but I am
> looking to automate the process so I can compute combinations for large
>   numbers of possible species.
> I could automate the generation of the array by the use of multiple
> loops but that doesn't seem rather pythonic. I was wondering if anyone
> had any sensible suggestions or pointers for efficient mechanisms for
> the array.
>
> Many Thanks
> Andy
>
> Example Data
> 3 species
> array([[1, 1, 1],
>        [1, 1, 0],
>        [1, 0, 1],
>        [0, 1, 1],
>        [1, 0, 0],
>        [0, 1, 0],
>        [0, 0, 1],
>        [0, 0, 0]])
> 4 species
> array([[1, 1, 1, 1],
>        [0, 1, 1, 1],
>        [1, 0, 1, 1],
>        [1, 1, 0, 1],
>        [1, 1, 1, 0],
>        [1, 1, 0, 0],
>        [1, 0, 1, 0],
>        [1, 0, 0, 1],
>        [0, 1, 1, 0],
>        [0, 1, 0, 1],
>        [0, 0, 1, 1],
>        [1, 0, 0, 0],
>        [0, 1, 0, 0],
>        [0, 0, 1, 0],
>        [0, 0, 0, 1],
>        [0, 0, 0, 0]])
>
> _______________________________________________
> 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/20070614/656db952/attachment.htm 

From ezra.taylor at gmail.com  Thu Jun 14 15:58:33 2007
From: ezra.taylor at gmail.com (Ezra Taylor)
Date: Thu, 14 Jun 2007 09:58:33 -0400
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <1181816053.e051f8f93c8aa@mail.bg>
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
Message-ID: <eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>

I think Emilia means what's the difference.  From what little I know,
#!/usr/bin/env python will choose the first python that's in your path.
Were as the second option, you explicitly choose which instance of python
you want.  I'm using using python from Activestate.  So my shebang is to the
Activestate directory for python.  If I'm wrong, please correct.

Ezra

On 6/14/07, emilia12 at mail.bg <emilia12 at mail.bg> wrote:
>
> hi list,
>
> how to choose between "#!/usr/bin/env python" and
> "#!/usr/local/bin/python" in the beginning of the script ?
> e.
>
>
>
> -----------------------------
>
> SCENA - ???????????? ????????? ???????? ?? ??????? ??????????? ?
> ??????????.
> http://www.bgscena.com/
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Ezra Taylor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070614/27b4b957/attachment.html 

From lnhaig at gmail.com  Thu Jun 14 16:05:11 2007
From: lnhaig at gmail.com (Lance Haig)
Date: Thu, 14 Jun 2007 15:05:11 +0100
Subject: [Tutor] Certificate creation.
Message-ID: <46714B17.7030601@gmail.com>

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

Hi All,

Is there a way to create ssl certificates with python and GNUTLS?

I am part of a project http://www.bongo-project.org which is a mail and
calendering solution. We use python in our project to a large extent but
we have a problem with the ssl key generation using GNUTLS.

Some machines take days to create enough random data to create the
certificates because they are headless and don't have key input for us
to capture.

We currently use a python script to run our set-up program and this in
turn creates the certificates.

Is there another way to create certificates from a python script that
will speed things up for these types of machines?

I would appreciate any help on this thanks

Regards

Lance
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFGcUsXOw09RVRgt9wRAgfkAJ993ha5e38OS5YAc0xAaDg7GMGxRgCgnfCR
j6oeFdWInj4xp2fIloiQxfM=
=TlaD
-----END PGP SIGNATURE-----

From vishnu at montalvosystems.com  Thu Jun 14 16:05:52 2007
From: vishnu at montalvosystems.com (Vishnu Mohan)
Date: Thu, 14 Jun 2007 19:35:52 +0530
Subject: [Tutor] locking files
In-Reply-To: <f4p5m4$fs8$1@sea.gmane.org>
References: <791760.11994.qm@web43145.mail.sp1.yahoo.com>
	<f4p5m4$fs8$1@sea.gmane.org>
Message-ID: <46714B40.9070600@montalvosystems.com>

You can look into the flock or lockf  methods in fcntl module
(or)
the following link will help you

http://www.python.org/doc/2.4/lib/module-fcntl.html

VishnuMohan


Alan Gauld wrote:
> "Jeff Peery" <jeffpeery at yahoo.com> wrote
>
>   
>> does anyone know if there is a way in python to lock 
>> a file so others cannot open it, or can only read it? 
>>     
>
> Thats normally controlled by your OS and the rules vary 
> slightly between them. In general if you open a file for 
> writing the OS should lock it against writing (and in 
> some cases against reading too!). So if you want to 
> lock an existing file while you read and write you could use 
> a mode string of 'r+'. If you want to create a new locked 
> file use 'w+''. BUT remember that its up to you to manage 
> where the cursor is, otherwise you could wind up overwriting 
> your data.
>
> Another way to protect access, but less reliable, is 
> to change the file permissions (using os.chmod()) 
> at the start of the operation and change themback at 
> the end. But that will only protect ahainst access by 
> other users not against access by other programs that 
> you might be running! Also you need to have 
> permission to change permissions in the first place!
>
> HTH,
>
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070614/c452127a/attachment-0001.htm 

From davdunc at gmail.com  Thu Jun 14 16:14:26 2007
From: davdunc at gmail.com (David Duncan)
Date: Thu, 14 Jun 2007 09:14:26 -0500
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
	<eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>
Message-ID: <3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>

On 6/14/07, Ezra Taylor <ezra.taylor at gmail.com> wrote:
>
> I think Emilia means what's the difference.  From what little I know,
> #!/usr/bin/env python will choose the first python that's in your path.
> Were as the second option, you explicitly choose which instance of python
> you want.  I'm using using python from Activestate.  So my shebang is to the
> Activestate directory for python.  If I'm wrong, please correct.
>
> Ezra
>
> On 6/14/07, emilia12 at mail.bg <emilia12 at mail.bg> wrote:
> >
> > hi list,
> >
> > how to choose between "#!/usr/bin/env python" and
> > "#!/usr/local/bin/python" in the beginning of the script ?
> > e.
> >
> >
> >
> > -----------------------------
> >
> > SCENA - ???????????? ????????? ???????? ?? ??????? ??????????? ?
> > ??????????.
> > http://www.bgscena.com/
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Ezra Taylor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
The real difference here is that by using the "env"  command, you have the
option to input many different settings preferences before calling the
python of your choice.  The statement above, is a very simple choice of the
python based upon the current environment, but it could be augmented very
easily.

I suggest that you check out the man page for the command "env".

-- 
David Duncan

Registered Linux User #279425
http://counter.li.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070614/0cbf69c5/attachment.html 

From Senthil_OR at Dell.com  Thu Jun 14 16:35:01 2007
From: Senthil_OR at Dell.com (Senthil_OR at Dell.com)
Date: Thu, 14 Jun 2007 20:05:01 +0530
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>
References: <mailman.29516.1181765640.32030.tutor@python.org><1181816053.e051f8f93c8aa@mail.bg><eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>
	<3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>
Message-ID: <D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>

Okay, I guess, people are missing points here. 
 
When do you
 
#!/usr/local/bin/python
You are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with.
You are pointing to python is located at /usr/local/bin/python
 
Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, the above #! will fail.
For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly.
 
Thus,
#/usr/bin/env python
Will figure out the correct location of python ( /usr/bin/python or /bin/python from $PATH) and make that as the interpreter for rest of the script.
- ( env is almost always located in /usr/bin/ so one need not worry what is env is not present at /usr/bin)
 
Hope this helps.
 
-- 
Senthil


The price of seeking to force our beliefs on others is that someday they might force their beliefs on us. -- Mario Cuomo 
 

________________________________

From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf Of David Duncan
Sent: Thursday, June 14, 2007 19:44
To: tutor at python.org
Subject: Re: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"




On 6/14/07, Ezra Taylor <ezra.taylor at gmail.com> wrote: 

	I think Emilia means what's the difference.  From what little I know, #!/usr/bin/env python will choose the first python that's in your path.  Were as the second option, you explicitly choose which instance of python you want.  I'm using using python from Activestate.  So my shebang is to the Activestate directory for python.  If I'm wrong, please correct. 
	
	Ezra 
	
	
	
	On 6/14/07, emilia12 at mail.bg <emilia12 at mail.bg> wrote: 

		hi list,
		
		how to choose between "#!/usr/bin/env python" and
		"#!/usr/local/bin/python" in the beginning of the script ? 
		e.
		
		
		
		-----------------------------
		
		SCENA - ???????????? ????????? ???????? ?? ??????? ??????????? ? ??????????.
		http://www.bgscena.com/
		
		_______________________________________________ 
		Tutor maillist  -  Tutor at python.org
		http://mail.python.org/mailman/listinfo/tutor
		




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


The real difference here is that by using the "env"  command, you have the option to input many different settings preferences before calling the python of your choice.  The statement above, is a very simple choice of the python based upon the current environment, but it could be augmented very easily. 

I suggest that you check out the man page for the command "env".  

-- 
David Duncan

Registered Linux User #279425
http://counter.li.org 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070614/fd34f72c/attachment.htm 

From vishnu at montalvosystems.com  Thu Jun 14 17:51:22 2007
From: vishnu at montalvosystems.com (Vishnu Mohan)
Date: Thu, 14 Jun 2007 21:21:22 +0530
Subject: [Tutor] Automatic generation of an "all possible combinations"
 array
In-Reply-To: <f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
References: <4671255F.9080808@bristol.ac.uk>
	<f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
Message-ID: <467163FA.3040704@montalvosystems.com>

Another simplest way of doing it  is

 >>>
from random import *
from sys import *

def bin_list(n):
    bin_val = 0
    if n >= 0:
        bin_val = 2**n - 1
    list = []
    while bin_val >= 0:
        list.append([((bin_val >> y) & 1) for y in range(n-1,-1,-1)])
        bin_val -= 1
    shuffle(list)
    return list
 >>>
bin_list(3) gives output as
   [ [0, 1],
     [1, 1],
     [0, 0],
     [1, 0] ]
Output list of patterns is random, we get different patterns for next run.

-VishnuMohan



Hugh M wrote:
> The 2**n different lists that you are seeking have a direct 
> association to the binary representation of the integers 0 through 
> (2**n)-1.
>
> You can use this fact and the "repeated division method" for 
> converting numbers between different bases to generate these lists and 
> form the desired list of lists:
>
> def bit_list_maker(n):
>     x = 2**n
>     solution_set = []
>     for i in range(x):
>         this_answer = []
>         while i>0:
>             this_answer.append(i%2)
>             i=i/2
>         while len(this_answer)<n:
>             this_answer.append(0)
>         this_answer.reverse()
>         solution_set.append(this_answer)
>     return solution_set
> *
> *
> Another fun way to do it is to build up the lists recursively.  The 
> possibilities for n bits can be built from the possibilities for n-1 
> bits by adding a 1 and a 0 to each possibility (ending up with twice 
> as many elements):
>
> def recursive_bit_list(n):
>     if n==1:
>         return [[0],[1]]
>     else:
>         return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
>                map(lambda x: x+[1], recursive_bit_list(n-1))
>
> Hope this helps!
>
> -Hugh
>
>  
> On 6/14/07, *Andy Cheesman* <Andy.cheesman at bristol.ac.uk 
> <mailto:Andy.cheesman at bristol.ac.uk>> wrote:
>
>     Hi people
>
>     I am trying to generate an array of all possible combinations of
>     1, and
>     zeros (see example data) for a rather nice Kinetic mote Carlo program
>     which I am writing python. So far, I've been working out for
>     combinations for 4 or less species by hand as it is quick! but I am
>     looking to automate the process so I can compute combinations for
>     large
>       numbers of possible species.
>     I could automate the generation of the array by the use of multiple
>     loops but that doesn't seem rather pythonic. I was wondering if anyone
>     had any sensible suggestions or pointers for efficient mechanisms for
>     the array.
>
>     Many Thanks
>     Andy
>
>     Example Data
>     3 species
>     array([[1, 1, 1],
>            [1, 1, 0],
>            [1, 0, 1],
>            [0, 1, 1],
>            [1, 0, 0],
>            [0, 1, 0],
>            [0, 0, 1],
>            [0, 0, 0]])
>     4 species
>     array([[1, 1, 1, 1],
>            [0, 1, 1, 1],
>            [1, 0, 1, 1],
>            [1, 1, 0, 1],
>            [1, 1, 1, 0],
>            [1, 1, 0, 0],
>            [1, 0, 1, 0],
>            [1, 0, 0, 1],
>            [0, 1, 1, 0],
>            [0, 1, 0, 1],
>            [0, 0, 1, 1],
>            [1, 0, 0, 0],
>            [0, 1, 0, 0],
>            [0, 0, 1, 0],
>            [0, 0, 0, 1],
>            [0, 0, 0, 0]])
>
>     _______________________________________________
>     Tutor maillist  -   Tutor at python.org <mailto: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 wescpy at gmail.com  Thu Jun 14 20:13:07 2007
From: wescpy at gmail.com (wesley chun)
Date: Thu, 14 Jun 2007 11:13:07 -0700
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
	<eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>
	<3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>
	<D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>
Message-ID: <78b3a9580706141113m7a01bfa7yf9815b4b624966f0@mail.gmail.com>

> Okay, I guess, people are missing points here.
>
> #!/usr/local/bin/python
> You are specifying the location to the python executable in your machine,
> that rest of the script needs to be interpreted with.
> You are pointing to python is located at /usr/local/bin/python
>
> Consider the possiblities that in a different machine, python may be
> installed at /usr/bin/python or /bin/python in those cases, the above #!
> will fail.
> For those cases, we get to call the env executable with argument which will
> determine the arguments path by searching in the $PATH and use it correctly.
>
> Thus,
> #/usr/bin/env python
> Will figure out the correct location of python ( /usr/bin/python or
> /bin/python from $PATH) and make that as the interpreter for rest of the
> script.
> - ( env is almost always located in /usr/bin/ so one need not worry what is
> env is not present at /usr/bin)


senthil is correct in this regard.  the bottom line is that the one
with env is more flexible and will run on more systems and more types
of systems because it uses the "env" command to find where python is
located and executes it.

the other one simply will *not* work if python is not installed in
that exact location.

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 laurenb01 at gmail.com  Thu Jun 14 20:35:09 2007
From: laurenb01 at gmail.com (Lauren)
Date: Thu, 14 Jun 2007 14:35:09 -0400
Subject: [Tutor] Finding all locations of a sequence
Message-ID: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>

Ok, please bear with me, I'm very new to programming and python. And
my question is rather...convoluted.

I have a bunch of sequences (about 4100 or so), and want to know where
they are in a very, very large string of letters. But wait, there's
more. Some of these sequences match to more than 'word' (for
example...to be consistent with later, chicken could match to poultry
or chicken).

example of what I want to do (on a much smaller scale):

Say I have chicken and I want to know where it occurs in a string of
words, but I want it to match to both chicken and poultry and have the
output of:

chicken  (locations of chicken and poultry in the string)

or something like that.

The string I'm dealing with is really large, so whatever will get
through it the fastest is ideal for me.

I hope this all makes sense...

If it's possible to have pseudocode that would be helpful.

From kent37 at tds.net  Thu Jun 14 20:47:26 2007
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 14 Jun 2007 11:47:26 -0700
Subject: [Tutor] Get max quantity
In-Reply-To: <d5506a9f0706131134v510d526bsf0556cc03519e9ef@mail.gmail.com>
References: <46702DDC.8040804@web.de>
	<d5506a9f0706131134v510d526bsf0556cc03519e9ef@mail.gmail.com>
Message-ID: <46718D3E.8050604@tds.net>

Brian Wisti wrote:
> Hi Carlos,
> 
> On 6/13/07, Carlos <carloslara at web.de> wrote:
>> Hello,
>>
>> If I have a dictionary like:
>>
>> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
>>
>> How can I get the item with the largest quantity? I tried:
>>
>> max(inventory)
>>
>> but got:
>>
>> 'pears'
>>
>> What I would like to get is 'oranges', at least in this case.
>>
>> Thanks,
>> Carlos
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> 
> There are indeed several ways to sort this particular cat. Here's my
> own favorite:
> 
> # Sort the list of keys by inventory count, from high to low
>>>> inventory
> {'pears': 217, 'apples': 430, 'oranges': 525, 'bananas': 312}
>>>> items = inventory.keys()
>>>> items
> ['pears', 'apples', 'oranges', 'bananas']
>>>> items.sort(cmp=lambda a,b: cmp(inventory[b], inventory[a]))
>>>> items
> ['oranges', 'apples', 'bananas', 'pears']
>>>> items[0]
> 'oranges'

You should learn how to use the key parameter to sort, it is much more 
efficient than using cmp and IMO easier to write and understand. In this 
case, you could use key=inventory.__getitem__

> 
> It does result in another list, same as the the approaches listed by
> Kent and Jason. If *all* you were interested was the key associated
> with the greatest inventory count, you could wrap your favorite
> solution in a function and return the key from that.

Neither of my original suggestions created another list. This is 
actually a significant difference between my solutions using max() and 
yours and Jason's using sort. If the list is long using max() could be 
much more efficient because it just makes a single pass through the 
list. max() has O(n) complexity whereas in general sort is O(n log n) so 
as n gets large the advantage of max() should increase. Also for large n 
there should be an advantage to not creating the intermediate list.

As always, if you care about the time taken by an operation, measure 
(with timeit); I am just making educated guesses.

Kent
> 
> Kind Regards,
> 
> Brian Wisti
> http://coolnamehere.com/
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From finalyugi at sapo.pt  Thu Jun 14 21:07:54 2007
From: finalyugi at sapo.pt (Rolando Pereira)
Date: Thu, 14 Jun 2007 20:07:54 +0100
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>
References: <mailman.29516.1181765640.32030.tutor@python.org><1181816053.e051f8f93c8aa@mail.bg><eb90f15e0706140658t14eeadf6j67b8466860244f3f@mail.gmail.com>	<3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>
	<D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>
Message-ID: <4671920A.5000308@sapo.pt>

Senthil_OR at Dell.com escreveu:
> Okay, I guess, people are missing points here. 
>  
> When do you
>  
> #!/usr/local/bin/python
> You are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with.
> You are pointing to python is located at /usr/local/bin/python
>  
> Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, the above #! will fail.
> For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly.
>  
> Thus,
> #/usr/bin/env python
> Will figure out the correct location of python ( /usr/bin/python or /bin/python from $PATH) and make that as the interpreter for rest of the script.
> - ( env is almost always located in /usr/bin/ so one need not worry what is env is not present at /usr/bin)
>  
> Hope this helps.
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

I've always used #!/usr/bin/python...

Perhaps I should use the "#!/usr/bin/env python" one.

-- 
                        _
ASCII ribbon campaign ( )
  - against HTML email  X
              & vCards / \

From nuin at genedrift.org  Thu Jun 14 21:46:51 2007
From: nuin at genedrift.org (Paulo Nuin)
Date: Thu, 14 Jun 2007 15:46:51 -0400
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
Message-ID: <46719B2B.3080506@genedrift.org>

Hi Lauren

You can use two approaches:

 1- String method find

This returns a int value with the lowest position of your search on the 
string (sequence) you are searching. From the documentation:

*find*( sub[, start[, end]])
Return the lowest index in the string where substring sub is found, such 
that sub is contained in the range [start, end]. Optional arguments 
start and end are interpreted as in slice notation. Return |-1| if sub 
is not found.
Example:

position = sequence1.find('chicken')

If your search is not found on your sequence, it will return -1.
You put this in a while loop and you can then search for all occurrences 
of your search string.

2- Use regular expression
You have to import the re module and use the finditer method. The 
finditer method will return the iterator of your regular expression 
matches. Basically you will have to compile a regular expression

mysearch = re.compile('chicken')

and the use the finditer method:

iterator = mysearch.finditer(sequence1)

And then you use a loop to return all the matches

for match in iterator:
...     print match.span()

Each span object is a pair of positions (begin and end) 
of your regular expression matches in the sequence. 
To know more about regex check this page

http://www.amk.ca/python/howto/regex/

HTH

Paulo









Lauren wrote:
> Ok, please bear with me, I'm very new to programming and python. And
> my question is rather...convoluted.
>
> I have a bunch of sequences (about 4100 or so), and want to know where
> they are in a very, very large string of letters. But wait, there's
> more. Some of these sequences match to more than 'word' (for
> example...to be consistent with later, chicken could match to poultry
> or chicken).
>
> example of what I want to do (on a much smaller scale):
>
> Say I have chicken and I want to know where it occurs in a string of
> words, but I want it to match to both chicken and poultry and have the
> output of:
>
> chicken  (locations of chicken and poultry in the string)
>
> or something like that.
>
> The string I'm dealing with is really large, so whatever will get
> through it the fastest is ideal for me.
>
> I hope this all makes sense...
>
> If it's possible to have pseudocode that would be helpful.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


From tms43 at clearwire.net  Thu Jun 14 21:48:52 2007
From: tms43 at clearwire.net (Teresa Stanton)
Date: Thu, 14 Jun 2007 12:48:52 -0700
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
Message-ID: <003701c7aebd$09f98d30$1deca790$@net>

OK, I'm going to take a shot at this.  If what I'm understanding is correct,
a dictionary might help.  But that would depend on the format of the
original sequence.  If you have a list:

Lst1 = ['cow', 'pig', 'chicken', 'poultry', 'beef', 'pork']

Then you could:

Lst1.index('chicken')

And get 2, because the list starts with 0,  not 1, as the first index.

Or this:

>>> for i in Lst1:
	if i == 'chicken':
		print Lst1.index(i)
	if i == 'poultry':
		print Lst1.index(i)

		
2
3

Now, Kent or Alan and perhaps others will have a much more sophisticated way
of doing this same problem.  I'm still not exactly sure what it is you are
looking for, because there isn't enough information for me to really get a
grasp on your problem. My response is a simple list structure that has
simple operations.

Hope it helps :)

T

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of Lauren
Sent: Thursday, June 14, 2007 11:35 AM
To: tutor at python.org
Subject: [Tutor] Finding all locations of a sequence

Ok, please bear with me, I'm very new to programming and python. And
my question is rather...convoluted.

I have a bunch of sequences (about 4100 or so), and want to know where
they are in a very, very large string of letters. But wait, there's
more. Some of these sequences match to more than 'word' (for
example...to be consistent with later, chicken could match to poultry
or chicken).

example of what I want to do (on a much smaller scale):

Say I have chicken and I want to know where it occurs in a string of
words, but I want it to match to both chicken and poultry and have the
output of:

chicken  (locations of chicken and poultry in the string)

or something like that.

The string I'm dealing with is really large, so whatever will get
through it the fastest is ideal for me.

I hope this all makes sense...

If it's possible to have pseudocode that would be helpful.
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor




From bill at celestial.net  Thu Jun 14 21:55:35 2007
From: bill at celestial.net (Bill Campbell)
Date: Thu, 14 Jun 2007 12:55:35 -0700
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <4671920A.5000308@sapo.pt>
References: <3e445c500706140714y27befa9em81158417bd5569fe@mail.gmail.com>
	<D6ED7B7268DC0F4C9BF6AF2537BCE5C60102AA48@blrx3m03.blr.amer.dell.com>
	<4671920A.5000308@sapo.pt>
Message-ID: <20070614195535.GA8519@ayn.mi.celestial.com>

On Thu, Jun 14, 2007, Rolando Pereira wrote:
>Senthil_OR at Dell.com escreveu:
>> Okay, I guess, people are missing points here. 
>>  
>> When do you
>>  
>> #!/usr/local/bin/python
>> You are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with.
>> You are pointing to python is located at /usr/local/bin/python
>>  
>> Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, the above #! will fail.
>> For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly.
>>  
>> Thus,
>> #/usr/bin/env python
>> Will figure out the correct location of python ( /usr/bin/python or /bin/python from $PATH) and make that as the interpreter for rest of the script.
>> - ( env is almost always located in /usr/bin/ so one need not worry what is env is not present at /usr/bin)
>>  
...
>I've always used #!/usr/bin/python...
>
>Perhaps I should use the "#!/usr/bin/env python" one.

The case where ``#!/usr/bin/env python'' won't work is where
there are multiple versions of python on the system, and one
wants to run a version that's not first in the PATH.  In that
case one needs to put the full path to the proper executable.

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

``The trouble with fighting for human freedom is that one spends most of
one's time defending scoundrels. For it is against scoundrels that
oppressive laws are first aimed, and oppression must be stopped at the
beginning if it is to be stopped at all.'' -- H. L. Mencken

From laurenb01 at gmail.com  Thu Jun 14 22:13:57 2007
From: laurenb01 at gmail.com (Lauren)
Date: Thu, 14 Jun 2007 16:13:57 -0400
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <003701c7aebd$09f98d30$1deca790$@net>
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
	<003701c7aebd$09f98d30$1deca790$@net>
Message-ID: <91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>

Ok, what I have is a RNA sequence (about 5 million nucleotides
[characters] long) and have (4100) subsequences (from another
sequence) and the sub-sequences are 6 characters long, that I want to
find in it.
The problem is the exceptional bond of U:G, which results in U bonding
to A (as per normal) and G (the abnormal bond) and G to bond with C
(as per normal) and U. Normally I'd go to search software already
available, however what I need done isn't covered b y anything out
there so far. That and I believe that they do not deal with the
exceptional bond. In any event, I want to know where the subsequences
can bind in the larger RNA sequence (ie, the location of binding in
the larger sequence) so I'm not (just) for where they would bind
normally, but also where the abnormal bonds would figure in.
Unfortunately my first attempt at this was unbearably slow, so I'm
hoping there is a faster way.

So an example with this would be:

Subseq  AAAAAU can bind to UUUUUA (which is normal) and UUUUUG (not so
normal) and I want to know where UUUUUA, and UUUUUG are in the large
RNA sequence, and the locations to show up as one...thing.

I don't know if that is more helpful or not than the chicken example...

Thanks again for the help


On 14/06/07, Teresa Stanton <tms43 at clearwire.net> wrote:
> OK, I'm going to take a shot at this.  If what I'm understanding is correct,
> a dictionary might help.  But that would depend on the format of the
> original sequence.  If you have a list:
>
> Lst1 = ['cow', 'pig', 'chicken', 'poultry', 'beef', 'pork']
>
> Then you could:
>
> Lst1.index('chicken')
>
> And get 2, because the list starts with 0,  not 1, as the first index.
>
> Or this:
>
> >>> for i in Lst1:
>         if i == 'chicken':
>                 print Lst1.index(i)
>         if i == 'poultry':
>                 print Lst1.index(i)
>
>
> 2
> 3
>
> Now, Kent or Alan and perhaps others will have a much more sophisticated way
> of doing this same problem.  I'm still not exactly sure what it is you are
> looking for, because there isn't enough information for me to really get a
> grasp on your problem. My response is a simple list structure that has
> simple operations.
>
> Hope it helps :)
>
> T
>
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
> Of Lauren
> Sent: Thursday, June 14, 2007 11:35 AM
> To: tutor at python.org
> Subject: [Tutor] Finding all locations of a sequence
>
> Ok, please bear with me, I'm very new to programming and python. And
> my question is rather...convoluted.
>
> I have a bunch of sequences (about 4100 or so), and want to know where
> they are in a very, very large string of letters. But wait, there's
> more. Some of these sequences match to more than 'word' (for
> example...to be consistent with later, chicken could match to poultry
> or chicken).
>
> example of what I want to do (on a much smaller scale):
>
> Say I have chicken and I want to know where it occurs in a string of
> words, but I want it to match to both chicken and poultry and have the
> output of:
>
> chicken  (locations of chicken and poultry in the string)
>
> or something like that.
>
> The string I'm dealing with is really large, so whatever will get
> through it the fastest is ideal for me.
>
> I hope this all makes sense...
>
> If it's possible to have pseudocode that would be helpful.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
>


-- 
Lauren

Laurenb01 at gmail.com

From nuin at genedrift.org  Thu Jun 14 22:26:16 2007
From: nuin at genedrift.org (Paulo Nuin)
Date: Thu, 14 Jun 2007 16:26:16 -0400
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>	<003701c7aebd$09f98d30$1deca790$@net>
	<91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>
Message-ID: <4671A468.1070907@genedrift.org>

Hi Lauren

I use the find string method to search DNA motifs. Here is an example

while sp < len(fasta[j].sequence):
                                pos = string.find(fasta[j].sequence, 
motif[i], sp)
                                if pos != -1 and pos > 0:
                                        plist.append(int(size) - pos)
                                        mlist.append(toprint)
                                        sp = pos
                                else:
                                        sp = len(fasta[j].sequence)-1
                                sp+=1
                        pos = 0
                        sp = 0

You might even be able to trim a bit this code, but it is a start.

HTH

Paulo



Lauren wrote:
> Ok, what I have is a RNA sequence (about 5 million nucleotides
> [characters] long) and have (4100) subsequences (from another
> sequence) and the sub-sequences are 6 characters long, that I want to
> find in it.
> The problem is the exceptional bond of U:G, which results in U bonding
> to A (as per normal) and G (the abnormal bond) and G to bond with C
> (as per normal) and U. Normally I'd go to search software already
> available, however what I need done isn't covered b y anything out
> there so far. That and I believe that they do not deal with the
> exceptional bond. In any event, I want to know where the subsequences
> can bind in the larger RNA sequence (ie, the location of binding in
> the larger sequence) so I'm not (just) for where they would bind
> normally, but also where the abnormal bonds would figure in.
> Unfortunately my first attempt at this was unbearably slow, so I'm
> hoping there is a faster way.
>
> So an example with this would be:
>
> Subseq  AAAAAU can bind to UUUUUA (which is normal) and UUUUUG (not so
> normal) and I want to know where UUUUUA, and UUUUUG are in the large
> RNA sequence, and the locations to show up as one...thing.
>
> I don't know if that is more helpful or not than the chicken example...
>
> Thanks again for the help
>
>
> On 14/06/07, Teresa Stanton <tms43 at clearwire.net> wrote:
>   
>> OK, I'm going to take a shot at this.  If what I'm understanding is correct,
>> a dictionary might help.  But that would depend on the format of the
>> original sequence.  If you have a list:
>>
>> Lst1 = ['cow', 'pig', 'chicken', 'poultry', 'beef', 'pork']
>>
>> Then you could:
>>
>> Lst1.index('chicken')
>>
>> And get 2, because the list starts with 0,  not 1, as the first index.
>>
>> Or this:
>>
>>     
>>>>> for i in Lst1:
>>>>>           
>>         if i == 'chicken':
>>                 print Lst1.index(i)
>>         if i == 'poultry':
>>                 print Lst1.index(i)
>>
>>
>> 2
>> 3
>>
>> Now, Kent or Alan and perhaps others will have a much more sophisticated way
>> of doing this same problem.  I'm still not exactly sure what it is you are
>> looking for, because there isn't enough information for me to really get a
>> grasp on your problem. My response is a simple list structure that has
>> simple operations.
>>
>> Hope it helps :)
>>
>> T
>>
>> -----Original Message-----
>> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
>> Of Lauren
>> Sent: Thursday, June 14, 2007 11:35 AM
>> To: tutor at python.org
>> Subject: [Tutor] Finding all locations of a sequence
>>
>> Ok, please bear with me, I'm very new to programming and python. And
>> my question is rather...convoluted.
>>
>> I have a bunch of sequences (about 4100 or so), and want to know where
>> they are in a very, very large string of letters. But wait, there's
>> more. Some of these sequences match to more than 'word' (for
>> example...to be consistent with later, chicken could match to poultry
>> or chicken).
>>
>> example of what I want to do (on a much smaller scale):
>>
>> Say I have chicken and I want to know where it occurs in a string of
>> words, but I want it to match to both chicken and poultry and have the
>> output of:
>>
>> chicken  (locations of chicken and poultry in the string)
>>
>> or something like that.
>>
>> The string I'm dealing with is really large, so whatever will get
>> through it the fastest is ideal for me.
>>
>> I hope this all makes sense...
>>
>> If it's possible to have pseudocode that would be helpful.
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>>
>>     
>
>
>   


From carroll at tjc.com  Fri Jun 15 00:06:26 2007
From: carroll at tjc.com (Terry Carroll)
Date: Thu, 14 Jun 2007 15:06:26 -0700 (PDT)
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>
Message-ID: <Pine.LNX.4.44.0706141459150.12785-100000@violet.rahul.net>

On Thu, 14 Jun 2007, Lauren wrote:

> Subseq  AAAAAU can bind to UUUUUA (which is normal) and UUUUUG (not so
> normal) and I want to know where UUUUUA, and UUUUUG are in the large
> RNA sequence, and the locations to show up as one...thing.

How about something like this?

========================================================================

def seqsearch(seq, targets):
   """
   return a list of match objects, each of which identifies where any of
   the targets are found in the string seq
    seq: string to be searched
    targets: list or tuple of alternate targets to be searched

   note: re.findall is not used, because it wont catch overlaps
   """
   
   import re
   resultlist=[]
   pos=0
   regext_text = "|".join(targets)
   regex = re.compile(regext_text)
   while True:
      result = regex.search(seq, pos)
      if result is None:
         break
      resultlist.append(result)
      pos = result.start()+1
   return resultlist

targets = ["UUUUUA", "UUUUUG"]
sequence="UUCAAUUUGATACCAUUUUUAGCUUCCGUUUUUGCGATACCAUUUUAGCGU"
#                        ++++++       ++++++
#         0         1         2         3         4         5
#         012345678901234567890123456789012345678901234567890
# note: matches at 15 & 28
matches = seqsearch(sequence, targets)
for m in matches:
   print "match %s found at location %s" % (sequence[m.start():m.end()],
                                            m.start()) 
========================================================================

This prints, as expected:

match UUUUUA found at location 15
match UUUUUG found at location 28


From alan.gauld at btinternet.com  Fri Jun 15 00:52:32 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 14 Jun 2007 23:52:32 +0100
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
Message-ID: <f4sgrh$ohq$1@sea.gmane.org>

>From the welter of posts, coming back to the original,
let's summarise:

<emilia12 at mail.bg> wrote in message 
news:1181816053.e051f8f93c8aa at mail.bg...
> how to choose between "#!/usr/bin/env python" and
> "#!/usr/local/bin/python" in the beginning of the script ?

Use env if you want maximum flexibility across
different machines. It will find where the first python
in the PATH lives and use it.

Use a hard path if you have multiple pythons installed
and it matters which one is used. But be aware that
a hard path may not work on another machine
or OS version.

And neither makes any difference on a non-Unix
based OS. (I count cygwin as being Unix based)

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 Jun 15 01:08:27 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 15 Jun 2007 00:08:27 +0100
Subject: [Tutor] Finding all locations of a sequence
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
Message-ID: <f4shpc$rgo$1@sea.gmane.org>

"Lauren" <laurenb01 at gmail.com> wrote

Caveat: I am not into the realms of DNA sequencing so this may
not be viable but...

> Say I have chicken and I want to know where it occurs in a string of
> words, but I want it to match to both chicken and poultry and have 
> the
> output of:
>
> chicken  (locations of chicken and poultry in the string)

When searching for more than one pattern at a time I'd go
for a regex. A simple string search is faster on its own but
a single regex search will typically be faster than a repeated
string search.

For the simple case above a search for  (chicken)|(poultry)
should work:

>>> import re
>>> s = ''' there are a lot of chickens in my poultry farm but
...     very few could be called a spring chicken'''
...
>>> regex = '(chicken)|(poultry)'
>>> r = re.compile(regex)
...
>>> r.findall(s)
...
[('chicken', ''), ('', 'poultry'), ('chicken', '')]
>>> [match for match in r.finditer(s)]
[<_sre.SRE_Match object at 0x01E75920>, <_sre.SRE_Match object at 
0x01E758D8>, <_sre.SRE_Match object at 0x01E75968>]
>>>

The match objects will let you find the location in the original
string which I suspect you will need?

> The string I'm dealing with is really large, so whatever will get
> through it the fastest is ideal for me.

Again I expect a regex to be fastest for multiple seach criteria
over a single pass. Now what your regex will look like for
R/DNA sequences I have no idea, but if you can describe it I'm
sure somebody here can help formulate a suitable pattern

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



From chrispython at mac.com  Fri Jun 15 15:19:57 2007
From: chrispython at mac.com (chrispython at mac.com)
Date: Fri, 15 Jun 2007 06:19:57 -0700
Subject: [Tutor] Subclassing vs. stand alone functions
Message-ID: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>

Hi there,

I am new to Python and trying to get my head around the OO stuff. I guess my question is - when do you go with subclassing vs. making a standalone function? 

Let's say you want to load a dictionary. Do I create a function that accepts some argument (say a file name) and returns a dictionary, or do I subclass dict and override the __init__  and __setitem__ functions to make 'self-loading' dictionary? It seems the end result is the same.

Here is a follow-up if you will indulge me...

I created a class called WebPage which is a stand-alone class (I get that). It loads a web page template, and has a function to update the replacement vars with your data (updHtmlVar), and another to spit out the html to a file (wrtHtml). Do you subclass WebPage for each particular page you want (because you can customize it with load functions for each piece of data) or do you just use it as is, and create separate functions outside the class that load the data and you just use updHtmlVar to load it into your WebPage object? Again, the end result is the same.

(I can send code samples if it will help).

Thanks,

Chris

From jorgen.maillist at gmail.com  Fri Jun 15 15:31:29 2007
From: jorgen.maillist at gmail.com (Jorgen Bodde)
Date: Fri, 15 Jun 2007 15:31:29 +0200
Subject: [Tutor] Subclassing vs. stand alone functions
In-Reply-To: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
References: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
Message-ID: <11e49df10706150631s66e192dal9e10d2aaa7b51e0d@mail.gmail.com>

Hi,

Basically you write a (sub)class when you want to preserve state
information of your instance. If the functionality in question lives
longer then the scope of the function, and will be called from
different methods to obtain the same information and state of the
functionality at that time, it is a candidate for a class.

Whenever the class lives very short, and there is no chance that
seperate threads might screw up the state of the functionality, it is
usually sufficient to keep it inside a module.

My 2ct,
- Jorgen

On 6/15/07, chrispython at mac.com <chrispython at mac.com> wrote:
> Hi there,
>
> I am new to Python and trying to get my head around the OO stuff. I guess my question is - when do you go with subclassing vs. making a standalone function?
>
> Let's say you want to load a dictionary. Do I create a function that accepts some argument (say a file name) and returns a dictionary, or do I subclass dict and override the __init__  and __setitem__ functions to make 'self-loading' dictionary? It seems the end result is the same.
>
> Here is a follow-up if you will indulge me...
>
> I created a class called WebPage which is a stand-alone class (I get that). It loads a web page template, and has a function to update the replacement vars with your data (updHtmlVar), and another to spit out the html to a file (wrtHtml). Do you subclass WebPage for each particular page you want (because you can customize it with load functions for each piece of data) or do you just use it as is, and create separate functions outside the class that load the data and you just use updHtmlVar to load it into your WebPage object? Again, the end result is the same.
>
> (I can send code samples if it will help).
>
> Thanks,
>
> Chris
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

From Senthil_OR at Dell.com  Fri Jun 15 17:00:55 2007
From: Senthil_OR at Dell.com (Senthil_OR at Dell.com)
Date: Fri, 15 Jun 2007 20:30:55 +0530
Subject: [Tutor] Subclassing vs. stand alone functions
In-Reply-To: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
References: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
Message-ID: <D6ED7B7268DC0F4C9BF6AF2537BCE5C60102ACF2@blrx3m03.blr.amer.dell.com>

chrispython at mac.com wrote:
> 
> Let's say you want to load a dictionary. Do I create a function that
> accepts some argument (say a file name) and returns a dictionary, or
> do I subclass dict and override the __init__  and __setitem__
> functions to make 'self-loading' dictionary? It seems the end result
> is the same.    

I am not understanding, what you mean by "loading" a dictionary or a
value in python.
You mean creating a custom dictionary? Then,
a) obj = Dict(list_of_tuples)
b) obj = mydict{}
c) def fun():
	# process it and store in dict.
	return mydict

These are are various ways.

Now, the question is when do you subclass?
Only when you want to extend the behaviour of particular class.

For e.g, you want to extend the Exception class to define your own
Exception, then you will subclass it.
Class MyException(Exception):
	def __init__(self):
		pass
	def __str__(self):
		return "My Exception, Hurray!"

The same, can applied to dictionary, say you want extend the behaviour
of dictionary with a get a random key-value pair.		

Next is, what if you want different instances of a class.
Well, those are the Objects.
In the class you define a property which can be variable and set those
property values when you create the objects from that Class.
	 
> Do you subclass WebPage for each
> particular page you want (because you can customize it with load
> functions for each piece of data) or do you just use it as is, and
> create separate functions outside the class that load the data and

Objects.

> (I can send code samples if it will help).

Sure, please do. I might not check the email on sat/sun. But others here
are ofcourse very helpful.

I hope my explaination help u a bit.

Thanks,

-- 
Senthil


 Your own mileage may vary.

From alan.gauld at btinternet.com  Fri Jun 15 18:59:22 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 15 Jun 2007 17:59:22 +0100
Subject: [Tutor] Subclassing vs. stand alone functions
References: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
Message-ID: <f4ughb$q95$1@sea.gmane.org>

<chrispython at mac.com> wrote 

> I am new to Python and trying to get my head around 
> the OO stuff. I guess my question is - when do you go 
> with subclassing vs. making a standalone function? 

OK, I'll take a slightly different approach than the other 
answers so far.

First: procedural and OO styles of programming are diffrent 
ways of thinking about a problem. Any programming problem 
can be solved using either approach and both approaches 
are equally good, neither is intrinsically "better" than the other.

Second: Some problems are more amenable to an OO
aproach than a procedural and vice versa. And the majority 
can be done either way with very little to choose between 
them.

I will now assume that you understand the procedural way 
and already know how to apply good procedural design, 
including modularity featuring loose coupling and tight 
cohesion. In addition data structure design and its relationship 
to your procedural design should be a concept familiar to you.
( In a perfect world you'll also be familiar with the princuiples of 
functional programming and the lambda calculus, but that's 
possibly asking too much.)

That leaves the question of why and wjen should we use OOP?
OOP suits programs that feature a high level of correspondence 
between the "real world" and the software modfel we are building.
For example simulation software (including many games) usually 
involves the representation and control of a number of objects. 
It is a natural link to model these objects as classes and create 
corresponding objects in our solution. Similarly GUIs are made 
up of windows, widgets, etc. Again these have a fairtly clear 
translation into objects.

When we get into problems primarily of algorithms, or of 
transforms to fixed data then an OOP style is not always such 
an obvious fit. Similarly when modelling complex state 
machines the applicability of OOP can be less obvious and 
a traditional table driven procedural style may seem better suited.

In those cases the decision to use OOP is likely to be driven 
by the desire to create a reusable component. Something that 
can be utilised across multiple projects. or it may be driven by 
the desire to abstract away a complex process or data structure.
Hiding it behind a simplere API.  This can be done using 
traditional approaches but usually only at the cost od writing 
an awful lot of code or by exposing the data structure at least 
for initialisation purposes.

Now to your examples:

> Let's say you want to load a dictionary. 

Why would anyone ever want to load a dictionary?
What is the higher level goal you are trying to achieve?
Is the dictionary part of the solution or the problem?
If it is part of the problem a dictionary object may be appropriate. 
If its part of the solution, and you are already using a non 
OOP approach why would you want an object? Unless its 
for the reasons above - reuse or abstraction that is hard using 
procedures. But you should very rarely be making decisions
at this level unless you have alrwady decided on amn overall 
approach and you are considering an exception to the overall 
style. ie Should I create a function in an OOP design or should 
I create a class in a procedural design. (Mixing styles is OK 
but will normally involve some compromises)

> Do I create a function that accepts some argument 
> or do I subclass dict and override 
> It seems the end result is the same.

Quite so and the andswer will depend on what you are 
trying to achieve. There is no definitive right answer.

> I created a class called WebPage which is a stand-alone 
> class (I get that). 

Sorry, I don't get it! :-).
Do you mean you only have a class and never create any instances?
Or do you mean you don;t subclass anything in defining it?
Or do you mean you only create a single instance?

> It loads a web page template, and has a function to update 
> the replacement vars with your data (updHtmlVar), and another 
> to spit out the html to a file (wrtHtml). 

The data that this page holds is an html template.
Does it also hold the data displayed by the html? in 
which case its not updating with 'your' data but with 
*its own* data. But it may allow you to pass some data 
to it. Or is it that it renders the html only when given 
some data? Which it doesn't store?

The issue of what data a class is responsible for is key 
to its design. If the WebPage ownds the data then all access 
to that data should be via the webPage. If the WebPage accesses 
the data then it needs an interface to the supplying object. 

> Do you subclass WebPage for each particular page 
> you want 

Almost certainly not. You should have different instances.
But you might have different *kinds* of page (Frame, CSS, 
Table, Dynamic, Static etc) and those could be subclasses.

> (because you can customize it with load functions for 
> each piece of data) or do you just use it as is, and create 
> separate functions outside the class that load the data 
> and you just use updHtmlVar to load it into your 
> WebPage object? 

Hopefully you have a set of objects that manage your data 
and each web page has a set of supplier objects that it can 
query as needed when asked to render its html. Thus you 
register a supplier with the page and each time the page is 
asked for its html it will query the supplier objecs for the 
data it needs. (This may imply that you have a DataSupplier 
class and a set of subclasses per type with a comon interface.)
Or it may mean that the web page stores the type of the 
supplier and knows how to interface with each...  There is 
also a likely need for a correspoindence between the html 
template and the dta to be displayed, either that ort the 
template needs tom provide a set of defaults for the case when 
the suppliers data is insufficient for the templates needs.
But as ever it is the designers choice...

> Again, the end result is the same.

Agreed, the choice of OOP or procedural is not about the 
end result it's about which approach suits the problem to 
be solved (and possibly the future reuse criteria).

HTH,

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


From Andy.cheesman at bristol.ac.uk  Fri Jun 15 19:08:47 2007
From: Andy.cheesman at bristol.ac.uk (Andy Cheesman)
Date: Fri, 15 Jun 2007 18:08:47 +0100
Subject: [Tutor] Automatic generation of an "all possible combinations"
 array
In-Reply-To: <f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
References: <4671255F.9080808@bristol.ac.uk>
	<f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
Message-ID: <4672C79F.8060506@bristol.ac.uk>

The code works great, Thanks for the speedy response. The only problem
which I can see is that the code scales very bad with the size of n.

So, as  I want a small subsection of the data (i.e lines where there are
only 4 1s, number in the code below) for a system where n is large(>20).
The idea is that this  would reduce the number of iterations dramatic
despite the individual loop taking longer to operate.(see example data).
I've modified the bit_list_maker to allow for this but it has started to
 produce rows which are identical.
Can anyone make any suggestion/improvements to the code

def bit_list_maker_mod(n, number):
    x = n*number
    solution_set = []
    row_total = number
    for i in range(x):
        this_answer = []
        row = 0
        while i>0:
            this_answer.append(i%2)
            if i%2 == 1:
                row +=1
            i=i/2
            if row == row_total:
                break
        while len(this_answer)<n:
            this_answer.append(0)
        this_answer.reverse()
        solution_set.append(this_answer)
    return solution_set

Hugh M wrote:
> The 2**n different lists that you are seeking have a direct association
> to the binary representation of the integers 0 through (2**n)-1.
> 
> You can use this fact and the "repeated division method" for converting
> numbers between different bases to generate these lists and form the
> desired list of lists:
> 
> def bit_list_maker(n):
>     x = 2**n
>     solution_set = []
>     for i in range(x):
>         this_answer = []
>         while i>0:
>             this_answer.append(i%2)
>             i=i/2
>         while len(this_answer)<n:
>             this_answer.append(0)
>         this_answer.reverse()
>         solution_set.append(this_answer)
>     return solution_set
> *
> *
> Another fun way to do it is to build up the lists recursively.  The
> possibilities for n bits can be built from the possibilities for n-1
> bits by adding a 1 and a 0 to each possibility (ending up with twice as
> many elements):
> 
> def recursive_bit_list(n):
>     if n==1:
>         return [[0],[1]]
>     else:
>         return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
>                map(lambda x: x+[1], recursive_bit_list(n-1))
> 
> Hope this helps!
> 
> -Hugh
> 
>  
> On 6/14/07, *Andy Cheesman* <Andy.cheesman at bristol.ac.uk
> <mailto:Andy.cheesman at bristol.ac.uk>> wrote:
> 
>     Hi people
> 
>     I am trying to generate an array of all possible combinations of 1, and
>     zeros (see example data) for a rather nice Kinetic mote Carlo program
>     which I am writing python. So far, I've been working out for
>     combinations for 4 or less species by hand as it is quick! but I am
>     looking to automate the process so I can compute combinations for large
>       numbers of possible species.
>     I could automate the generation of the array by the use of multiple
>     loops but that doesn't seem rather pythonic. I was wondering if anyone
>     had any sensible suggestions or pointers for efficient mechanisms for
>     the array.
> 
>     Many Thanks
>     Andy
> 
>     Example Data
>     3 species
>     array([[1, 1, 1],
>            [1, 1, 0],
>            [1, 0, 1],
>            [0, 1, 1],
>            [1, 0, 0],
>            [0, 1, 0],
>            [0, 0, 1],
>            [0, 0, 0]])
>     4 species
>     array([[1, 1, 1, 1],
>            [0, 1, 1, 1],
>            [1, 0, 1, 1],
>            [1, 1, 0, 1],
>            [1, 1, 1, 0],
>            [1, 1, 0, 0],
>            [1, 0, 1, 0],
>            [1, 0, 0, 1],
>            [0, 1, 1, 0],
>            [0, 1, 0, 1],
>            [0, 0, 1, 1],
>            [1, 0, 0, 0],
>            [0, 1, 0, 0],
>            [0, 0, 1, 0],
>            [0, 0, 0, 1],
>            [0, 0, 0, 0]])
> 
>     _______________________________________________
>     Tutor maillist  -   Tutor at python.org <mailto:Tutor at python.org>
>     http://mail.python.org/mailman/listinfo/tutor
> 
> 

From rabidpoobear at gmail.com  Fri Jun 15 20:57:08 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Fri, 15 Jun 2007 13:57:08 -0500
Subject: [Tutor] Automatic generation of an "all possible combinations"
 array
In-Reply-To: <4672C79F.8060506@bristol.ac.uk>
References: <4671255F.9080808@bristol.ac.uk>	<f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
	<4672C79F.8060506@bristol.ac.uk>
Message-ID: <4672E104.60604@gmail.com>

Andy Cheesman wrote:
> The code works great, Thanks for the speedy response. The only problem
> which I can see is that the code scales very bad with the size of n.
>   
You could also do this by iterating in base-16 instead of base-10...
given a string of hex,
like "59FDE", there is a direct correlation between the value of each 
digit and the value in binary representation.
In other words, every digit is 4 binary bits.
So if you have a dictionary or something mapping these values to their 
binary equivalents,
hexmap = {"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101",
"6":"0110","7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100",
"d":"1101","e":"1110","f":"1111"}

then for any number n,
you simply do the following:
binary = ""
for x in hex(n)[2:]:
  binary += (hexmap[x])

this is very simple, but I am unsure how efficient it is.
You'd have to test it out.
But it might be faster for large n, compared to a repeated-division or 
recursive approach (I have no idea.)
I used strings for brevity of the code, but you could do the same with 
lists.
obviously you'd need another loop to generate your values (0 -> n) so 
that this can convert them to hex.
HTH,
-Luke

From alan.gauld at btinternet.com  Sat Jun 16 01:28:16 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 16 Jun 2007 00:28:16 +0100
Subject: [Tutor] Automatic generation of an "all possible combinations"
	array
References: <4671255F.9080808@bristol.ac.uk>	<f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com><4672C79F.8060506@bristol.ac.uk>
	<4672E104.60604@gmail.com>
Message-ID: <f4v7ah$4vf$1@sea.gmane.org>


"Luke Paireepinart" <rabidpoobear at gmail.com> wrote

> You could also do this by iterating in base-16 instead of base-10...

I was going to suggest the same but using octal which
has the same property but fewer values to map. :-)

> hexmap = 
> {"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101",
> "6":"0110","7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100",
> "d":"1101","e":"1110","f":"1111"}
>
> then for any number n,
> you simply do the following:
> binary = ""
> for x in hex(n)[2:]:
>  binary += (hexmap[x])
>
> this is very simple, but I am unsure how efficient it is.

Its very efficient, many of the C standard library routines (tolower 
etc)
use a similar technique. The amount of memory used is low and the
speed of a dictionary lookup is much less that multiple divisions etc
You can even avoid the dictionary and just use a list for octal since
n is the number of the index position, but I don't think list indexing 
is
any/much faster than a dictionary lookup in Python. (Time for timeit()
here I think...)

HTH,

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



From chrispython at mac.com  Sat Jun 16 03:21:32 2007
From: chrispython at mac.com (chrispython at mac.com)
Date: Fri, 15 Jun 2007 18:21:32 -0700
Subject: [Tutor] Subclassing vs. stand alone functions
Message-ID: <58F78522-0113-1000-C3C2-36B0F7E302B3-Webmail-10025@mac.com>


I am new to Python and trying to get my head around 
the OO stuff. I guess my question is - when do you go 
with subclassing vs. making a standalone function? 

OK, I'll take a slightly different approach than the other 
answers so far.

First: procedural and OO styles of programming are diffrent 
ways of thinking about a problem. Any programming problem 
can be solved using either approach and both approaches 
are equally good, neither is intrinsically "better" than the other.

Second: Some problems are more amenable to an OO
aproach than a procedural and vice versa. And the majority 
can be done either way with very little to choose between 
them.

I will now assume that you understand the procedural way 
and already know how to apply good procedural design, 
including modularity featuring loose coupling and tight 
cohesion. In addition data structure design and its relationship 
to your procedural design should be a concept familiar to you.
( In a perfect world you'll also be familiar with the princuiples of 
functional programming and the lambda calculus, but that's 
possibly asking too much.)

>Not sure about the lambda calculus, but I have been doing procedural programming 
>for about 10 years. (I try my best for  modularity and all that good stuff :)
>That leaves the question of why and wjen should we use OOP?

OOP suits programs that feature a high level of correspondence 
between the "real world" and the software modfel we are building.
For example simulation software (including many games) usually 
involves the representation and control of a number of objects. 
It is a natural link to model these objects as classes and create 
corresponding objects in our solution. Similarly GUIs are made 
up of windows, widgets, etc. Again these have a fairtly clear 
translation into objects.

When we get into problems primarily of algorithms, or of 
transforms to fixed data then an OOP style is not always such 
an obvious fit. Similarly when modelling complex state 
machines the applicability of OOP can be less obvious and 
a traditional table driven procedural style may seem better suited.

In those cases the decision to use OOP is likely to be driven 
by the desire to create a reusable component. Something that 
can be utilised across multiple projects. or it may be driven by 
the desire to abstract away a complex process or data structure.
Hiding it behind a simplere API.  This can be done using 
traditional approaches but usually only at the cost od writing 
an awful lot of code or by exposing the data structure at least 
for initialisation purposes.

>Thanks, this is just what I needed! A way to think about which to use.

Now to your examples:

Let's say you want to load a dictionary. 

Why would anyone ever want to load a dictionary?

>I just want to create dictionary with some data in it. The data
>comes from a file, let's say. I would then go on to do something with
>the dictionary - like use it as input to another function. (Sorry, I am thinking
>procedurally, or are dictionaries typically populated for you by 
>the functions you call... maybe it's just a bad example.

What is the higher level goal you are trying to achieve?
Is the dictionary part of the solution or the problem?
If it is part of the problem a dictionary object may be appropriate. 
If its part of the solution, and you are already using a non 
OOP approach why would you want an object? Unless its 
for the reasons above - reuse or abstraction that is hard using 
procedures. But you should very rarely be making decisions
at this level unless you have alrwady decided on amn overall 
approach and you are considering an exception to the overall 
style. ie Should I create a function in an OOP design or should 
I create a class in a procedural design. (Mixing styles is OK 
but will normally involve some compromises)

Do I create a function that accepts some argument 
or do I subclass dict and override 
It seems the end result is the same.

Quite so and the andswer will depend on what you are 
trying to achieve. There is no definitive right answer.

I created a class called WebPage which is a stand-alone 
class (I get that). 

Sorry, I don't get it! :-).
Do you mean you only have a class and never create any instances?
>No.
Or do you mean you don;t subclass anything in defining it?
>Yes.
Or do you mean you only create a single instance?
>You could have multiple instances. 

It loads a web page template, and has a function to update 
the replacement vars with your data (updHtmlVar), and another 
to spit out the html to a file (wrtHtml). 

The data that this page holds is an html template.
Does it also hold the data displayed by the html? 
in 
which case its not updating with 'your' data but with 
*its own* data. But it may allow you to pass some data 
to it. Or is it that it renders the html only when given 
some data? Which it doesn't store?
>It stores the data and the template. When it is instantiated, 
>you just have the template and the variables. You would then
>go through the variables and assign values to them. When you call the
>wrtHTML method, it marries the data with the template and writes out the
>HTML to a file. (Not too practical, but it's just for my own learning...)


The issue of what data a class is responsible for is key 
to its design. If the WebPage ownds the data then all access 
to that data should be via the webPage. If the WebPage accesses 
the data then it needs an interface to the supplying object. 

Do you subclass WebPage for each particular page 
you want 

Almost certainly not. You should have different instances.
But you might have different *kinds* of page (Frame, CSS, 
Table, Dynamic, Static etc) and those could be subclasses.

>That's what I was thinking - you could have different kinds of pages.
(because you can customize it with load functions for 
each piece of data) or do you just use it as is, and create 
separate functions outside the class that load the data 
and you just use updHtmlVar to load it into your 
WebPage object? 

Hopefully you have a set of objects that manage your data 
and each web page has a set of supplier objects that it can 
query as needed when asked to render its html. Thus you 
register a supplier with the page and each time the page is 
asked for its html it will query the supplier objecs for the 
data it needs. (This may imply that you have a DataSupplier 
class and a set of subclasses per type with a comon interface.)
>That's where I am trying to get to. You would instantiate a WebPage
>with a template and each data element would have some kind of handler
>that fills itself with the right data. 

Or it may mean that the web page stores the type of the 
supplier and knows how to interface with each...  There is 
also a likely need for a correspoindence between the html 
template and the dta to be displayed, either that ort the 
template needs tom provide a set of defaults for the case when 
the suppliers data is insufficient for the templates needs.
But as ever it is the designers choice...

Again, the end result is the same.

Agreed, the choice of OOP or procedural is not about the 
end result it's about which approach suits the problem to 
be solved (and possibly the future reuse criteria).

>I don't want to use OOP just for the sake of using it, but I also don't want
>to dismiss it outright just because I am not familiar with it.

>Just so you know, my day gig is maintaining a 30 year old COBOL app and 
>writing custom RPGLE  - http://en.wikipedia.org/wiki/RPGLE - on an IBM i5. 
>So that's where I am coming from. 

>I'm having a lot of fun learning something new with Python.


HTH,

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

>Thanks for the quick response and help.


From hyoogle at gmail.com  Sat Jun 16 04:21:33 2007
From: hyoogle at gmail.com (Hugh M)
Date: Fri, 15 Jun 2007 22:21:33 -0400
Subject: [Tutor] Automatic generation of an "all possible combinations"
	array
In-Reply-To: <4672C79F.8060506@bristol.ac.uk>
References: <4671255F.9080808@bristol.ac.uk>
	<f55c23000706140606red848fej95acd77c6a6de2a3@mail.gmail.com>
	<4672C79F.8060506@bristol.ac.uk>
Message-ID: <f55c23000706151921j378e42c8kfc936a30fb6c02d0@mail.gmail.com>

Ah, in the case of looking for all n-digit bit-strings that contain exactly
m-1's, the recursive solution is even nicer.  Here's how I think of it:
Base Case(s):
- if you want 0 1's (m==0) then return all 0's.
- if you want all 1's (n==m) then return all 1's.

Otherwise Recursive Case:
- return the set of all (n-1)digit bit-strings that contain exactly m-1's
plus a 0
combined with the set of all (n-1)digit bit-strings that contain exactly
m-1's plus a 1

Here's some code that does just that:

def recursive_bit_list(n,m):
    if m==0:
        return [n*[0]]
    elif n==m:
        return [n*[1]]
    else:
        return map(lambda x: x+[0], recursive_bit_list(n-1,m)) + \
               map(lambda x: x+[1], recursive_bit_list(n-1,m-1))


If you want it faster and don't mind building up a large in-memory
dictionary as you compute this, you can try incorporating a "memoizer" so
that you don't repeatedly compute the same answer many times.

e.g.:

memoizer = {}

def recursive_bit_list(n,m):
    global memoizer
    if memoizer.has_key((n,m)):
        return memoizer[(n,m)]
    elif m==0:
        return [n*[0]]
    elif n==m:
        return [n*[1]]
    else:
        answer = map(lambda x: x+[0], recursive_bit_list(n-1,m)) + \
               map(lambda x: x+[1], recursive_bit_list(n-1,m-1))
        memoizer[(n,m)] = answer
        return answer


I didn't do any extensive tests- when n is large both of these are far from
speedy...  Maybe there are other ideas?

Good luck!

-Hugh



On 6/15/07, Andy Cheesman <Andy.cheesman at bristol.ac.uk> wrote:
>
> The code works great, Thanks for the speedy response. The only problem
> which I can see is that the code scales very bad with the size of n.
>
> So, as  I want a small subsection of the data (i.e lines where there are
> only 4 1s, number in the code below) for a system where n is large(>20).
> The idea is that this  would reduce the number of iterations dramatic
> despite the individual loop taking longer to operate.(see example data).
> I've modified the bit_list_maker to allow for this but it has started to
> produce rows which are identical.
> Can anyone make any suggestion/improvements to the code
>
> def bit_list_maker_mod(n, number):
>     x = n*number
>     solution_set = []
>     row_total = number
>     for i in range(x):
>         this_answer = []
>         row = 0
>         while i>0:
>             this_answer.append(i%2)
>             if i%2 == 1:
>                 row +=1
>             i=i/2
>             if row == row_total:
>                 break
>         while len(this_answer)<n:
>             this_answer.append(0)
>         this_answer.reverse()
>         solution_set.append(this_answer)
>     return solution_set
>
> Hugh M wrote:
> > The 2**n different lists that you are seeking have a direct association
> > to the binary representation of the integers 0 through (2**n)-1.
> >
> > You can use this fact and the "repeated division method" for converting
> > numbers between different bases to generate these lists and form the
> > desired list of lists:
> >
> > def bit_list_maker(n):
> >     x = 2**n
> >     solution_set = []
> >     for i in range(x):
> >         this_answer = []
> >         while i>0:
> >             this_answer.append(i%2)
> >             i=i/2
> >         while len(this_answer)<n:
> >             this_answer.append(0)
> >         this_answer.reverse()
> >         solution_set.append(this_answer)
> >     return solution_set
> > *
> > *
> > Another fun way to do it is to build up the lists recursively.  The
> > possibilities for n bits can be built from the possibilities for n-1
> > bits by adding a 1 and a 0 to each possibility (ending up with twice as
> > many elements):
> >
> > def recursive_bit_list(n):
> >     if n==1:
> >         return [[0],[1]]
> >     else:
> >         return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
> >                map(lambda x: x+[1], recursive_bit_list(n-1))
> >
> > Hope this helps!
> >
> > -Hugh
> >
> >
> > On 6/14/07, *Andy Cheesman* <Andy.cheesman at bristol.ac.uk
> > <mailto: Andy.cheesman at bristol.ac.uk>> wrote:
> >
> >     Hi people
> >
> >     I am trying to generate an array of all possible combinations of 1,
> and
> >     zeros (see example data) for a rather nice Kinetic mote Carlo
> program
> >     which I am writing python. So far, I've been working out for
> >     combinations for 4 or less species by hand as it is quick! but I am
> >     looking to automate the process so I can compute combinations for
> large
> >       numbers of possible species.
> >     I could automate the generation of the array by the use of multiple
> >     loops but that doesn't seem rather pythonic. I was wondering if
> anyone
> >     had any sensible suggestions or pointers for efficient mechanisms
> for
> >     the array.
> >
> >     Many Thanks
> >     Andy
> >
> >     Example Data
> >     3 species
> >     array([[1, 1, 1],
> >            [1, 1, 0],
> >            [1, 0, 1],
> >            [0, 1, 1],
> >            [1, 0, 0],
> >            [0, 1, 0],
> >            [0, 0, 1],
> >            [0, 0, 0]])
> >     4 species
> >     array([[1, 1, 1, 1],
> >            [0, 1, 1, 1],
> >            [1, 0, 1, 1],
> >            [1, 1, 0, 1],
> >            [1, 1, 1, 0],
> >            [1, 1, 0, 0],
> >            [1, 0, 1, 0],
> >            [1, 0, 0, 1],
> >            [0, 1, 1, 0],
> >            [0, 1, 0, 1],
> >            [0, 0, 1, 1],
> >            [1, 0, 0, 0],
> >            [0, 1, 0, 0],
> >            [0, 0, 1, 0],
> >            [0, 0, 0, 1],
> >            [0, 0, 0, 0]])
> >
> >     _______________________________________________
> >     Tutor maillist  -   Tutor at python.org <mailto:Tutor at python.org >
> >     http://mail.python.org/mailman/listinfo/tutor
> >
> >
> _______________________________________________
> Tutor maillist  -   Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Hugh Morgenbesser     hugh at alum.mit.edu    617 504 0734
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070615/26db01b2/attachment.htm 

From eiwot at hotmail.com  Sat Jun 16 07:14:53 2007
From: eiwot at hotmail.com (Eiwot)
Date: Sat, 16 Jun 2007 05:14:53 +0000
Subject: [Tutor] How to localize PyKaraoke ?
Message-ID: <BAY126-W54B0E594A31E744CED41C4AF1D0@phx.gbl>


Hi all,
   Can I use PyKaraoke in another language such as German ? How to make a song lyrics that match with the song , any word break or phrase break algorithm required ?
 
Thanks
Eiwot
http://pyarticles.blogspot.com/
http://pythonforge.blogspot.com
_________________________________________________________________
Play free games, earn tickets, get cool prizes! Join Live Search Club.?
http://club.live.com/home.aspx?icid=CLUB_wlmailtextlink
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070616/1f767736/attachment-0001.htm 

From janos.juhasz at VELUX.com  Sat Jun 16 07:24:12 2007
From: janos.juhasz at VELUX.com (=?ISO-8859-1?Q?J=E1nos_Juh=E1sz?=)
Date: Sat, 16 Jun 2007 07:24:12 +0200
Subject: [Tutor] Tutor Digest, Vol 40, Issue 38
In-Reply-To: <mailman.29756.1181950135.32030.tutor@python.org>
Message-ID: <OFA964C6AA.51DC18FD-ONC12572FC.001A9C91-C12572FC.001DADDB@velux.com>

Hi Andy,

> The code works great, Thanks for the speedy response. The only problem
> which I can see is that the code scales very bad with the size of n.

> So, as  I want a small subsection of the data (i.e lines where there are
> only 4 1s, number in the code below) for a system where n is large(>20).
> The idea is that this  would reduce the number of iterations dramatic
> despite the individual loop taking longer to operate.(see example data).
> I've modified the bit_list_maker to allow for this but it has started to
> produce rows which are identical.
> Can anyone make any suggestion/improvements to the code

I feel that you would use this table for something else than simple print 
it.
It is probably a decision table.
As each cell of this table can be calculated anytime, I think to not store 
it in
any big table with a lot of integers in each cell, but simple calculate it 
at need.
You can save a lot of memory in that way.
If it is a decision table, I don't mind to starting the permutation on the 
first col
instead of the last. It doesn't change the permutation itself, just its 
order.

def Perm_matrix(row, col):
    if (row & (2**col)): return 1
    return 0

n = 4

for row in range(2**n):
    for col in range(n):
        print Perm_matrix(row, col),
    print ';'


It is easy to turn it into a class.

class Perm:
    def __init__(self, num):
        self.rownum = 2**num
        self.colnum = num

    def Perm_matrix(self, row, col):
        if (row & (2**col)): return 1
        return 0

    def __getitem__(self,(row,col)):
            return self.Perm_matrix(row,col)

m = Perm(4)

for row in range(m.rownum):
    for col in range(m.colnum):
        print m[row, col],
    print ''


Regards,
Janos

From alan.gauld at btinternet.com  Sat Jun 16 09:27:55 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 16 Jun 2007 08:27:55 +0100
Subject: [Tutor] Subclassing vs. stand alone functions
References: <58F78522-0113-1000-C3C2-36B0F7E302B3-Webmail-10025@mac.com>
Message-ID: <f503dt$t3u$1@sea.gmane.org>

<chrispython at mac.com> wrote
>>Just so you know, my day gig is maintaining a 30 year old COBOL app 
>>and
>>writing custom RPGLE  - http://en.wikipedia.org/wiki/RPGLE - on an 
>>IBM i5.
>>So that's where I am coming from.

Thats probably one of the hardest places to learn OOP from.
COBOL, more than any other language I've used forces
programmers to separate data and function explicitly. It then
compounds matters by encouraging the use of global
variables (within modules at least).

Of course COBOL is peerless in tackling exactly those problems
where OOP is weakest - large volume data translation. But its a
big jump from thinking in COBOL to thinking in OOP.  I had to
make the transition in the opposite direction and it was "challenging"

Of course there is COBOL WITH OBJECTS now but I've no idea
how that works. And with rigid discipline you can build with very
small modules comprising precisely one data structure and the
functions that operate on that but its not conventional COBOL
practice.

So I sympathise, but urge you to hang in there the penny
will start to drop, especially if you try to create some projects
that suit OOP - like building a few GUIs or simulations.

Regards,

Alan G.
(2 years with MicroFocus COBOL on OS/360 for Y2K ;-)



From kent37 at tds.net  Sat Jun 16 15:30:02 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 16 Jun 2007 06:30:02 -0700
Subject: [Tutor] Subclassing vs. stand alone functions
In-Reply-To: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
References: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
Message-ID: <4673E5DA.4000107@tds.net>

chrispython at mac.com wrote:
> Hi there,
> 
> I am new to Python and trying to get my head around the OO stuff. I
> guess my question is - when do you go with subclassing vs. making a
> standalone function?

> Let's say you want to load a dictionary. Do I create a function that
> accepts some argument (say a file name) and returns a dictionary, or
> do I subclass dict and override the __init__  and __setitem__
> functions to make 'self-loading' dictionary? It seems the end result
> is the same.

I tend to reserve OOP for the cases where it provides a clear benefit 
and use a procedural style otherwise. So in this case I would make a 
separate factory function to load the dictionary because it is simpler. 
Also you are not changing the behaviour of your new dict so overriding 
seems unnecessary. (BTW Why would you override __setitem__?)

There are many cases where OOP has a clear benefit in simper code, 
encapsulation or reusability. There are times when you have to use OOP, 
for example when using a library that is specialized by subclassing, 
such as a GUI library or the cmd package.

There are also many cases where OOP just adds unneeded complication to 
your code; in these cases Python lets you write in the simpler 
procedural style.

I have written more on this topic here:
http://personalpages.tds.net/~kent37/stories/00014.html

Kent

From kent37 at tds.net  Sat Jun 16 15:33:31 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sat, 16 Jun 2007 06:33:31 -0700
Subject: [Tutor] using zip
In-Reply-To: <000801c7ada5$d1c02c70$6400a8c0@bilbilis>
References: <000801c7ada5$d1c02c70$6400a8c0@bilbilis>
Message-ID: <4673E6AB.2000605@tds.net>

lucio arteaga wrote:
> I am trying to learn using zip in combination of if statemeny. , If I do 
> not make mistakes the program runs wll. Otherwise very bad?

I don't understand your question. Are you talking about the zip() 
function or the zipfile module? What are you trying to do with it? 
Perhaps if you showed us the code you are having trouble with that would 
help.

Kent




From chrispython at mac.com  Sat Jun 16 16:46:24 2007
From: chrispython at mac.com (chrispython at mac.com)
Date: Sat, 16 Jun 2007 07:46:24 -0700
Subject: [Tutor] Subclassing vs. stand alone functions
In-Reply-To: <4673E5DA.4000107@tds.net>
References: <3CDE8122-0113-1000-B74E-141437B759CC-Webmail-10021@mac.com>
	<4673E5DA.4000107@tds.net>
Message-ID: <58F78522-0113-1000-C8A5-36B0F7E302B3-Webmail-10025@mac.com>

Thanks again, this is exactly the kind of info I need to make the jump from 
procedural to OO design.   I bookmarked your site for reference.
On Saturday, June 16, 2007, at 09:30AM, "Kent Johnson" <kent37 at tds.net> wrote:
>chrispython at mac.com wrote:
>> Hi there,
>> 
>> I am new to Python and trying to get my head around the OO stuff. I
>> guess my question is - when do you go with subclassing vs. making a
>> standalone function?
>
>> Let's say you want to load a dictionary. Do I create a function that
>> accepts some argument (say a file name) and returns a dictionary, or
>> do I subclass dict and override the __init__  and __setitem__
>> functions to make 'self-loading' dictionary? It seems the end result
>> is the same.
>
>I tend to reserve OOP for the cases where it provides a clear benefit 
>and use a procedural style otherwise. So in this case I would make a 
>separate factory function to load the dictionary because it is simpler. 
>Also you are not changing the behaviour of your new dict so overriding 
>seems unnecessary. (BTW Why would you override __setitem__?)
>
>There are many cases where OOP has a clear benefit in simper code, 
>encapsulation or reusability. There are times when you have to use OOP, 
>for example when using a library that is specialized by subclassing, 
>such as a GUI library or the cmd package.
>
>There are also many cases where OOP just adds unneeded complication to 
>your code; in these cases Python lets you write in the simpler 
>procedural style.
>
>I have written more on this topic here:
>http://personalpages.tds.net/~kent37/stories/00014.html
>
>Kent
>
>

From norman at khine.net  Sat Jun 16 19:39:29 2007
From: norman at khine.net (Norman Khine)
Date: Sat, 16 Jun 2007 19:39:29 +0200
Subject: [Tutor] how to use replace() from a list
Message-ID: <46742051.30707@khine.net>



Hi I have this class:

def title_to_name(title):
    title = title.encode('ascii', 'replace')
    name = title.lower().replace('/', '_').replace('?',
'_').replace('.', '')
    return '_'.join(name.split())

Is there a way to have just one replace and so that:

replace('/', '_').replace('?', '_').replace('.', '_')

if I put these strings in a list

remove = ['/', '.', '?']

I get this error:

AttributeError: 'list' object has no attribute 'replace'

Thanks

Norman


From alan.gauld at btinternet.com  Sat Jun 16 23:30:17 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 16 Jun 2007 22:30:17 +0100
Subject: [Tutor] how to use replace() from a list
References: <46742051.30707@khine.net>
Message-ID: <f51kpb$2d7$1@sea.gmane.org>

"Norman Khine" <norman at khine.net> wrote 

>    name = title.lower().replace('/', '_').replace('?',
> '_').replace('.', '')
>    return '_'.join(name.split())
> 
> Is there a way to have just one replace and so that:

Check out the string.maketrans() function and 
the translate method.

Basically you do something like:

table = string.maketrans('/?_','___')
title = title.translate(table)

Now I'm not sure how it will react to the translation mapping 
all three chars to the same result char, but it should work...

HTH,


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


From maseriyer at yahoo.com  Sun Jun 17 08:59:47 2007
From: maseriyer at yahoo.com (Iyer)
Date: Sat, 16 Jun 2007 23:59:47 -0700 (PDT)
Subject: [Tutor] iterating over a sequence question..
Message-ID: <481705.89027.qm@web50703.mail.re2.yahoo.com>


say, if I have a list l = [1,2,3,5]

and another tuple t = ('r', 'g', 'b')

Suppose I iterate over list l, and t at the same time, if I use the zip function as in zip(l,t) , I will not be able to cover elements 3 and 5 in list l

>>> l = [1,2,3,5]
>>> t = ('r', 'g', 'b')
>>> for i in zip(l,t):
...     print i
...     
(1, 'r')
(2, 'g')
(3, 'b')

is there an elegant way in python to print all the elements in l, while looping over list t, if len(t) != len(l) as to get the output:

(1, 'r')
 (2, 'g')
 (3, 'b')
(5, 'r')

I could iterate over l only and reset the index to point to the first element of t, in case the elements in t are "exhausted" . Any pythonic way to iterate over a sequence, while iterating over another shorter sequence continously (granted that the lengths of the two lists are different)?


-iyer
       
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070616/c0f1c047/attachment.html 

From john at fouhy.net  Sun Jun 17 09:44:24 2007
From: john at fouhy.net (John Fouhy)
Date: Sun, 17 Jun 2007 19:44:24 +1200
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <481705.89027.qm@web50703.mail.re2.yahoo.com>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
Message-ID: <5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>

On 17/06/07, Iyer <maseriyer at yahoo.com> wrote:
>
> say, if I have a list l = [1,2,3,5]
>
> and another tuple t = ('r', 'g', 'b')
>
> Suppose I iterate over list l, and t at the same time, if I use the zip
> function as in zip(l,t) , I will not be able to cover elements 3 and 5 in
> list l
>
> >>> l = [1,2,3,5]
> >>> t = ('r', 'g', 'b')
> >>> for i in zip(l,t):
> ...     print i
> ...
> (1, 'r')
> (2, 'g')
> (3, 'b')
>
> is there an elegant way in python to print all the elements in l, while
> looping over list t, if len(t) != len(l) as to get the output:
>
> (1, 'r')
>  (2, 'g')
>  (3, 'b')
> (5, 'r')

Check out the itertools module.  I don't have the ability to test this
right now, but try something like:

import itertools
lst = [1,2,3,5]
t = ('r', 'g', 'b')

itertools.izip(lst, itertools.cycle(t))

-- 
John.

From alan.gauld at btinternet.com  Sun Jun 17 09:55:08 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 17 Jun 2007 08:55:08 +0100
Subject: [Tutor] iterating over a sequence question..
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
Message-ID: <f52pcv$d87$1@sea.gmane.org>


"Iyer" <maseriyer at yahoo.com> wrote

> Any pythonic way to iterate over a sequence, while iterating 
> over another shorter sequence continously 

I don;t know how pythonic it is, but I'd do it thus:

>>> a = (1, 2, 3, 4)
>>> b = ('a', 'b', 'c')
>>> n = len(a)/len(b) + 1
>>> t = map(None,a,b*n)[:len(a)]
>>> t
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'a')]
>>> for x,y in t:
...     print x,y
...     
1 a
2 b
3 c
4 a


I suspect you could use a list comp too but map seemed easier.
And of course you could compress it into less lines:

>>> for x,y in map(None,a,b*(len(a)/len(b)+1))[:len(a)]:
...     print x,y

HTH,

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


From rabidpoobear at gmail.com  Sun Jun 17 11:13:47 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Sun, 17 Jun 2007 04:13:47 -0500
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <f52pcv$d87$1@sea.gmane.org>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
	<f52pcv$d87$1@sea.gmane.org>
Message-ID: <4674FB4B.8050303@gmail.com>

Alan Gauld wrote:
> "Iyer" <maseriyer at yahoo.com> wrote
>
>   
>> Any pythonic way to iterate over a sequence, while iterating 
>> over another shorter sequence continously 
>>     
The first thing that occurred to me was just to use a modulus to index 
into the second, shorter list.
 >>> l = [1,2,3,4,5]
 >>> t = ('r','g','b')
 >>> for i in range(len(l)):
    print (l[i], t[i%len(t)])

which results in
   
(1, 'r')
(2, 'g')
(3, 'b')
(4, 'r')
(5, 'g')

not exactly Pythonic either, and you are assuming that l is longer than 
t (it is easy to account for opposite case as well.)

a more expanded version that accounts for either list being the longer 
one, or both being the same length, would be:

 >>> if len(t) > len(l): x = len(t)
else: x = len(l)
 >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
[(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]


-Luke

From alan.gauld at btinternet.com  Sun Jun 17 16:38:59 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 17 Jun 2007 15:38:59 +0100
Subject: [Tutor] iterating over a sequence question..
References: <481705.89027.qm@web50703.mail.re2.yahoo.com><f52pcv$d87$1@sea.gmane.org>
	<4674FB4B.8050303@gmail.com>
Message-ID: <f53h26$9tc$1@sea.gmane.org>


"Luke Paireepinart" <rabidpoobear at gmail.com> wrote

> The first thing that occurred to me was just to use a modulus to 
> index
> into the second, shorter list.

That was the first thing that occured to me too but when
I tried it I couldn't get it to work...

> >>> l = [1,2,3,4,5]
> >>> t = ('r','g','b')
> >>> for i in range(len(l)):
>    print (l[i], t[i%len(t)])

because I was trying t[len(t) % i]
and various  variations, I never thought of reversing the arguments!"
I knew a modulus trick existed but couldn't figure it out this 
morning.

I hadn't had coffee yet, at least that's my excuse! :-)

Alan G.



From reed at reedobrien.com  Sun Jun 17 16:59:22 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Sun, 17 Jun 2007 10:59:22 -0400
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
	<5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>
Message-ID: <FFCC85BD-953E-48C4-87A6-80755BA9571B@reedobrien.com>


On Jun 17, 2007, at 3:44 AM, John Fouhy wrote:

> On 17/06/07, Iyer <maseriyer at yahoo.com> wrote:
>>
>> say, if I have a list l = [1,2,3,5]
>>
>> and another tuple t = ('r', 'g', 'b')
>>
>> Suppose I iterate over list l, and t at the same time, if I use  
>> the zip
>> function as in zip(l,t) , I will not be able to cover elements 3  
>> and 5 in
>> list l
>>
>>>>> l = [1,2,3,5]
>>>>> t = ('r', 'g', 'b')
>>>>> for i in zip(l,t):
>> ...     print i
>> ...
>> (1, 'r')
>> (2, 'g')
>> (3, 'b')
>>
>> is there an elegant way in python to print all the elements in l,  
>> while
>> looping over list t, if len(t) != len(l) as to get the output:
>>
>> (1, 'r')
>>  (2, 'g')
>>  (3, 'b')
>> (5, 'r')
>
> Check out the itertools module.  I don't have the ability to test this
> right now, but try something like:
>
> import itertools
> lst = [1,2,3,5]
> t = ('r', 'g', 'b')
>
> itertools.izip(lst, itertools.cycle(t))
>
> -- 
> John.
>

+1 for John's solution

usage:
 >>> [x for x in itertools.izip(lst, itertools.cycle(t)]
 >>> [(1, 'r'), (2, 'g'), (3, 'b'), (5, 'r')]



From fiveholiday55 at hotmail.com  Sun Jun 17 18:49:31 2007
From: fiveholiday55 at hotmail.com (Henry Dominik)
Date: Sun, 17 Jun 2007 17:49:31 +0100
Subject: [Tutor] Class error
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
	<5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>
Message-ID: <BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>

Hello people,

I was trying my hands on Python's Classes and have a first hurdle and can't 
seem to get past it.

-----Below is the error message ------

Traceback (most recent call last):
  File "C:/Development/python/EmplAddrBookEntry.py", line 3, in -toplevel-
    class EmplAddrBookEntry(AddrBookEntry):
TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)
-----end-----------------
Here are the classes, and they are saved in diferent files
----------------------AddrBookEntry.py-------------------------------------
class AddrBookEntry(object):
    'address book entry class'
    def __init__(self, nm, ph):
        self.name = nm
        self.phone = ph
        print  'Created instance of ', self.name

    def updatePhone(self, newPh):
        self.phone = newPh
        print 'Updated the phone number to: ', self.phone


----------------------EmplAddrBookEntry.py-------------------------------------
import AddrBookEntry

class EmplAddrBookEntry(AddrBookEntry):

    def __init__(self, nm, ph, id, em):
        AddrBookEntry.__init__(self, nm, ph)
        self.empid = id
        self.email = em

    def updateEmail(self, newEmail):
        self.email = newEmail
        print 'Updated with new email', self.email

-------------------------------------------------------------
The error message spills out onto the  IDLE Python Shell window when I press 
the F5.

Your help is highly appreciated.

--Dom


From rabidpoobear at gmail.com  Sun Jun 17 19:43:48 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Sun, 17 Jun 2007 12:43:48 -0500
Subject: [Tutor] Class error
In-Reply-To: <BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>	<5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>
	<BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>
Message-ID: <467572D4.5090900@gmail.com>

Henry Dominik wrote:
> Hello people,
>
> I was trying my hands on Python's Classes and have a first hurdle and can't 
> seem to get past it.
>
> -----Below is the error message ------
>
> Traceback (most recent call last):
>   File "C:/Development/python/EmplAddrBookEntry.py", line 3, in -toplevel-
>     class EmplAddrBookEntry(AddrBookEntry):
> TypeError: Error when calling the metaclass bases
>     module.__init__() takes at most 2 arguments (3 given)
>   
It says "module.__init__" not "AddrBookEntry.__init__" which leads me to 
believe that
> ----------------------AddrBookEntry.py-------------------------------------
>   
the filename of your module
> class AddrBookEntry(object):
>   
and the class name itself are confusing you.
> import AddrBookEntry
>
> class EmplAddrBookEntry(AddrBookEntry):
>
>     def __init__(self, nm, ph, id, em):
>         AddrBookEntry.__init__(self, nm, ph)
>   
I believe this should be "AddrBookEntry.AddrBookEntry.__init__"

I can't be certain, but that's what it looks like off the top of my head.
-Luke

From pierre.cutellic at gmail.com  Sun Jun 17 20:16:36 2007
From: pierre.cutellic at gmail.com (pierre cutellic)
Date: Sun, 17 Jun 2007 20:16:36 +0200
Subject: [Tutor] editing macros for catia V5
Message-ID: <3c8b20230706171116q5dc482cdu5390a7e278f09573@mail.gmail.com>

I am new to Python and trying to get my head around catia V5
I would like to start to write some automated process in python for catia,
does anybody know the way to or some docs maybe?

cheers
Pierre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070617/46f05074/attachment.htm 

From David.Heiser at intelliden.com  Sun Jun 17 20:22:12 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Sun, 17 Jun 2007 12:22:12 -0600
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <FFCC85BD-953E-48C4-87A6-80755BA9571B@reedobrien.com>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3BA@csoexc02.intelliden.net>


I love this [Tutor] list. There are always new tricks that change the
way I write code. And it makes me like Python more every day.

I keep a script file with "notes" on the things I learn here and I refer
to these notes frequently. Here are the notes I made for this thread:


""" iterate/map/modulus/(zip) """
a = (1, 2, 3, 4, 5)
b = ('r', 'g', 'b')
na = len(a)
nb = len(b)

print
print "==================================="
# zip
A = ''.join([str(i) for i in a])  # "12345"
B = ''.join(b)                    # "rgb"
print zip(A, B), "              - zip (inadequate)"
print
print "==================================="
# brute force
m = 0
n = 0
t = []
##x = 10
##for i in range(x):
for i in range(max(na, nb)):
    if m == na:
        m = 0
    if n == nb:
        n = 0
    t.append((a[m], b[n]))
    m += 1
    n += 1
print t,  "- brute force"
print
print "==================================="
# itertools
from itertools import izip, cycle
print list(izip(a, cycle(b))), "- itertools"
print
print "==================================="
# map
print map(None,a,b*(na/nb+1))[:na], "- map"
print
print "==================================="
# modulus
print [(a[i], b[i%nb]) for i in range(na)], "- modulus"
print
print "-----------------------------------"
##x = max(na, nb)
x = 10
print [(a[i%na], b[i%nb]) for i in range(x)], "- modulus (extended)"
print
print "==================================="

This mailing list is great. Thanks to all the experienced Python coders
who offer various solutions to the questions, and to all the beginners
who ask them.



-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Reed O'Brien
Sent: Sunday, June 17, 2007 8:59 AM
To: Iyer; tutor at python.org
Subject: Re: [Tutor] iterating over a sequence question..



On Jun 17, 2007, at 3:44 AM, John Fouhy wrote:

> On 17/06/07, Iyer <maseriyer at yahoo.com> wrote:
>>
>> say, if I have a list l = [1,2,3,5]
>>
>> and another tuple t = ('r', 'g', 'b')
>>
>> Suppose I iterate over list l, and t at the same time, if I use
>> the zip
>> function as in zip(l,t) , I will not be able to cover elements 3  
>> and 5 in
>> list l
>>
>>>>> l = [1,2,3,5]
>>>>> t = ('r', 'g', 'b')
>>>>> for i in zip(l,t):
>> ...     print i
>> ...
>> (1, 'r')
>> (2, 'g')
>> (3, 'b')
>>
>> is there an elegant way in python to print all the elements in l,
>> while
>> looping over list t, if len(t) != len(l) as to get the output:
>>
>> (1, 'r')
>>  (2, 'g')
>>  (3, 'b')
>> (5, 'r')
>
> Check out the itertools module.  I don't have the ability to test this

> right now, but try something like:
>
> import itertools
> lst = [1,2,3,5]
> t = ('r', 'g', 'b')
>
> itertools.izip(lst, itertools.cycle(t))
>
> --
> John.
>

+1 for John's solution

usage:
 >>> [x for x in itertools.izip(lst, itertools.cycle(t)]
 >>> [(1, 'r'), (2, 'g'), (3, 'b'), (5, 'r')]


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

From alan.gauld at btinternet.com  Sun Jun 17 20:28:03 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 17 Jun 2007 19:28:03 +0100
Subject: [Tutor] Class error
References: <481705.89027.qm@web50703.mail.re2.yahoo.com><5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com>
	<BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>
Message-ID: <f53ufm$foj$1@sea.gmane.org>


"Henry Dominik" <fiveholiday55 at hotmail.com> wrote


> import AddrBookEntry
> 
> class EmplAddrBookEntry(AddrBookEntry):

This says you are creating a new class that inherits 
from the *module* AddrBookEntry. Notice that the 
error message referred to the module not the class...

You probably meant:

class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):

>    def __init__(self, nm, ph, id, em):
>        AddrBookEntry.__init__(self, nm, ph)

Which makes this line become
         AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)

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  Sun Jun 17 20:35:43 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 17 Jun 2007 19:35:43 +0100
Subject: [Tutor] editing macros for catia V5
References: <3c8b20230706171116q5dc482cdu5390a7e278f09573@mail.gmail.com>
Message-ID: <f53uu1$h1q$1@sea.gmane.org>


"pierre cutellic" <pierre.cutellic at gmail.com> wrote

>I am new to Python and trying to get my head around catia V5
> I would like to start to write some automated process in python for 
> catia,
> does anybody know the way to or some docs maybe?

Until your post I'd never even heard of Catia. Having looked at
the IBM web site for it I'm not sure why you would choose
Python to write automated processes for it? However there
is a web page here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347243

That shows an example using Windows COM automation but in my
experience COM via Python is no easier than via VBScript or any
other scripting language. So if you know VB/VBscript etc stick with 
those.

There are several other web pages that sjhow up if you google
catia python

HTH,

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





From fiveholiday55 at hotmail.com  Sun Jun 17 20:52:36 2007
From: fiveholiday55 at hotmail.com (Henry Dominik)
Date: Sun, 17 Jun 2007 19:52:36 +0100
Subject: [Tutor] Class error
References: <481705.89027.qm@web50703.mail.re2.yahoo.com><5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com><BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>
	<f53ufm$foj$1@sea.gmane.org>
Message-ID: <BAY142-DAV14B032C101281C3543ACEAD1C0@phx.gbl>

Thanks a million Alan,

Your suggestion helped solve the problem.
Besides, why did I have to do this: class 
EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):

The AddrBookEntry and EmplAddrBookEntry classes are in the same folder, I 
didn't think I needed to call another module or something..

Well, I need to learn more :)

Thanks anyway

--Dom
----- Original Message ----- 
From: "Alan Gauld" <alan.gauld at btinternet.com>
To: <tutor at python.org>
Sent: Sunday, June 17, 2007 7:28 PM
Subject: Re: [Tutor] Class error


>
> "Henry Dominik" <fiveholiday55 at hotmail.com> wrote
>
>
>> import AddrBookEntry
>>
>> class EmplAddrBookEntry(AddrBookEntry):
>
> This says you are creating a new class that inherits
> from the *module* AddrBookEntry. Notice that the
> error message referred to the module not the class...
>
> You probably meant:
>
> class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>
>>    def __init__(self, nm, ph, id, em):
>>        AddrBookEntry.__init__(self, nm, ph)
>
> Which makes this line become
>         AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)
>
> 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
> 


From andreas at kostyrka.org  Sun Jun 17 21:53:00 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Sun, 17 Jun 2007 21:53:00 +0200
Subject: [Tutor] Class error
In-Reply-To: <BAY142-DAV14B032C101281C3543ACEAD1C0@phx.gbl>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com><5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com><BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl>	<f53ufm$foj$1@sea.gmane.org>
	<BAY142-DAV14B032C101281C3543ACEAD1C0@phx.gbl>
Message-ID: <4675911C.2030003@kostyrka.org>

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

Well, Python is not Java :)

Unqualified names reference always only objects defined in the local
module by default.

If you want to use unqualified names, you could do something like that:

from AddrBookEntry import AddrBookEntry

or

import AddrBookEntry as abe
AddrBookEntry = abe.AddrBookEntry

Andreas

Henry Dominik wrote:
> Thanks a million Alan,
> 
> Your suggestion helped solve the problem.
> Besides, why did I have to do this: class 
> EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
> 
> The AddrBookEntry and EmplAddrBookEntry classes are in the same folder, I 
> didn't think I needed to call another module or something..
> 
> Well, I need to learn more :)
> 
> Thanks anyway
> 
> --Dom
> ----- Original Message ----- 
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> To: <tutor at python.org>
> Sent: Sunday, June 17, 2007 7:28 PM
> Subject: Re: [Tutor] Class error
> 
> 
>> "Henry Dominik" <fiveholiday55 at hotmail.com> wrote
>>
>>
>>> import AddrBookEntry
>>>
>>> class EmplAddrBookEntry(AddrBookEntry):
>> This says you are creating a new class that inherits
>> from the *module* AddrBookEntry. Notice that the
>> error message referred to the module not the class...
>>
>> You probably meant:
>>
>> class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>>
>>>    def __init__(self, nm, ph, id, em):
>>>        AddrBookEntry.__init__(self, nm, ph)
>> Which makes this line become
>>         AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)
>>
>> 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGdZEbHJdudm4KnO0RAnz9AJ409z7wGgQgQxC2T9u7JQJz8W2h6wCcCFQD
OqhkiSC897klBc1SMZ0rMTc=
=DPIk
-----END PGP SIGNATURE-----

From bellzii at yahoo.com  Sun Jun 17 14:28:46 2007
From: bellzii at yahoo.com (bellzii)
Date: Sun, 17 Jun 2007 05:28:46 -0700 (PDT)
Subject: [Tutor] newbie question
Message-ID: <11162803.post@talk.nabble.com>


hey everyone , can any1 tell me what does the module optparse do ?

thanks 4 ur time
-- 
View this message in context: http://www.nabble.com/newbie-question-tf3935888.html#a11162803
Sent from the Python - tutor mailing list archive at Nabble.com.


From kent37 at tds.net  Sun Jun 17 22:28:33 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 17 Jun 2007 16:28:33 -0400
Subject: [Tutor] how to use replace() from a list
In-Reply-To: <46742051.30707@khine.net>
References: <46742051.30707@khine.net>
Message-ID: <46759971.7040100@tds.net>

Norman Khine wrote:
> 
> Hi I have this class:
> 
> def title_to_name(title):
>     title = title.encode('ascii', 'replace')
>     name = title.lower().replace('/', '_').replace('?',
> '_').replace('.', '')
>     return '_'.join(name.split())
> 
> Is there a way to have just one replace and so that:
> 
> replace('/', '_').replace('?', '_').replace('.', '_')

You can use re.sub():
In [1]: title = 'www.example.com/foo?bar'
In [2]: import re
In [5]: re.sub(r'[/?.]', '_', title)
Out[5]: 'www_example_com_foo_bar'

Kent

From kent37 at tds.net  Sun Jun 17 22:39:13 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 17 Jun 2007 16:39:13 -0400
Subject: [Tutor] newbie question
In-Reply-To: <11162803.post@talk.nabble.com>
References: <11162803.post@talk.nabble.com>
Message-ID: <46759BF1.9050402@tds.net>

bellzii wrote:
> hey everyone , can any1 tell me what does the module optparse do ?

It helps parse command line arguments. See the docs at
http://docs.python.org/lib/module-optparse.html

Kent

From kent37 at tds.net  Sun Jun 17 22:41:12 2007
From: kent37 at tds.net (Kent Johnson)
Date: Sun, 17 Jun 2007 16:41:12 -0400
Subject: [Tutor] using zip
In-Reply-To: <000301c7b04d$46c5b180$6400a8c0@bilbilis>
References: <000801c7ada5$d1c02c70$6400a8c0@bilbilis>
	<4673E6AB.2000605@tds.net>
	<000301c7b04d$46c5b180$6400a8c0@bilbilis>
Message-ID: <46759C68.3040008@tds.net>

lucio arteaga wrote:
> 
> ----- Original Message ----- From: "Kent Johnson" <kent37 at tds.net>
> To: "lucio arteaga" <mi1492 at cox.net>
> Cc: <Tutor at python.org>
> Sent: Saturday, June 16, 2007 8:33 AM
> Subject: Re: [Tutor] using zip
> 
> 
>> lucio arteaga wrote:
>>> I am trying to learn using zip in combination of if statemeny. , If I 
>>> do not make mistakes the program runs well. Otherwise is very bad?
>>
>> I don't understand your question. Are you talking about the zip() 
>> function or the zipfile module? What are you trying to do with it? 
>> Perhaps if you showed us the code you are having trouble with that 
>> would help.
> 
> I am using it as a function

OK, what are you trying to do with it? What have you tried? What does 
the code look like?

We need a lot more information before we can give you any help.

Kent

PS Please use Reply All to reply to the list.

From mi1492 at cox.net  Sun Jun 17 23:00:06 2007
From: mi1492 at cox.net (lucio arteaga)
Date: Sun, 17 Jun 2007 16:00:06 -0500
Subject: [Tutor] using zip
References: <000801c7ada5$d1c02c70$6400a8c0@bilbilis>
	<4673E6AB.2000605@tds.net>
	<000301c7b04d$46c5b180$6400a8c0@bilbilis>
	<46759C68.3040008@tds.net>
Message-ID: <000301c7b122$7bedb990$6400a8c0@bilbilis>

I have used a function  to input the data and then a module Tproblem has 
been solved .Thank you to all

From: "Kent Johnson" <kent37 at tds.net>
To: "lucio arteaga" <mi1492 at cox.net>; "tutor-python" <tutor at python.org>
Sent: Sunday, June 17, 2007 3:41 PM
Subject: Re: [Tutor] using zip


> lucio arteaga wrote:
>>
>> ----- Original Message ----- From: "Kent Johnson" <kent37 at tds.net>
>> To: "lucio arteaga" <mi1492 at cox.net>
>> Cc: <Tutor at python.org>
>> Sent: Saturday, June 16, 2007 8:33 AM
>> Subject: Re: [Tutor] using zip
>>
>>
>>> lucio arteaga wrote:
>>>> I am trying to learn using zip in combination of if statemeny. , If I 
>>>> do not make mistakes the program runs well. Otherwise is very bad?
>>>
>>> I don't understand your question. Are you talking about the zip() 
>>> function or the zipfile module? What are you trying to do with it? 
>>> Perhaps if you showed us the code you are having trouble with that would 
>>> help.
>>
>> I am using it as a function
>
> OK, what are you trying to do with it? What have you tried? What does the 
> code look like?
>
> We need a lot more information before we can give you any help.
>
> Kent
>
> PS Please use Reply All to reply to the list. 


From linus at linusnordstrom.com  Mon Jun 18 00:46:26 2007
From: linus at linusnordstrom.com (=?ISO-8859-1?Q?Linus_Nordstr=F6m?=)
Date: Mon, 18 Jun 2007 00:46:26 +0200
Subject: [Tutor] sockets
Message-ID: <1eb3a0e10706171546j390c7888re160a0c1c2fe8a83@mail.gmail.com>

Hello
I'm trying to rewrite a chat-program i did in school this spring in
python, the school program was in java. All this to leran python.

Anyway. I m trying to send a message using udp to a server that
conntains the message 3 0 0 0, it has to be in network byte order and
unsigned. I have tried to send it like a string "3000" but get an
error message from the server saying that it did recive 4 bytes, but
that it was an unknown message

So what i am wondering is if there are anny special byte arrays, or
some thing i should use. or if there are anny other way than to send
the message than a string.

From andreas at kostyrka.org  Mon Jun 18 00:47:53 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Mon, 18 Jun 2007 00:47:53 +0200
Subject: [Tutor] sockets
Message-ID: <zJvNvyCDqqMq.dBZDPPpC@heaven.kostyrka.org>

Tip: consult the documentation of the struct module.

Andreas

-- Urspr?ngl. Mitteil. --
Betreff:	[Tutor] sockets
Von:	"Linus Nordstr?m" <linus at linusnordstrom.com>
Datum:		17.06.2007 22:47

Hello
I'm trying to rewrite a chat-program i did in school this spring in
python, the school program was in java. All this to leran python.

Anyway. I m trying to send a message using udp to a server that
conntains the message 3 0 0 0, it has to be in network byte order and
unsigned. I have tried to send it like a string "3000" but get an
error message from the server saying that it did recive 4 bytes, but
that it was an unknown message

So what i am wondering is if there are anny special byte arrays, or
some thing i should use. or if there are anny other way than to send
the message than a string.
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


From alan.gauld at btinternet.com  Mon Jun 18 01:00:36 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 18 Jun 2007 00:00:36 +0100
Subject: [Tutor] Class error
References: <481705.89027.qm@web50703.mail.re2.yahoo.com><5e58f2e40706170044v3799d5b2q4dd0f06519c549b8@mail.gmail.com><BAY142-DAV86EBC865CB41DE96C1F41AD1C0@phx.gbl><f53ufm$foj$1@sea.gmane.org>
	<BAY142-DAV14B032C101281C3543ACEAD1C0@phx.gbl>
Message-ID: <f54een$rcj$1@sea.gmane.org>

"Henry Dominik" <fiveholiday55 at hotmail.com> wrote

> Besides, why did I have to do this: class 
> EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
> 
> The AddrBookEntry and EmplAddrBookEntry classes 
> are in the same folder, 

Python doesn't care abpout the foldrs it only cares about 
the modules. They are in different modules therefore you 
need to import the other module. But importing the module 
just makes the module name available inside your module.
To make the contents of the module available you must 
reference the module. Modules are first class objects in 
Python they are not simply files (although they are 
implemented as simple files!)  You might think of the 
module as being like a class that you can't instantiate 
if you like.

Alternarively you can use the other form of import:

from Module import Name

In your cae that would be

from AddrBookEntry import AddrBookEntry

Now when you use AddrBookentry it refers to the named object  
inside the AddrBookEntry module.

HTH,

Alan G.


From linus at linusnordstrom.se  Mon Jun 18 01:03:12 2007
From: linus at linusnordstrom.se (=?ISO-8859-1?Q?Linus_Nordstr=F6m?=)
Date: Mon, 18 Jun 2007 01:03:12 +0200
Subject: [Tutor] sockets
In-Reply-To: <zJvNvyCDqqMq.dBZDPPpC@heaven.kostyrka.org>
References: <zJvNvyCDqqMq.dBZDPPpC@heaven.kostyrka.org>
Message-ID: <1eb3a0e10706171603x5390a16cv8160f9cc1152d791@mail.gmail.com>

Oh, thank you, exactly what i was looking for :)

On 6/18/07, Andreas Kostyrka <andreas at kostyrka.org> wrote:
> Tip: consult the documentation of the struct module.
>
> Andreas
>
> -- Urspr?ngl. Mitteil. --
> Betreff:        [Tutor] sockets
> Von:    "Linus Nordstr?m" <linus at linusnordstrom.com>
> Datum:          17.06.2007 22:47
>
> Hello
> I'm trying to rewrite a chat-program i did in school this spring in
> python, the school program was in java. All this to leran python.
>
> Anyway. I m trying to send a message using udp to a server that
> conntains the message 3 0 0 0, it has to be in network byte order and
> unsigned. I have tried to send it like a string "3000" but get an
> error message from the server saying that it did recive 4 bytes, but
> that it was an unknown message
>
> So what i am wondering is if there are anny special byte arrays, or
> some thing i should use. or if there are anny other way than to send
> the message than a string.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

From alan.gauld at btinternet.com  Mon Jun 18 01:06:38 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 18 Jun 2007 00:06:38 +0100
Subject: [Tutor] newbie question
References: <11162803.post@talk.nabble.com>
Message-ID: <f54eq1$s3o$1@sea.gmane.org>


"bellzii" <bellzii at yahoo.com> wrote
> hey everyone , can any1 tell me what does the module optparse do ?


It parses options.
That is it takes a command string and works out what
the various bits mean, in particular the command line
options or "switches".

For example you can call python like this:

$ python -i foo.py

And the -i is an option that tells python not to exity the 
intrerpreter
after running foo.py.

optparse can be usd to validate and select options in your programs.

The documentation includes background info and an extensive
tutorial (this must be one of the best documented modules in
the library) , did you read through it before posting? If so what
did you not understand?

HTH,

Alan G. 



From cjw at sympatico.ca  Mon Jun 18 02:48:21 2007
From: cjw at sympatico.ca (Colin J. Williams)
Date: Sun, 17 Jun 2007 20:48:21 -0400
Subject: [Tutor] wxPython GUI builders?
In-Reply-To: <f4pisa$4bi$1@sea.gmane.org>
References: <f4pisa$4bi$1@sea.gmane.org>
Message-ID: <4675D655.5030408@sympatico.ca>

Alan Gauld wrote:
> What's available and in what state of readiness?
> 
> I tried Boa Constructor but after half a dozen code tweaks 
> I was still running into compatibility errors with the latest 
> wxPython and gave up. 
> 
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't 
> looked at it for about 3 years.
> 
> Are there any others? And which ones do people 
> actually use? Commercial or Freeware.
> 
> Alan G.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Dabo is another but it's under continuing development.

Colin W.


From cjw at sympatico.ca  Mon Jun 18 02:48:21 2007
From: cjw at sympatico.ca (Colin J. Williams)
Date: Sun, 17 Jun 2007 20:48:21 -0400
Subject: [Tutor] wxPython GUI builders?
In-Reply-To: <f4pisa$4bi$1@sea.gmane.org>
References: <f4pisa$4bi$1@sea.gmane.org>
Message-ID: <4675D655.5030408@sympatico.ca>

Alan Gauld wrote:
> What's available and in what state of readiness?
> 
> I tried Boa Constructor but after half a dozen code tweaks 
> I was still running into compatibility errors with the latest 
> wxPython and gave up. 
> 
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't 
> looked at it for about 3 years.
> 
> Are there any others? And which ones do people 
> actually use? Commercial or Freeware.
> 
> Alan G.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Dabo is another but it's under continuing development.

Colin W.

From simon at partex.co.uk  Mon Jun 18 14:26:26 2007
From: simon at partex.co.uk (Simon Hooper)
Date: Mon, 18 Jun 2007 13:26:26 +0100
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <4674FB4B.8050303@gmail.com>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
	<f52pcv$d87$1@sea.gmane.org> <4674FB4B.8050303@gmail.com>
Message-ID: <20070618122626.GB18520@partex.co.uk>

Hi Luke,

* On 17/06/07, Luke Paireepinart wrote:
> a more expanded version that accounts for either list being the longer 
> one, or both being the same length, would be:
> 
>  >>> if len(t) > len(l): x = len(t)
> else: x = len(l)
>  >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
> [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]

Being the duffer that I am, I'm very pleased with myself that I came up
with a similar solution (albeit as a function rather than a list
comprehension) :)

You do not need the if statement either,

print [(l[i%len(l)],t[i%len(t)]) for i in range(max(len(l), len(t)))]

Regards

Simon.

-- 
Simon Hooper
PARTEX MARKING SYSTEMS UK LTD

From vishal.thebigv at gmail.com  Mon Jun 18 14:49:36 2007
From: vishal.thebigv at gmail.com (Vishal Jain)
Date: Mon, 18 Jun 2007 17:19:36 +0430
Subject: [Tutor] Python and XSI
Message-ID: <5f3b7ddd0706180549k5d90bb49keb27beeebbce782a@mail.gmail.com>

Hello Guys!!
I have just started learning Python couple days back, actually, I am a
fresher to programming. I am trying to get Python registered with XSI but
everything described in docs failed. I have Python 2.5.1 and Pywin32 build
210 installed. I tried to register Python manually also by running the file
C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py but
still no luck. Is anybody else also facing the same situation? I am not very
sure how many people here uses Python for XSI but still hoping to get some
light on my problem.

Thanks a lot

-- 
Vishal
(TheBigV)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070618/766f7204/attachment.html 

From cshan.pytutor at gmail.com  Mon Jun 18 17:56:28 2007
From: cshan.pytutor at gmail.com (cms cms)
Date: Mon, 18 Jun 2007 11:56:28 -0400
Subject: [Tutor] Help converting base32 to base16
Message-ID: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com>

Hello all,

Newbie here trying to find a module that I can use to convert a number of
strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
searched this list for similar questions, the Global Module Index, the
Vaults of Parnassus, as well as the obvious (Google); however , I cannot
seem to find anything on point. While I'm sure the solution will be obvious,
it currently escapes me.

TIA for any comments or suggestions.


--
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070618/3aed918c/attachment.htm 

From dyoo at cs.wpi.edu  Mon Jun 18 18:17:37 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Mon, 18 Jun 2007 12:17:37 -0400 (EDT)
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>
References: <91120f90706141135ue4d17fdqe9be723a3fc7fbae@mail.gmail.com>
	<003701c7aebd$09f98d30$1deca790$@net>
	<91120f90706141313n3d26464bl93335cbf5581af7f@mail.gmail.com>
Message-ID: <Pine.LNX.4.63.0706181155570.12133@cs.wpi.edu>



> Ok, what I have is a RNA sequence (about 5 million nucleotides 
> [characters] long) and have (4100) subsequences (from another sequence) 
> and the sub-sequences are 6 characters long, that I want to find in it.

Hi Lauren,

I am positive that this problem has been tackled before.  Have you talked 
to any of your fellow bioinformaticists?  It might not be effective to ask 
on Python-tutor because, for typical problems, regexes are sufficient. 
For your particular scenario, regexes may not be, so you may want to ask 
specialists like those on the Biopython mailing lists:

     http://biopython.org/wiki/Mailing_lists

It may seem like a simple extension of regular expression search, but as 
you may have noticed, feeding 4100 regex searches across that RNA sequence 
is going to take some time.  And trying to feed all of those subsequences 
as a single regular expression (using ORs) is probably not going to work 
too well either: the engine has limitations on how large the pattern can 
be before it starts behaving very badly.


To scale to this problem, we need to do something different.  What you're 
probably looking for is more typically known as the keyword matching 
problem, and there are algorithms specifically used for keyword matching. 
For example, take a look at Nicholas Lehuen's Pytst package, which 
implements ternary search trees:

     http://nicolas.lehuen.com/index.php/category/Pytst

I've also written a different package that uses the "Aho-Corasick" 
automata matcher, but to tell the truth I've let the code stale a bit, and 
can't support it (too busy with other work).  But if you're interested in 
tinkering with it, it's here: 
http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/.


If you're going to do more string-matching stuff, I'd recommend a look 
into "Algorithms on Strings, Trees, and Sequences".

     http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198

It's one of the better books on bioinformatics string algorithms, and it 
specifically covers this class of sequence-searching problems.

From alan.gauld at btinternet.com  Mon Jun 18 17:09:35 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 18 Jun 2007 16:09:35 +0100
Subject: [Tutor] Python and XSI
References: <5f3b7ddd0706180549k5d90bb49keb27beeebbce782a@mail.gmail.com>
Message-ID: <f5677j$e1f$1@sea.gmane.org>

"Vishal Jain" <vishal.thebigv at gmail.com> wrote

> I am trying to get Python registered with XSI but
> everything described in docs failed.

OK, I'm assuming that XSI is the 3D Graphics software from Avid?

Can you tell us which docs and what exactly 'failed' means?
What did you do and what actually happened?
Any error messages?

> C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py

ISTR that as being the script for registering Python as an
Active Scripting language for WSH and the IE ActiveX engine.

I assume from that, that XSI uses active scripting?

What did you expect to happen after running it?
And what did happen?

> still no luck. Is anybody else also facing the same situation? I am 
> not very
> sure how many people here uses Python for XSI but still hoping to 
> get some

I had to do a Google search...
You might have more luck on the main comp.lang.python list or
maybe even in the pyGame list. This group is for beginners to Python
and XSI looks a tad advanced for most beginners, going by the couple
of pages I browsed. OTOH there is usually somebody here with an
interest in most things...

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



From kent37 at tds.net  Mon Jun 18 18:30:55 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 18 Jun 2007 12:30:55 -0400
Subject: [Tutor] Help converting base32 to base16
In-Reply-To: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com>
References: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com>
Message-ID: <4676B33F.4040005@tds.net>

cms cms wrote:
> Hello all,
> 
> Newbie here trying to find a module that I can use to convert a number of
> strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
> searched this list for similar questions, the Global Module Index, the
> Vaults of Parnassus, as well as the obvious (Google); however , I cannot
> seem to find anything on point. While I'm sure the solution will be obvious,
> it currently escapes me.

The int() function takes a second argument of the base, so it can 
convert from base 16 or base 32 to integers. The hex() function converts 
from integer to base 16 but there is no equivalent built-in for base 32.

This cookbook recipe will convert in both directions:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286

Kent

From kent37 at tds.net  Mon Jun 18 19:37:19 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 18 Jun 2007 13:37:19 -0400
Subject: [Tutor] [Fwd: Re:  Help converting base32 to base16]
Message-ID: <4676C2CF.5000406@tds.net>

Forwarding to the list...

-------- Original Message --------
Subject: Re: [Tutor] Help converting base32 to base16
Date: Mon, 18 Jun 2007 12:12:46 -0500
From: lucio arteaga <mi1492 at cox.net>
To: Kent Johnson <kent37 at tds.net>
References: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc at mail.gmail.com> 
<4676B33F.4040005 at tds.net>

You are the second person that in less than a moth  has had a similar.
Please  Read in page  241 of my book Algorithms and their Computer 
Solutions
written by Lucio Arteaga ,and published by  Charles E. Merrill in 1972.

----- Original Message -----
From: "Kent Johnson" <kent37 at tds.net>
To: "cms cms" <cshan.pytutor at gmail.com>
Cc: <Tutor at python.org>
Sent: Monday, June 18, 2007 11:30 AM
Subject: Re: [Tutor] Help converting base32 to base16


> cms cms wrote:
>> Hello all,
>>
>> Newbie here trying to find a module that I can use to convert a number of
>> strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
>> searched this list for similar questions, the Global Module Index, the
>> Vaults of Parnassus, as well as the obvious (Google); however , I cannot
>> seem to find anything on point. While I'm sure the solution will be 
>> obvious,
>> it currently escapes me.
>
> The int() function takes a second argument of the base, so it can
> convert from base 16 or base 32 to integers. The hex() function converts
> from integer to base 16 but there is no equivalent built-in for base 32.
>
> This cookbook recipe will convert in both directions:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From alan.gauld at btinternet.com  Mon Jun 18 18:57:53 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 18 Jun 2007 17:57:53 +0100
Subject: [Tutor] Help converting base32 to base16
References: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com>
Message-ID: <f56dil$9dt$1@sea.gmane.org>

"cms cms" <cshan.pytutor at gmail.com> wrote

> Newbie here trying to find a module that I can use to convert a 
> number of
> strings (sha1 values) from base32 to base16 (hex), and vice versa.

I'm intrigued. What does a base 32 number look like?
For example what is 29 in base 32?
Or 1022 for that matter?

I undeetsanmd the principle but I'm wondering what characters
are used above the F of hex.

Also who uses base 32 and for what purpose?

Alan G. 



From jason.massey at gmail.com  Mon Jun 18 19:56:48 2007
From: jason.massey at gmail.com (Jason Massey)
Date: Mon, 18 Jun 2007 12:56:48 -0500
Subject: [Tutor] Help converting base32 to base16
In-Reply-To: <f56dil$9dt$1@sea.gmane.org>
References: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com>
	<f56dil$9dt$1@sea.gmane.org>
Message-ID: <7e3eab2c0706181056l12d8969jb282ece9c4053729@mail.gmail.com>

Nice entry at wikipedia:

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

I like the naming of Base32: *duotrigesimal

*Gotta try to work that into a conversation somehow.*
*
On 6/18/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "cms cms" <cshan.pytutor at gmail.com> wrote
>
> > Newbie here trying to find a module that I can use to convert a
> > number of
> > strings (sha1 values) from base32 to base16 (hex), and vice versa.
>
> I'm intrigued. What does a base 32 number look like?
> For example what is 29 in base 32?
> Or 1022 for that matter?
>
> I undeetsanmd the principle but I'm wondering what characters
> are used above the F of hex.
>
> Also who uses base 32 and for what purpose?
>
> 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/20070618/55aca9eb/attachment.htm 

From rabidpoobear at gmail.com  Mon Jun 18 20:37:21 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Mon, 18 Jun 2007 13:37:21 -0500
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <20070618122626.GB18520@partex.co.uk>
References: <481705.89027.qm@web50703.mail.re2.yahoo.com>
	<f52pcv$d87$1@sea.gmane.org> <4674FB4B.8050303@gmail.com>
	<20070618122626.GB18520@partex.co.uk>
Message-ID: <dfeb4470706181137x737f84b9l358a84c8c2043b16@mail.gmail.com>

On 6/18/07, Simon Hooper <simon at partex.co.uk> wrote:
>
> Hi Luke,
>
> * On 17/06/07, Luke Paireepinart wrote:
> > a more expanded version that accounts for either list being the longer
> > one, or both being the same length, would be:
> >
> >  >>> if len(t) > len(l): x = len(t)
> > else: x = len(l)
> >  >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
> > [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]
>
> Being the duffer that I am, I'm very pleased with myself that I came up
> with a similar solution (albeit as a function rather than a list
> comprehension) :)
>
> You do not need the if statement either,


Yeah, I never knew about the max() function!
I noticed someone else used it in one of their solutions.
I'm pretty sure I've seen it a lot before, just didn't remember it.
-Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070618/1cf0ac67/attachment.html 

From alan.gauld at btinternet.com  Mon Jun 18 22:12:02 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 18 Jun 2007 21:12:02 +0100
Subject: [Tutor] Help converting base32 to base16
References: <fda3eaf50706180856sd9c0948qb43ce6359debc7fc@mail.gmail.com><f56dil$9dt$1@sea.gmane.org>
	<7e3eab2c0706181056l12d8969jb282ece9c4053729@mail.gmail.com>
Message-ID: <f56oul$lah$1@sea.gmane.org>


"Jason Massey" <jason.massey at gmail.com> wrote

>  Nice entry at wikipedia:
> 
> http://en.wikipedia.org/wiki/Base_32
> 

Thanks for the link, I should have thought of oooking there!
I've heardof Base64 for encoding email but never come 
across Base32 - any of the versions!

Alan G.


From dyoo at cs.wpi.edu  Mon Jun 18 22:54:53 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Mon, 18 Jun 2007 16:54:53 -0400 (EDT)
Subject: [Tutor] Finding all locations of a sequence (fwd)
Message-ID: <Pine.LNX.4.63.0706181653280.18230@cs.wpi.edu>

Hi everyone,

Can someone help Lauren?  I apologize for this, but I am very time 
constrained at this moment, and won't be able to reply back for at least a 
few hours.  His question is below.  Thanks!


---------- Forwarded message ----------
Date: Mon, 18 Jun 2007 16:41:39 -0400
From: Lauren <laurenb01 at gmail.com>
To: Danny Yoo <dyoo at cs.wpi.edu>
Subject: Re: [Tutor] Finding all locations of a sequence

Ok, these may be useful. I do have a potentially embarrassing problem,
however I will preface this with I'm practically computer illiterate. Ok
after I download the one you wrote (which I think I understand better than
the one listed previous...famous last words, I'm sure), but when I ask to
import the ahocorasick module, it says it can't find it :( Is it possible to
get step by step instructions on how to open the module? Do I need something
other than the latest download for it?
Again, I'm not good at this programming thing, so I'm sure I'm missing
something obvious

Thank you for your help,

Lauren

On 18/06/07, Danny Yoo <dyoo at cs.wpi.edu> wrote:
>
>
>
>> Ok, what I have is a RNA sequence (about 5 million nucleotides
>> [characters] long) and have (4100) subsequences (from another sequence)
>> and the sub-sequences are 6 characters long, that I want to find in it.
>
> Hi Lauren,
>
> I am positive that this problem has been tackled before.  Have you talked
> to any of your fellow bioinformaticists?  It might not be effective to ask
> on Python-tutor because, for typical problems, regexes are sufficient.
> For your particular scenario, regexes may not be, so you may want to ask
> specialists like those on the Biopython mailing lists:
>
>      http://biopython.org/wiki/Mailing_lists
>
> It may seem like a simple extension of regular expression search, but as
> you may have noticed, feeding 4100 regex searches across that RNA sequence
> is going to take some time.  And trying to feed all of those subsequences
> as a single regular expression (using ORs) is probably not going to work
> too well either: the engine has limitations on how large the pattern can
> be before it starts behaving very badly.
>
>
> To scale to this problem, we need to do something different.  What you're
> probably looking for is more typically known as the keyword matching
> problem, and there are algorithms specifically used for keyword matching.
> For example, take a look at Nicholas Lehuen's Pytst package, which
> implements ternary search trees:
>
>      http://nicolas.lehuen.com/index.php/category/Pytst
>
> I've also written a different package that uses the "Aho-Corasick"
> automata matcher, but to tell the truth I've let the code stale a bit, and
> can't support it (too busy with other work).  But if you're interested in
> tinkering with it, it's here:
> http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/<http://hkn.eecs.berkeley.edu/%7Edyoo/python/ahocorasick/>
> .
>
>
> If you're going to do more string-matching stuff, I'd recommend a look
> into "Algorithms on Strings, Trees, and Sequences".
>
>      http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198
>
> It's one of the better books on bioinformatics string algorithms, and it
> specifically covers this class of sequence-searching problems.
>



-- 
Lauren

Laurenb01 at gmail.com

From linusno at gmail.com  Tue Jun 19 01:19:45 2007
From: linusno at gmail.com (=?ISO-8859-1?Q?Linus_Nordstr=F6m?=)
Date: Tue, 19 Jun 2007 01:19:45 +0200
Subject: [Tutor] sockets
In-Reply-To: <1eb3a0e10706171546j390c7888re160a0c1c2fe8a83@mail.gmail.com>
References: <1eb3a0e10706171546j390c7888re160a0c1c2fe8a83@mail.gmail.com>
Message-ID: <1eb3a0e10706181619r762bdacdqf64424148d0749dd@mail.gmail.com>

gusse i use this thread as my own little help thread.. :)

im having problem whit recv. It will not break the loop if ther are
nothing more to recive. It dose recv all tit should, but then it go
another round in the loop and get stuck on recv, as far as print
debugging has showed,  Dont realy know waht ells information i could
write sown to make my problem anny clrearer, so ask if anythin is
unclear :)

And on another note, is there a way to use the self. less, it might be
just me but it looks rather ugly :)

def recive(self):
         all_data = []
         while 1:
             self.buf = self.s.recv(4096)
             if not self.buf: break
             all_data.append(self.buf)
         return all_data


On 6/18/07, Linus Nordstr?m <linus at linusnordstrom.com> wrote:
> Hello
> I'm trying to rewrite a chat-program i did in school this spring in
> python, the school program was in java. All this to leran python.
>
> Anyway. I m trying to send a message using udp to a server that
> conntains the message 3 0 0 0, it has to be in network byte order and
> unsigned. I have tried to send it like a string "3000" but get an
> error message from the server saying that it did recive 4 bytes, but
> that it was an unknown message
>
> So what i am wondering is if there are anny special byte arrays, or
> some thing i should use. or if there are anny other way than to send
> the message than a string.
>

From alan.gauld at btinternet.com  Tue Jun 19 01:34:28 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 19 Jun 2007 00:34:28 +0100
Subject: [Tutor] sockets
References: <1eb3a0e10706171546j390c7888re160a0c1c2fe8a83@mail.gmail.com>
	<1eb3a0e10706181619r762bdacdqf64424148d0749dd@mail.gmail.com>
Message-ID: <f574q7$tlr$1@sea.gmane.org>

"Linus Nordstr?m" <linusno at gmail.com> wrote

> im having problem whit recv. It will not break the loop if ther are
> nothing more to recive.

Take a look at the client side of the address book
example in my network profgramming topic. It shows
an example of breaking out of a recv loop.

Another option is to use the select module services

> And on another note, is there a way to use the self. less,
> it might be just me but it looks rather ugly :)

No, it's good practice, it distinguishes between class level
variables and local variables. The use of self/this etc is usually
required in industrial coding standards for C++ and Java
(eg Dept of defense/Government etc) for the same reason,
even though those languages don't require it. As in many
things python is simply enforcing what is already considered
good practice elsewhere.

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  Tue Jun 19 01:37:46 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 19 Jun 2007 00:37:46 +0100
Subject: [Tutor] Finding all locations of a sequence (fwd)
References: <Pine.LNX.4.63.0706181653280.18230@cs.wpi.edu>
Message-ID: <f5750e$u4o$1@sea.gmane.org>


> From: Lauren <laurenb01 at gmail.com>
> To: Danny Yoo <dyoo at cs.wpi.edu>
> Subject: Re: [Tutor] Finding all locations of a sequence
>
> after I download the one you wrote (which I think I understand 
> better than
> the one listed previous...famous last words, I'm sure), but when I 
> ask to
> import the ahocorasick module, it says it can't find it :(

You will need to ocate and download the module too.
Either store it along with your program or in the site-packages
folder in your python installation.

> get step by step instructions on how to open the module?

You just import it.
You can read more about that in my modules and functions topic
if that helps.

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




From hokkakada at khmeros.info  Tue Jun 19 07:19:31 2007
From: hokkakada at khmeros.info (hok kakada)
Date: Tue, 19 Jun 2007 12:19:31 +0700
Subject: [Tutor] cannot pickle instancemethod objects
In-Reply-To: <466FDE76.2030509@tds.net>
References: <200706121009.10756.hokkakada@khmeros.info>
	<200706131840.35440.hokkakada@khmeros.info>
	<466FDE76.2030509@tds.net>
Message-ID: <200706191219.32263.hokkakada@khmeros.info>

?????? ??? 13 ?????? 2007 19:09, Kent Johnson ??????????????
> hok kakada wrote:
> >> What kind of object is matcher? Does it have any attributes that are
> >> functions? (Not methods you defined for the class, but functions or
> >> methods that you assign to attributes of self.)
> >
> > Actually, I use the translate-toolkit from
> > http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/
> > in translate/search/match.py:
> >         if comparer is None:
> >             comparer = lshtein.LevenshteinComparer(max_length)
> >
>  >         self.comparer = comparer
> >
> > I just found the problem that it is because of the LevenshteinComparer.
> > Once I assign self.comparer = None, the I can dump the matcher
> > successfully. However, I still don't understand what could be wrong with
> > LevenshteinComparer.
>
> I think the problem is this code in LevenshteinComparer.__init__():
>
>          if Levenshtein:
>              self.distance = self.native_distance
>          else:
>              self.distance = self.python_distance
>
> which assigns an instance method to an instance attribute; this is the
> instancemethod that can't be pickled.
Ok...but how can we deal with it?

Kind Regards,
da

From vishal.thebigv at gmail.com  Tue Jun 19 10:08:36 2007
From: vishal.thebigv at gmail.com (Vishal Jain)
Date: Tue, 19 Jun 2007 12:08:36 +0400
Subject: [Tutor] Python and XSI
Message-ID: <5f3b7ddd0706190108y7ebe22ax2e859fb3760d1ee2@mail.gmail.com>

Yes XSI is a 3D package from Avid. Also knows as Softimage|XSI

By everything failed I mean that XSI isnt registering Python resulting in I
cant select scripitng langauge as Python inside XSI. After running the said
script the command prompt says "Python:Registered" but no error messages.

Yes XSI supports only ActiveX Scripts.

If everything goes good I expect to select scripting langauge as Python
inside XSI and start scripting. But apparently eveything went good as per
the manuals and docs except my luck :(

I did search google but will search more as per your guidlines. And I am a
beginner too in Python. I never coded before.

Thanks a lot for ur suggestions and concern.

By the way are you the same Alan Gauld who posts in XSI Base and CG Talk??

Vishal

Message: 6
Date: Mon, 18 Jun 2007 16:09:35 +0100
From: "Alan Gauld" <alan.gauld at btinternet.com>
Subject: Re: [Tutor] Python and XSI
To: tutor at python.org
Message-ID: <f5677j$e1f$1 at sea.gmane.org>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
       reply-type=original

"Vishal Jain" <vishal.thebigv at gmail.com> wrote

> I am trying to get Python registered with XSI but
> everything described in docs failed.

OK, I'm assuming that XSI is the 3D Graphics software from Avid?

Can you tell us which docs and what exactly 'failed' means?
What did you do and what actually happened?
Any error messages?

> C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py

ISTR that as being the script for registering Python as an
Active Scripting language for WSH and the IE ActiveX engine.

I assume from that, that XSI uses active scripting?

What did you expect to happen after running it?
And what did happen?

> still no luck. Is anybody else also facing the same situation? I am
> not very
> sure how many people here uses Python for XSI but still hoping to
> get some

I had to do a Google search...
You might have more luck on the main comp.lang.python list or
maybe even in the pyGame list. This group is for beginners to Python
and XSI looks a tad advanced for most beginners, going by the couple
of pages I browsed. OTOH there is usually somebody here with an
interest in most things...

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070619/ded2eb30/attachment.html 

From ranpra at gmail.com  Tue Jun 19 12:22:26 2007
From: ranpra at gmail.com (Pradeep Kumar)
Date: Tue, 19 Jun 2007 14:22:26 +0400
Subject: [Tutor] wxpython - Grid
Message-ID: <76b198110706190322s167eb27byb6d279a555218eeb@mail.gmail.com>

Hi,

Tell me about Advance usage of wxGrid
any site or tutorial.
1. data entry program making invoice
Pradeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070619/f9a16032/attachment.html 

From kent37 at tds.net  Tue Jun 19 12:27:15 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 19 Jun 2007 06:27:15 -0400
Subject: [Tutor] cannot pickle instancemethod objects
In-Reply-To: <200706191219.32263.hokkakada@khmeros.info>
References: <200706121009.10756.hokkakada@khmeros.info>	<200706131840.35440.hokkakada@khmeros.info>	<466FDE76.2030509@tds.net>
	<200706191219.32263.hokkakada@khmeros.info>
Message-ID: <4677AF83.2090702@tds.net>

hok kakada wrote:
>>> Actually, I use the translate-toolkit from
>>> http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/

>>> I just found the problem that it is because of the LevenshteinComparer.
>>> Once I assign self.comparer = None, the I can dump the matcher
>>> successfully. However, I still don't understand what could be wrong with
>>> LevenshteinComparer.
>> I think the problem is this code in LevenshteinComparer.__init__():
>>
>>          if Levenshtein:
>>              self.distance = self.native_distance
>>          else:
>>              self.distance = self.python_distance
>>
>> which assigns an instance method to an instance attribute; this is the
>> instancemethod that can't be pickled.
> Ok...but how can we deal with it?

Either assign self.comparer = None before pickling, or define a 
__getstate__() method that returns a dict which doesn't include the 
comparer. Something like

def __getstate__(self):
   d = self.__dict__.copy()
   del d[comparer]
   return d

See http://docs.python.org/lib/pickle-inst.html

Kent

From lake2snow19 at hotmail.com  Wed Jun 20 02:29:51 2007
From: lake2snow19 at hotmail.com (Mat Newport)
Date: Tue, 19 Jun 2007 17:29:51 -0700
Subject: [Tutor] tips for writing a program
Message-ID: <BAY119-DAV1D4372115AB3A9A56EAD4F3110@phx.gbl>

I have taken a fundamentals of programming course at a local college, but that class does not provide the level of expertise to write a program I have in mind. So I do have basic skills, I just need to be shown the tools to write this thing and I think I could put it all together. 
Basically the program would scan a specified folder, build a list of specific files (.txt in the example below), and then have the ability to move and rename certain one's based on a separate list. For example, it would scan c:\test\  for .txt files
and find:

"Koontz lighning.txt"
"davinci_code.txt" 

it would then test its list of found files against a large database for a match, and upon finding the match copy move and rename them to

"Dean Koontz - Lightning.txt"
"Dan Brown - The Davinci Code.txt"

Et cetera. I know basic python but don't know how to make it generate the list, store them, analyze it against another list, then copy and rename based on the matches it finds. Is this a task for a different program?





From rabidpoobear at gmail.com  Wed Jun 20 04:36:46 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 19 Jun 2007 21:36:46 -0500
Subject: [Tutor] tips for writing a program
In-Reply-To: <BAY119-DAV1D4372115AB3A9A56EAD4F3110@phx.gbl>
References: <BAY119-DAV1D4372115AB3A9A56EAD4F3110@phx.gbl>
Message-ID: <467892BE.1070702@gmail.com>

Mat Newport wrote:
> I have taken a fundamentals of programming course at a local college, but that class does not provide the level of expertise to write a program I have in mind. So I do have basic skills, I just need to be shown the tools to write this thing and I think I could put it all together. 
>   
You sound confident in your ability to reason the problem out.  That's 
very good.
> Basically the program would scan a specified folder, build a list of specific files (.txt in the example below), and then have the ability to move and rename certain one's based on a separate list. For example, it would scan c:\test\  for .txt files
> and find:
>
> "Koontz lighning.txt"
> "davinci_code.txt" 
>
> it would then test its list of found files against a large database for a match, and upon finding the match copy move and rename them to
>
> "Dean Koontz - Lightning.txt"
> "Dan Brown - The Davinci Code.txt"
>
> Et cetera. I know basic python but don't know how to make it generate the list, store them, analyze it against another list, then copy and rename based on the matches it finds. Is this a task for a different program?
>   
There are certainly automated file renamer programs out there, but none 
can provide the flexibility of being able to code your own.
Also, if you're really interested in programming, you should take any 
opportunity you can to work on your skills, provided the required level 
of skill
is not vastly out of reach of your own level at the time, and from what 
you have said, I believe you could do this program.

I'm not exactly sure what all your questions are... if you explain in 
more detail, we should be able to assist you with everything.
Here's some hints for what I think you're asking.

"how to generate the list" of files in a directory.
import os #we need this for the path and directory listing functions
directory = 'c:\\test' #define the target directory
extensions = ['txt']
#a list comprehension would be a succinct way to filter the directory 
listing.
listing = [filename for filename in os.listdir(directory) if 
os.path.splitext(filename)[-1].lower() in extensions]

listing now contains all the filenames in the target directory that 
contain the file extension you're looking for.
If the above line doesn't make sense, you can try reading about "list 
comprehensions."  feel free to ask any questions you might have.


"how to store them"
I'm assuming you mean the directory listing?
I'm not sure what you mean by 'store'
You mean permanently store?

"analyze it against another list"
I'm not sure where these lists are coming from.
If you have a basic, direct mapping from incorrect to correct filenames,
like  you know
Koontz lighning.txt  should always be renamed to Dean Koontz - Lightning.txt
the problem is fairly simple.
If you're trying to match based on keywords, etc. it gets more complex.

"copy and rename based on the matches it finds"
if you want to rename a file, you can use the os.rename function.
If you ever find you need help on a certain function,
just use the builtin method "help"
 >>> help(os.rename)
Help on built-in function rename in module nt:

rename(...)
    rename(old, new)
   
    Rename a file or directory.

so this tells us we can do, for example,

os.rename("C:\\test.txt","C:\\foobar.txt")


So try to be more specific where I got confused (I get confused easily)
and I'll try to give you more specific help.
-Luke

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


From maseriyer at yahoo.com  Wed Jun 20 08:43:25 2007
From: maseriyer at yahoo.com (Iyer)
Date: Tue, 19 Jun 2007 23:43:25 -0700 (PDT)
Subject: [Tutor] iterating over a sequence question..
In-Reply-To: <dfeb4470706181137x737f84b9l358a84c8c2043b16@mail.gmail.com>
Message-ID: <753645.27925.qm@web50707.mail.re2.yahoo.com>

wow,

very interesting thread this was..I probably learnt a lot from this than by flipping a few pages of a python text...

thank you all for your interesting responses .. 

iyer

Luke Paireepinart <rabidpoobear at gmail.com> wrote: 

On 6/18/07, Simon Hooper <simon at partex.co.uk> wrote: Hi Luke,

* On 17/06/07, Luke Paireepinart wrote:
> a more expanded version that accounts for either list being the longer
> one, or both being the same length, would be:
>
>  >>> if len(t) > len(l): x = len(t) 
> else: x = len(l)
>  >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
> [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]

Being the duffer that I am, I'm very pleased with myself that I came up 
with a similar solution (albeit as a function rather than a list
comprehension) :)

You do not need the if statement either,
Yeah, I never knew about the max() function!
I noticed someone else used it in one of their solutions. 
I'm pretty sure I've seen it a lot before, just didn't remember it.
-Luke



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


 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070619/4bcb78f3/attachment.htm 

From alan.gauld at btinternet.com  Wed Jun 20 11:08:17 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 20 Jun 2007 10:08:17 +0100
Subject: [Tutor] tips for writing a program
References: <BAY119-DAV1D4372115AB3A9A56EAD4F3110@phx.gbl>
Message-ID: <f5aqq5$4au$1@sea.gmane.org>

"Mat Newport" <lake2snow19 at hotmail.com> wrote

> Basically the program would scan a specified folder, 
> build a list of specific files (.txt in the example below), 

Look at the glob module and its glob function.

Or if you want to include subdirectories lkook at the 
os.walk function. There are examples of using both 
in my Using the OS topic in my tutorial.

> ... to move and rename certain one's 

And the os and shutil modules contain functions to do 
this - again see my OS topic for examples.

> based on a separate list. 

Which could be stored in a file and read into a 
normal python list at startup.

> it would then test its list of found files against 
> a large database for a match, and upon finding 
> the match copy move and rename them 

All fairly simple using the modules mentioned above.

> Et cetera. I know basic python but don't know how to make 
> it generate the list, 

glob will give you a list, os.walk needs more work 
but the normal Python list processing methods will 
work just fine. Do you have any more specific 
questions/problems?

> store them, 

You probably only need to store them in memory so 
once you put them in a list you should be fine.

> analyze it against another list, 

That can be done by looping over one list while comparing 
the items in the other. Luke has shown one way to do that 
using a list comprehension.

> then copy and rename based on the matches it finds. 

See the shutil functions mentioned above.

> Is this a task for a different program?

No, Python is perfectly suited to this kind of task. 
I did something very similar a few weeks ago

Have a go, if you get stuck come back and ask us more 
specific questions and show us the code and error messages.

HTH,

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


From norman at khine.net  Wed Jun 20 12:32:53 2007
From: norman at khine.net (Norman Khine)
Date: Wed, 20 Jun 2007 12:32:53 +0200
Subject: [Tutor] AttributeError: 'list' object has no attribute 'capitalize'
Message-ID: <46790255.7090200@khine.net>

Hello,
I would like to capitalize each word from an input form.

The problem is that the input form can be added as:

"HELLO world"
"hello world"
"HELLO WORLD"

etc..

If I do this:

>>> string = "HELLO world"
>>> print string.capitalize()
Hello world
>>>

only the first word gets capitalized.

My question is how to get all the words in the string to start with
capital letter?

Basically what I would like is to normalize the data input and store
this correctly in the database. Maybe there a simpler approach to this
data input problem.

Many thanks

Norman

From strider1551 at gmail.com  Wed Jun 20 12:38:09 2007
From: strider1551 at gmail.com (Adam A. Zajac)
Date: Wed, 20 Jun 2007 06:38:09 -0400
Subject: [Tutor] AttributeError: 'list' object has no attribute
 'capitalize'
In-Reply-To: <46790255.7090200@khine.net>
References: <46790255.7090200@khine.net>
Message-ID: <20070620063809.3b376f8a@lavos>

On Wed, 20 Jun 2007 12:32:53 +0200

Norman Khine <norman at khine.net> wrote:

> My question is how to get all the words in the string to start with
> capital letter?
title() should do it

>>>a = "hello world"
>>>a.title()
>>>'Hello World'

From likemepearl at yahoo.co.in  Wed Jun 20 12:35:02 2007
From: likemepearl at yahoo.co.in (pearl jb)
Date: Wed, 20 Jun 2007 11:35:02 +0100 (BST)
Subject: [Tutor] List within Dictionary
Message-ID: <145412.52396.qm@web7911.mail.in.yahoo.com>

I wanted to know "How to access the list elements which is in Dictionary"  

dict = {'John':['ph=919873673','res=91928827737'] , 'William' : ['ph=91983763','res=91837474848'] }


I want the output to be

1. John res=91928827737
2. William ph=91983763


       
---------------------------------
 Once upon a time there was 1 GB storage on Yahoo! Mail. Click here for happy ending!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070620/0b6d0513/attachment.html 

From norman at khine.net  Wed Jun 20 13:01:30 2007
From: norman at khine.net (Norman Khine)
Date: Wed, 20 Jun 2007 13:01:30 +0200
Subject: [Tutor] AttributeError: 'list' object has no attribute
	'capitalize'
In-Reply-To: <20070620063809.3b376f8a@lavos>
References: <46790255.7090200@khine.net> <20070620063809.3b376f8a@lavos>
Message-ID: <4679090A.7070705@khine.net>

thanks, it is as easy as that ;)

Adam A. Zajac wrote:
> On Wed, 20 Jun 2007 12:32:53 +0200
> 
> Norman Khine <norman at khine.net> wrote:
> 
>> My question is how to get all the words in the string to start with
>> capital letter?
> title() should do it
> 
>>>> a = "hello world"
>>>> a.title()
>>>> 'Hello World'
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From kent37 at tds.net  Wed Jun 20 13:52:56 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 20 Jun 2007 07:52:56 -0400
Subject: [Tutor] List within Dictionary
In-Reply-To: <145412.52396.qm@web7911.mail.in.yahoo.com>
References: <145412.52396.qm@web7911.mail.in.yahoo.com>
Message-ID: <46791518.1050100@tds.net>

pearl jb wrote:
> I wanted to know "How to access the list elements which is in Dictionary" 
> 
> dict = {'John':['ph=919873673','res=91928827737'] , 'William' : 
> ['ph=91983763','res=91837474848'] }
> 
> 
> I want the output to be
> 
> 1. John res=91928827737
> 2. William ph=91983763

You can use dict.items() to iterate over key, value pairs, then access 
the elements of the value list using regular list indexing. I'm not sure 
how you want to select res for John and ph for William so here is an 
example that prints res for both:

In [11]: d = {'John':['ph=919873673','res=91928827737'] , 'William' : 
['ph=91983763','res=91837474848'] }
In [12]: for name, phones in d.items():
    ....:     print name, phones[1]

William res=91837474848
John res=91928827737


Note that the ordering of keys is essentially random. If you want the 
list in order by name, you can sort the items:

In [13]: for name, phones in sorted(d.items()): 

     print name, phones[1]

John res=91928827737
William res=91837474848


Using enumerate() and some string formatting will give you a sequence 
number:

In [17]: for i, (name, phones) in enumerate(sorted(d.items())):
     print '%s. %s %s' % (i+1, name, phones[1])

1. John res=91928827737
2. William res=91837474848

Docs:
dict.items(): http://docs.python.org/lib/typesmapping.html#l2h-294
sorted(): http://docs.python.org/lib/built-in-funcs.html#l2h-68
enumerate(): http://docs.python.org/lib/built-in-funcs.html#l2h-24
string formatting: http://docs.python.org/lib/typesseq-strings.html

Two more notes:
- Don't use dict as the name for a dict (or list to name a list, or str 
to name a string) as it shadows the name of the built-in type.
- Please don't send HTML mail to the list - use plain text

Kent

From mhoy4 at cox.net  Wed Jun 20 18:26:43 2007
From: mhoy4 at cox.net (Mike Hoy)
Date: Wed, 20 Jun 2007 09:26:43 -0700
Subject: [Tutor] How do I delete all Files of certain extension type?
Message-ID: <46795543.8090308@cox.net>

I have a phonebook program that creates .pb files for each entry that is 
created. One of the features of the program will be to allow the user to 
delete all of the .pb files in the directory. For simplicity I was just 
going to have it delete all the .pb files in the same directory I was 
working in.

I've tried to make a while loop that will delete all the .pb file found 
from glob but it obviously is wrong:

Here is what I have so far:

def deleteAll():
    print "Here is a list of all Phonebook files in this directory: "
    pb_files = glob.glob('*.pb')
    print pb_files

    deleteFiles = raw_input("Would you like to delete all .pb files? ")
    if deleteFiles == "Yes":
    # need to loop thru pb_files and use os.remove
        while pb_files > 0:
            os.remove(pb_files)       
           
    elif deleteFiles == "No":
        print "GoodBye"

deleteAll()


Any pointers you can offer would be appreciated.

Thanks,

Mike Hoy

From rfquerin at gmail.com  Wed Jun 20 20:03:59 2007
From: rfquerin at gmail.com (Richard Querin)
Date: Wed, 20 Jun 2007 14:03:59 -0400
Subject: [Tutor] how can I compare a local directory or file with a remote
	one
Message-ID: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>

I'm interested in writing a quick script that would run a diff-type
command that would compare a local directory to a remote one to
identify the changes in the files within that directory.

I was initially thinking that I would maybe use the linux diff command
in conjunction with the wget command (or something similar) to create
a local copy but that involves downloading files. Is there any way in
python to do a similar thing but without having to download a copy of
the remote files/directories?

Any ideas?

From kent37 at tds.net  Wed Jun 20 20:20:55 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 20 Jun 2007 14:20:55 -0400
Subject: [Tutor] How do I delete all Files of certain extension type?
In-Reply-To: <46795543.8090308@cox.net>
References: <46795543.8090308@cox.net>
Message-ID: <46797007.2090001@tds.net>

Mike Hoy wrote:
> I have a phonebook program that creates .pb files for each entry that is 
> created. One of the features of the program will be to allow the user to 
> delete all of the .pb files in the directory. For simplicity I was just 
> going to have it delete all the .pb files in the same directory I was 
> working in.
> 
> I've tried to make a while loop that will delete all the .pb file found 
> from glob but it obviously is wrong:
> 
> Here is what I have so far:
> 
> def deleteAll():
>     print "Here is a list of all Phonebook files in this directory: "
>     pb_files = glob.glob('*.pb')
>     print pb_files
> 
>     deleteFiles = raw_input("Would you like to delete all .pb files? ")
>     if deleteFiles == "Yes":
>     # need to loop thru pb_files and use os.remove
>         while pb_files > 0:
>             os.remove(pb_files)       

This is not the right way to iterate over a list. Try this:
   for pb_file in pb_files:
     os.remove(pb_file)

Kent

>            
>     elif deleteFiles == "No":
>         print "GoodBye"
> 
> deleteAll()
> 
> 
> Any pointers you can offer would be appreciated.
> 
> Thanks,
> 
> Mike Hoy
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From aristotle831 at gmail.com  Wed Jun 20 20:45:17 2007
From: aristotle831 at gmail.com (F.Lee)
Date: Wed, 20 Jun 2007 14:45:17 -0400
Subject: [Tutor] How do I delete all Files of certain extension type?
In-Reply-To: <46795543.8090308@cox.net>
References: <46795543.8090308@cox.net>
Message-ID: <2ea9c4100706201145u20ffe494s4871b06cae8eaa05@mail.gmail.com>

On 6/20/07, Mike Hoy <mhoy4 at cox.net> wrote:
> I have a phonebook program that creates .pb files for each entry that is
> created. One of the features of the program will be to allow the user to
> delete all of the .pb files in the directory. For simplicity I was just
> going to have it delete all the .pb files in the same directory I was
> working in.
>
> I've tried to make a while loop that will delete all the .pb file found
> from glob but it obviously is wrong:
>
> Here is what I have so far:
>
> def deleteAll():
>     print "Here is a list of all Phonebook files in this directory: "
>     pb_files = glob.glob('*.pb')
>     print pb_files
>
>     deleteFiles = raw_input("Would you like to delete all .pb files? ")
>     if deleteFiles == "Yes":
>     # need to loop thru pb_files and use os.remove
>         while pb_files > 0:
>             os.remove(pb_files)
>
>     elif deleteFiles == "No":
>         print "GoodBye"
>
> deleteAll()
>
>
> Any pointers you can offer would be appreciated.
>
> Thanks,
>
> Mike Hoy
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Mike,

A couple of things:
1. pb_files is a list. You never change the list, yet you say "while
pb_files>0..."
2. os.remove takes a path as its parm, not a list.

suggestion: How 'bout something like
for f in pb_files:
   os.remove(f)

In fact, since you're removing all of 'em, you could just do
os.system("rm *.pb") ## assumes *nix OS

HTH

F.Lee

From tktucker at gmail.com  Wed Jun 20 21:41:49 2007
From: tktucker at gmail.com (Tom Tucker)
Date: Wed, 20 Jun 2007 15:41:49 -0400
Subject: [Tutor] how can I compare a local directory or file with a
	remote one
In-Reply-To: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
Message-ID: <2a278ffe0706201241h44357de8q6b33731c267b52e0@mail.gmail.com>

What are we comparing? Size of files, number of files in a directory, md5sum
of the files, directory size, etc?  What about rsync?  You can use rsync to
compare directories between a source and destiantion system and just report
differences.  For example, comparing /etc directores between two RHEL
4.5systems.



On 6/20/07, Richard Querin <rfquerin at gmail.com> wrote:
>
> I'm interested in writing a quick script that would run a diff-type
> command that would compare a local directory to a remote one to
> identify the changes in the files within that directory.
>
> I was initially thinking that I would maybe use the linux diff command
> in conjunction with the wget command (or something similar) to create
> a local copy but that involves downloading files. Is there any way in
> python to do a similar thing but without having to download a copy of
> the remote files/directories?
>
> Any ideas?
> _______________________________________________
> 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/20070620/df1defee/attachment.htm 

From alan.gauld at btinternet.com  Wed Jun 20 21:41:02 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 20 Jun 2007 20:41:02 +0100
Subject: [Tutor] how can I compare a local directory or file with a
	remoteone
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
Message-ID: <f5bvsj$jb0$1@sea.gmane.org>

"Richard Querin" <rfquerin at gmail.com> wrote

> I was initially thinking that I would maybe use the linux diff 
> command
> in conjunction with the wget command (or something similar) to 
> create
> a local copy but that involves downloading files. Is there any way 
> in
> python to do a similar thing but without having to download a copy 
> of
> the remote files/directories?

Nt unless you can mount the remote filesystem as if it were local,
but even then puython is still going to need access to the file
contents to do a diff, the only difference is it wouldn't store them
on a disk. But you can read the file into memory from a remote
server so thats not really much advantage. Whatever you do you
somehow have to get the contents over the network.

You might find that comparing the files checksums is sufficient.

Alan G. 



From kent37 at tds.net  Wed Jun 20 21:57:48 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 20 Jun 2007 15:57:48 -0400
Subject: [Tutor] how can I compare a local directory or file with a
 remote one
In-Reply-To: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
Message-ID: <467986BC.5070603@tds.net>

Richard Querin wrote:
> I'm interested in writing a quick script that would run a diff-type
> command that would compare a local directory to a remote one to
> identify the changes in the files within that directory.
> 
> I was initially thinking that I would maybe use the linux diff command
> in conjunction with the wget command (or something similar) to create
> a local copy but that involves downloading files. Is there any way in
> python to do a similar thing but without having to download a copy of
> the remote files/directories?

What kind of access do you have to the remote directory? File server, 
ssh, ...

This might be interesting:
http://dirssync.sourceforge.net/

Kent

From norman at khine.net  Wed Jun 20 22:04:20 2007
From: norman at khine.net (Norman Khine)
Date: Wed, 20 Jun 2007 22:04:20 +0200
Subject: [Tutor] how can I compare a local directory or file with a
 remote one
In-Reply-To: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
Message-ID: <46798844.4040205@khine.net>

It depends what you want to compare. Here we use Git http://git.or.cz/
it is written in python and basically you can have two repositories on
the different machines, and track the changes. Obviously if you make a
change on a file, this change has to be commited before it can be
accounted for. perhaps it is of help.

Richard Querin wrote:
> I'm interested in writing a quick script that would run a diff-type
> command that would compare a local directory to a remote one to
> identify the changes in the files within that directory.
> 
> I was initially thinking that I would maybe use the linux diff command
> in conjunction with the wget command (or something similar) to create
> a local copy but that involves downloading files. Is there any way in
> python to do a similar thing but without having to download a copy of
> the remote files/directories?
> 
> Any ideas?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From maseriyer at yahoo.com  Thu Jun 21 02:22:50 2007
From: maseriyer at yahoo.com (Iyer)
Date: Wed, 20 Jun 2007 17:22:50 -0700 (PDT)
Subject: [Tutor] sorting lists into sub lists based on a key
Message-ID: <354109.93437.qm@web50703.mail.re2.yahoo.com>

if I have a list of lists, that goes like this: [[0,['a','b']],[0,['c','d']],[3,['f','g']], [0,['a','b']],[0,['c','d']], [3,['f1','f2']], [2,['zz','dd']]]

what could be the best way to reorder this such that the sublists with the same first element go into their own sub-list ?

like, 

sublist0 = [0,['a','b']],[0,['c','d']],[0,['a','b']],[0,['c','d']]

sublist2 = [2,['zz','dd']]

sublist3 [3,['f','g']], [3,['f1','f2']]

Does this seem to be the best way to do it ?

===============================================================================

from operator import itemgetter
from itertools import groupby

data_list = [[0,['a','b']],[0,['c','d']],[3,['f','g']], [0,['a','b']],[0,['c','d']], [3,['f1','f2']], [2,['zz','dd']]]
data_list.sort()

list1 = []

for key, items in groupby(data_list, key= itemgetter(0)):    
    list1.append(list(items))
       
print "After grouping the list by first value in each element:"
print list1

print "printing each sublist"
for i in list1:
    print i
    

===============================================================================

output :

After grouping the list by first value in each element:After grouping the list by first value in each element:
[[[0, ['a', 'b']], [0, ['a', 'b']], [0, ['c', 'd']], [0, ['c', 'd']]], [[2, ['zz', 'dd']]], [[3, ['f', 'g']], [3, ['f1', 'f2']]]]
printing each sublist
[[0, ['a', 'b']], [0, ['a', 'b']], [0, ['c', 'd']], [0, ['c', 'd']]]
[[2, ['zz', 'dd']]]
[[3, ['f', 'g']], [3, ['f1', 'f2']]]


       
---------------------------------
Got a little couch potato? 
Check out fun summer activities for kids.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070620/dc2fb6ab/attachment.htm 

From kent37 at tds.net  Thu Jun 21 02:46:42 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 20 Jun 2007 20:46:42 -0400
Subject: [Tutor] sorting lists into sub lists based on a key
In-Reply-To: <354109.93437.qm@web50703.mail.re2.yahoo.com>
References: <354109.93437.qm@web50703.mail.re2.yahoo.com>
Message-ID: <4679CA72.2010706@tds.net>

Iyer wrote:
> if I have a list of lists, that goes like this: 
> [[0,['a','b']],[0,['c','d']],[3,['f','g']], [0,['a','b']],[0,['c','d']], 
> [3,['f1','f2']], [2,['zz','dd']]]
> 
> what could be the best way to reorder this such that the sublists with 
> the same first element go into their own sub-list ?
> 
> Does this seem to be the best way to do it ?
> 
> list1 = []
> 
> for key, items in groupby(data_list, key= itemgetter(0)):    
>     list1.append(list(items))

This looks good to me. You could use a list comprehension which is a bit 
more concise and idiomatic:
list1 = [ list(items) for key, items in groupby(data_list, key= 
itemgetter(0)) ]


I can't help thinking that perhaps you should be using dicts to hold 
your data, you seem to have key/value pairs, but without knowing more 
about the problem I can't tell.

Ken

From john at fouhy.net  Thu Jun 21 03:48:40 2007
From: john at fouhy.net (John Fouhy)
Date: Thu, 21 Jun 2007 13:48:40 +1200
Subject: [Tutor] AttributeError: 'list' object has no attribute
	'capitalize'
In-Reply-To: <46790255.7090200@khine.net>
References: <46790255.7090200@khine.net>
Message-ID: <5e58f2e40706201848t11897c70wbace94a4c3bead7c@mail.gmail.com>

On 20/06/07, Norman Khine <norman at khine.net> wrote:
> My question is how to get all the words in the string to start with
> capital letter?

Hmm, well the title() function is a new one to me :-)

More generally, if we have raw = 'one two three', then I would have
done it using raw.split().  i.e.

capwords = [s.capitalize() for s in raw.split()]  # this will give you
a list of capitalized words
capstr = ' '.join(capwords)    # join them together, with spaces between

-- 
John.

From reed at reedobrien.com  Thu Jun 21 05:51:54 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Wed, 20 Jun 2007 23:51:54 -0400
Subject: [Tutor] how can I compare a local directory or file with a
	remote one
In-Reply-To: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
Message-ID: <D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>


On Jun 20, 2007, at 2:03 PM, Richard Querin wrote:

> I'm interested in writing a quick script that would run a diff-type
> command that would compare a local directory to a remote one to
> identify the changes in the files within that directory.
>
> I was initially thinking that I would maybe use the linux diff command
> in conjunction with the wget command (or something similar) to create
> a local copy but that involves downloading files. Is there any way in
> python to do a similar thing but without having to download a copy of
> the remote files/directories?
>
> Any ideas?
>

At first blush it sounds to me like you want rsync, as has been  
pointed out.  If on of the systems is running an OS that doesn't come  
with rsync... I have used http://www.vdesmedt.com/~vds2212/rsync.html  
to achieve the same result.

~r

From zebra05 at gmail.com  Thu Jun 21 15:08:07 2007
From: zebra05 at gmail.com (OkaMthembo)
Date: Thu, 21 Jun 2007 15:08:07 +0200
Subject: [Tutor] Python and Clearsilver for Web Development
Message-ID: <c7c6f3bc0706210608v34458a8bu1aae407807f7eb8c@mail.gmail.com>

Hi All,

Would anyone have experience using Clearsilver with Python for web
development? i wish to find out
- how easy/ difficult it is to seperate presentation from logic,
- how fast such a setup would be compared to asp.net, jsp and php
- whether or not such a setup would work with Lighttpd.
I have access to the Clearsilver reading material but i wish to hear other
opinions.

The link is http://www.clearsilver.net

Best regards,

Sithembewena Lloyd Dube

-- 
"The Stupidry Foundry"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070621/a5f32936/attachment.html 

From python at venix.com  Thu Jun 21 15:06:37 2007
From: python at venix.com (Lloyd Kvam)
Date: Thu, 21 Jun 2007 09:06:37 -0400
Subject: [Tutor] how can I compare a local directory or file with
	a	remote one
In-Reply-To: <D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
	<D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>
Message-ID: <1182431197.4092.179.camel@localhost.localdomain>

On Wed, 2007-06-20 at 23:51 -0400, Reed O'Brien wrote:
> On Jun 20, 2007, at 2:03 PM, Richard Querin wrote:
> 
> > I'm interested in writing a quick script that would run a diff-type
> > command that would compare a local directory to a remote one to
> > identify the changes in the files within that directory.
> >
> > I was initially thinking that I would maybe use the linux diff command
> > in conjunction with the wget command (or something similar) to create
> > a local copy but that involves downloading files. Is there any way in
> > python to do a similar thing but without having to download a copy of
> > the remote files/directories?
> >
> > Any ideas?
> >
> 
> At first blush it sounds to me like you want rsync, as has been  
> pointed out.  If on of the systems is running an OS that doesn't come  
> with rsync... I have used http://www.vdesmedt.com/~vds2212/rsync.html  
> to achieve the same result.
> 

I downloaded the file from the web site, but was disappointed to see
that there appears to be no support for any network transport.  It
simply operates on locally mounted directories.  I only did a cursory
scan of the source code.  Did I miss something?

Certainly the program provides useful example code for file comparisons,
but it does not appear to directly support any kind of remote
processing.

When I need to deal with Windows computers, I sorely feel the lack of
ssh, rsync, and sshfs.

> ~r
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp


From dyoo at cs.wpi.edu  Thu Jun 21 15:47:48 2007
From: dyoo at cs.wpi.edu (Danny Yoo)
Date: Thu, 21 Jun 2007 09:47:48 -0400 (EDT)
Subject: [Tutor] how can I compare a local directory or file with a
 remote one
In-Reply-To: <1182431197.4092.179.camel@localhost.localdomain>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
	<D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>
	<1182431197.4092.179.camel@localhost.localdomain>
Message-ID: <Pine.LNX.4.63.0706210939020.2951@cs.wpi.edu>

>> At first blush it sounds to me like you want rsync, as has been
>> pointed out.  If on of the systems is running an OS that doesn't come
>> with rsync... I have used http://www.vdesmedt.com/~vds2212/rsync.html
>> to achieve the same result.
>>
>
> When I need to deal with Windows computers, I sorely feel the lack of 
> ssh, rsync, and sshfs.


I know this is very Python-unspecific, but I might as well chime in: 
there's a utility called "Unison" that's similar to rsync, and works on 
Windows:

     http://www.cis.upenn.edu/~bcpierce/unison/

From reed at reedobrien.com  Thu Jun 21 20:45:21 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Thu, 21 Jun 2007 14:45:21 -0400
Subject: [Tutor] how can I compare a local directory or file with a
	remote one
In-Reply-To: <1182431197.4092.179.camel@localhost.localdomain>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
	<D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>
	<1182431197.4092.179.camel@localhost.localdomain>
Message-ID: <C3EEF79C-37DE-4944-9A82-CFA8171AE673@reedobrien.com>

On Jun 21, 2007, at 9:06 AM, Lloyd Kvam wrote:

> On Wed, 2007-06-20 at 23:51 -0400, Reed O'Brien wrote:
>> On Jun 20, 2007, at 2:03 PM, Richard Querin wrote:
>>
>>> I'm interested in writing a quick script that would run a diff-type
>>> command that would compare a local directory to a remote one to
>>> identify the changes in the files within that directory.
>>>
>>> I was initially thinking that I would maybe use the linux diff  
>>> command
>>> in conjunction with the wget command (or something similar) to  
>>> create
>>> a local copy but that involves downloading files. Is there any  
>>> way in
>>> python to do a similar thing but without having to download a  
>>> copy of
>>> the remote files/directories?
>>>
>>> Any ideas?
>>>
>>
>> At first blush it sounds to me like you want rsync, as has been
>> pointed out.  If on of the systems is running an OS that doesn't come
>> with rsync... I have used http://www.vdesmedt.com/~vds2212/rsync.html
>> to achieve the same result.
>>
>
> I downloaded the file from the web site, but was disappointed to see
> that there appears to be no support for any network transport.  It
> simply operates on locally mounted directories.  I only did a cursory
> scan of the source code.  Did I miss something?
>
> Certainly the program provides useful example code for file  
> comparisons,
> but it does not appear to directly support any kind of remote
> processing.
>
> When I need to deal with Windows computers, I sorely feel the lack of
> ssh, rsync, and sshfs.
>

It has been a couple years since I have used it, but I am sure I did  
it across a network via SMB.  I no longer work there, so I  
unfortunately don't have access to what I did.

I remember it being over a network because the www server was  
separate from the backup server.  I may have done it on the Windows  
machine and had the remote N*X SMB mounted as a network drive. I  
think I also used putty on a Windows server to make an ssh tunnel to  
work over at another project.

To my great fortune I don't currently have to deal with windows at  
all (currently).

~r



From amadeo.bellotti at gmail.com  Thu Jun 21 19:45:05 2007
From: amadeo.bellotti at gmail.com (Amadeo Bellotti)
Date: Thu, 21 Jun 2007 13:45:05 -0400
Subject: [Tutor] Online Rock Paper Sizzors
Message-ID: <d7253a230706211045u513b6f47w8f9a4da6a7a08565@mail.gmail.com>

any body know where i start with this I want to be able to enter user names
and keep score for the persons wins and loses anybody know how i can do
this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070621/44857364/attachment.html 

From python at venix.com  Thu Jun 21 22:40:50 2007
From: python at venix.com (Lloyd Kvam)
Date: Thu, 21 Jun 2007 16:40:50 -0400
Subject: [Tutor] how can I compare a local directory or file with
	a	remote one
In-Reply-To: <Pine.LNX.4.63.0706210939020.2951@cs.wpi.edu>
References: <7d81675b0706201103s41ed926dq7fcbfd9a8bd10d11@mail.gmail.com>
	<D90B9C3B-A79B-4219-8D3E-A14BD2398B87@reedobrien.com>
	<1182431197.4092.179.camel@localhost.localdomain>
	<Pine.LNX.4.63.0706210939020.2951@cs.wpi.edu>
Message-ID: <1182458450.4092.208.camel@localhost.localdomain>

On Thu, 2007-06-21 at 09:47 -0400, Danny Yoo wrote:
> >> At first blush it sounds to me like you want rsync, as has been
> >> pointed out.  If on of the systems is running an OS that doesn't come
> >> with rsync... I have used http://www.vdesmedt.com/~vds2212/rsync.html
> >> to achieve the same result.
> >>
> >
> > When I need to deal with Windows computers, I sorely feel the lack of 
> > ssh, rsync, and sshfs.
> 
> 
> I know this is very Python-unspecific, but I might as well chime in: 
> there's a utility called "Unison" that's similar to rsync, and works on 
> Windows:
> 
>      http://www.cis.upenn.edu/~bcpierce/unison/

Unfortunately unison uses either ssh or an unsecured socket for
communicating over a network.  From their docs:

        Warning: The socket method is insecure: not only are the texts
        of your changes transmitted over the network in unprotected
        form, it is also possible for anyone in the world to connect to
        the server process and read out the contents of your filesystem!
        (Of course, to do this they must understand the protocol that
        Unison uses to communicate between client and server, but all
        they need for this is a copy of the Unison sources.) The socket
        method is provided only for expert users with specific needs;
        everyone else should use the ssh method.

Just to get a bit more Python related, I've used the urllib2 libraries
to make SSL connections to a DAV (also spelled WebDav) server.  This is
reasonably straightforward to program in Python, but the server side is
clumsy to setup.

-- 
Lloyd Kvam
Venix Corp


From alan.gauld at btinternet.com  Thu Jun 21 23:00:38 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 21 Jun 2007 22:00:38 +0100
Subject: [Tutor] Online Rock Paper Sizzors
References: <d7253a230706211045u513b6f47w8f9a4da6a7a08565@mail.gmail.com>
Message-ID: <f5eots$u1a$1@sea.gmane.org>

"Amadeo Bellotti" <amadeo.bellotti at gmail.com> wrote

> any body know where i start with this I want to be able to enter 
> user names
> and keep score for the persons wins and loses anybody know how i can 
> do
> this?

I recommend you write a web application.

There are many web frameworks available in Python from
basic CGI to Zope and all levels in between.

I use TurboGears which includes login and security as
part of the framework.

Now, what else do you not understand? If you ask more specific
questions you will get more specific answers. Also gicve us some
context.Are you an experienced programmer? Are you experienced
in writing web apps in some other language? In Python? At
what point are you stuck?

Or is it a homework assignment? If so we need to see your
attempts before giving hints.

HTH,

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



From chrispython at mac.com  Fri Jun 22 03:59:16 2007
From: chrispython at mac.com (chrispython at mac.com)
Date: Thu, 21 Jun 2007 18:59:16 -0700
Subject: [Tutor] using shelve
Message-ID: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>

I created a shelf called 'myshelf' and put two objects in it, a string and a list. When I open the shelf I get:

>>> d=shelve.open('/Users/development/Desktop/myshelf')
>>> d.keys()
['dir1', 'dir2']
>>> d
{'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 'dir1': ['.DS_Store', '.localized', 'access the latest version', 'Python Quick Reference.webloc', 'rssdb', 'workspace']}

It seems that when you use shelve.open(), it actually brings the entire shelf dictionary into memory, accessible through d.

What if you had 100 objects in myshelf, or 1000 or 100,000? Wouldn't it get bogged down?

If so, what is it good for and how would you store a large number of objects? (Storing strings and lists in an sql database is probably the way to go for this simple example, but what if  you had more complex objects?)

Thanks
Chris V.



From john at fouhy.net  Fri Jun 22 04:27:43 2007
From: john at fouhy.net (John Fouhy)
Date: Fri, 22 Jun 2007 14:27:43 +1200
Subject: [Tutor] using shelve
In-Reply-To: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
Message-ID: <5e58f2e40706211927o6766a96o140b73fd6b2d021@mail.gmail.com>

On 22/06/07, chrispython at mac.com <chrispython at mac.com> wrote:
> I created a shelf called 'myshelf' and put two objects in it, a string and a list. When I open the shelf I get:
>
> >>> d=shelve.open('/Users/development/Desktop/myshelf')
> >>> d.keys()
> ['dir1', 'dir2']
> >>> d
> {'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 'dir1': ['.DS_Store', '.localized', 'access the latest version', 'Python Quick Reference.webloc', 'rssdb', 'workspace']}
>
> It seems that when you use shelve.open(), it actually brings the entire shelf dictionary into memory, accessible through d.

Well ... all that tells me is that when you ask python for a string
representation of a shelf, it reads the entire thing.

> What if you had 100 objects in myshelf, or 1000 or 100,000? Wouldn't it get bogged down?

If you try to print out the whole thing, probably.  Let's try some test:

>>> import shelve
>>> d = shelve.open('test.shelf')
>>> for i in range(1000):
...  d[str(i)] = 'x'*i
...
>>> d.close()

Morpork:~/tmp repton$ ls -l test.shelf
-rw-r--r--   1 repton  repton       1M Jun 22 14:23 test.shelf

First, we'll measure how long it takes python to open the shelf using
shelve.open:

Morpork:~/tmp repton$ python -m timeit -s 'import shelve' 'd =
shelve.open("test.shelf")'
1000 loops, best of 3: 1.95 msec per loop

Now we'll measure how long it takes python to open a shelf and turn it
into a string:

Morpork:~/tmp repton$ python -m timeit -s 'import shelve' 'd =
shelve.open("test.shelf")' 'str(d)'
10 loops, best of 3: 51.5 msec per loop

So, that's about a factor of 25 difference.

HTH!

-- 
John.

From reed at reedobrien.com  Fri Jun 22 06:26:17 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Fri, 22 Jun 2007 00:26:17 -0400
Subject: [Tutor] using shelve
In-Reply-To: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
Message-ID: <83A86DC0-4635-459C-BEA3-BA0BE7DE2AFC@reedobrien.com>


On Jun 21, 2007, at 9:59 PM, chrispython at mac.com wrote:

> I created a shelf called 'myshelf' and put two objects in it, a  
> string and a list. When I open the shelf I get:
>
>>>> d=shelve.open('/Users/development/Desktop/myshelf')
>>>> d.keys()
> ['dir1', 'dir2']
>>>> d
> {'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 'dir1':  
> ['.DS_Store', '.localized', 'access the latest version', 'Python  
> Quick Reference.webloc', 'rssdb', 'workspace']}
>
> It seems that when you use shelve.open(), it actually brings the  
> entire shelf dictionary into memory, accessible through d.
>
> What if you had 100 objects in myshelf, or 1000 or 100,000?  
> Wouldn't it get bogged down?
>
> If so, what is it good for and how would you store a large number  
> of objects? (Storing strings and lists in an sql database is  
> probably the way to go for this simple example, but what if  you  
> had more complex objects?)
>
> Thanks
> Chris V.
>
>
>

have a gander at:
http://codeidol.com/python/python3/Databases-and-Persistence/

As well as the shelve docs.

~r
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/80001038/attachment.html 

From treloary_27 at hotmail.com  Fri Jun 22 09:13:52 2007
From: treloary_27 at hotmail.com (Nick Treloar)
Date: Fri, 22 Jun 2007 17:13:52 +1000
Subject: [Tutor] (no subject)
Message-ID: <BAY107-F1646A7780694FAD17E70819F170@phx.gbl>

im not sure why this progrm isnt running properly  one of the button wont 
open and it teel me a computer_guess is not defined here is my code

#NiCk TrEloaR PrOgRaMiNg Co.
#scissors paper rock
#10/6/07
from Tkinter import*

from random import choice

class Application(Frame):
    def __init__(self,master):
        """Initalize Frame."""
        Frame.__init__(self,master)
        self.grid()
        self.create_widget()
        self.computer_guess()

        #creating user indstructions
    def create_widget(self):
        #create description label
        Label(self,
              text="scissors paper rock "
              ).grid(row = 0,column = 0,sticky = W)

        #create the exit button
        self.exit_bttn = Button(self, text = "Exit", font = ("Arial", 12, 
"bold"), command = self.quit)
        self.exit_bttn.grid(row = 30, column = 0, sticky = E)

        #create the rock button
        self.rock_bttn = Button(self, text = "rock", font = ("Arial", 12, 
"bold"), command = self.rock)
        self.rock_bttn.grid(row = 1, column = 1, sticky = W)

        #create the scissors button
        self.scissors_bttn = Button(self, text = "scissors", font = 
("Arial", 12, "bold"), command = self.scissors)
        self.scissors_bttn.grid(row = 2, column = 2, sticky = W)

        #create the paper  button
        self.paper_bttn = Button(self, text = "paper", font = ("Arial", 12, 
"bold"), command = self.paper)
        self.paper_bttn.grid(row = 3, column = 3, sticky = W)





    def rock(self):
        value = "rock"
        computer_guess == random.choice(["scissors", "paper", "rock"])

        if computer_guess == "rock":
            Label(self,
                  text = "this is a draw!!", fg = "blue", font = ("Arial", 
14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        elif computer_guess == "paper":
            Label(self,
                  text = "you lose paper smothers rock", fg = "blue", font = 
("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        else:
            Label(self,
                  text = "you win rock smashes scissors", fg = "blue", font 
= ("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)




    def scissors(self):
        value = "scissors"
        computer_guess == random.choice(["scissors", "paper", "rock"])

        if computer_guess == "rock":
            Label(self,
                  text = "computer wins rock smashes scissors", fg = "blue", 
font = ("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        elif computer_guess == "paper":
            Label(self,
                  text = "you win rock smaches scissors", fg = "blue", font 
= ("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        else:
            Label(self,
                  text = "this is a draw", fg = "blue", font = ("Arial", 14, 
"bold"),
                  ).grid(row = 9, column = 0, sticky = W)



def paper(self):
        value = "paper"
        computer_guess == random.choice(["scissors", "paper", "rock"])

        if computer_guess == "rock":
            Label(self,
                  text = "yau win paper smothers rock", fg = "blue", font = 
("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        elif computer_guess == "paper":
            Label(self,
                  text = "this is a draw", fg = "blue", font = ("Arial", 14, 
"bold"),
                  ).grid(row = 9, column = 0, sticky = W)



        else:
            Label(self,
                  text = "computer wins scissors cut paper", fg = "blue", 
font = ("Arial", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)






root=Tk()
root.title("scissors paper rock")
root.geometry("600x600")
app = Application(root)

_________________________________________________________________
Advertisement: Ministry of Sound's Sessions 4 has arrived. Have a listen! 
http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=788&referral=hotmailtagline&URL=http://music.ninemsn.com.au/playlist.aspx?sectionid=2465&sectionname=artistfeature&subsectionid=9961&subsectionname=sessions4&categoryid=2602


From alan.gauld at btinternet.com  Fri Jun 22 09:43:06 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 22 Jun 2007 08:43:06 +0100
Subject: [Tutor] using shelve
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
Message-ID: <f5fuih$vph$1@sea.gmane.org>

<chrispython at mac.com> wrote 

>I created a shelf called 'myshelf' and put two objects in it, 
> a string and a list. When I open the shelf I get:

>>>> d
> {'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 
> 'dir1': ['.DS_Store', '.localized', 'access the latest version', 
> 'Python Quick Reference.webloc', 'rssdb', 'workspace']}
> 
> It seems that when you use shelve.open(), it actually 
> brings the entire shelf dictionary into memory, 
> accessible through d.

No, it seems that when you evaluate d it does that.
Remember that when you type an object reference 
at the >>> prompt Python evaluates it and prints 
the repr() of that object. The repr() of a shelve requires 
it's contents be fetched.

> What if you had 100 objects in myshelf, or 1000 or 100,000? 
> Wouldn't it get bogged down?

That would depend on how much RAM you have and how 
big the objects were. If we say a typical modern PC has 
512M and the average shelve entry takes up 1KB (actually 
quite high) then you can store 100,000 objects in RAM 
with impuny.  But in ffact shelve doesn't store everything 
in RAM so if you don't ask for everything at once so you 
can go quite a bit higher than that.

> If so, what is it good for and how would you store a large 
> number of objects? (Storing strings and lists in an sql 
> database is probably the way to go for this simple 
> example, but what if  you had more complex objects?)

A SQL database is the usual solution for large collections 
of complex objects. Shelve is good for basic persistence 
but its not good for managing complex relationships, and 
in particular for retrieval of objects using complex search
criteria. Thats where SQL comes in. There are OODBs 
available too, of varying quality and they can run OQL 
which is the OO version of SQL and can base queries 
on methods as well as data. (Zope comes with an ODB 
but I have no idea how capable it is.) (The url just posted 
by Reed is excellent for reviewing the pros/cons of all the 
various Python storage mechanisms - thanks Reed)

However many, many applications really only need a basic 
form of persistence where objects are stored to disk 
between executions of the program and for that shelve 
(and even basic pickle) is perfectly adequate.

HTH,

Alan G.


From alan.gauld at btinternet.com  Fri Jun 22 10:04:13 2007
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Fri, 22 Jun 2007 08:04:13 +0000 (GMT)
Subject: [Tutor] Online Rock Paper Sizzors
Message-ID: <759230.74954.qm@web86101.mail.ird.yahoo.com>

<Forwarding back to list>

----- Original Message ----
From: Amadeo Bellotti <amadeo.bellotti at gmail.com>
To: Alan Gauld <alan.gauld at btinternet.com>
Sent: Friday, 22 June, 2007 3:22:18 AM
Subject: Re: [Tutor] Online Rock Paper Sizzors

no this isn't a home work assignment. Ive never done web programming before i am pretty skilled in python i dont want an application like on a web browser. i want a client that each person can download. honestly i have no clue where to start with a web app once i get started i can probably take over


On 6/21/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
"Amadeo Bellotti" <amadeo.bellotti at gmail.com> wrote

> any body know where i start with this I want to be able to enter
> user names and keep score for the persons wins and loses anybody 
> know how i can  do this?

I recommend you write a web application.

There are many web frameworks available in Python from
basic CGI to Zope and all levels in between.

I use TurboGears which includes login and security as

part of the framework.

Now, what else do you not understand? If you ask more specific
questions you will get more specific answers. Also gicve us some
context.Are you an experienced programmer? Are you experienced

in writing web apps in some other language? In Python? At
what point are you stuck?

Or is it a homework assignment? If so we need to see your
attempts before giving hints.

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/20070622/c2fefb02/attachment.htm 

From vladoportos at vladoportos.sk  Fri Jun 22 11:39:20 2007
From: vladoportos at vladoportos.sk (Vladimir Strycek)
Date: Fri, 22 Jun 2007 11:39:20 +0200
Subject: [Tutor] SSH client for python ?
Message-ID: <467B98C8.50209@vladoportos.sk>

Hi all,

is there any nice ssh module for python ? for example if i wanna to 
write script which will connect to e.g 5 linux servers and execute some 
commands and at last save this output in file....

Any idea ?

Many thanks
Vladimir

From kent37 at tds.net  Fri Jun 22 13:10:44 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 22 Jun 2007 07:10:44 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <BAY107-F1646A7780694FAD17E70819F170@phx.gbl>
References: <BAY107-F1646A7780694FAD17E70819F170@phx.gbl>
Message-ID: <467BAE34.6020008@tds.net>

Nick Treloar wrote:
> im not sure why this progrm isnt running properly  one of the button wont 
> open and it teel me a computer_guess is not defined

Please include the exact error message and traceback when you report 
errors, they include much useful information.

Which button won't open?

Your __init__() method calls self.computer_guess() but there is no 
computer_guess() method, that is probably the source of the 
computer_guess error. I don't think you need that call at all since the 
guessing happens inside the rock, paper, scissors methods.

You should call root.mainloop() as the last line of your program, 
otherwise the buttons will not respond to clicks.

Kent

> here is my code
> 
> #NiCk TrEloaR PrOgRaMiNg Co.
> #scissors paper rock
> #10/6/07
> from Tkinter import*
> 
> from random import choice
> 
> class Application(Frame):
>     def __init__(self,master):
>         """Initalize Frame."""
>         Frame.__init__(self,master)
>         self.grid()
>         self.create_widget()
>         self.computer_guess()
> 
>         #creating user indstructions
>     def create_widget(self):
>         #create description label
>         Label(self,
>               text="scissors paper rock "
>               ).grid(row = 0,column = 0,sticky = W)
> 
>         #create the exit button
>         self.exit_bttn = Button(self, text = "Exit", font = ("Arial", 12, 
> "bold"), command = self.quit)
>         self.exit_bttn.grid(row = 30, column = 0, sticky = E)
> 
>         #create the rock button
>         self.rock_bttn = Button(self, text = "rock", font = ("Arial", 12, 
> "bold"), command = self.rock)
>         self.rock_bttn.grid(row = 1, column = 1, sticky = W)
> 
>         #create the scissors button
>         self.scissors_bttn = Button(self, text = "scissors", font = 
> ("Arial", 12, "bold"), command = self.scissors)
>         self.scissors_bttn.grid(row = 2, column = 2, sticky = W)
> 
>         #create the paper  button
>         self.paper_bttn = Button(self, text = "paper", font = ("Arial", 12, 
> "bold"), command = self.paper)
>         self.paper_bttn.grid(row = 3, column = 3, sticky = W)
> 
> 
> 
> 
> 
>     def rock(self):
>         value = "rock"
>         computer_guess == random.choice(["scissors", "paper", "rock"])
> 
>         if computer_guess == "rock":
>             Label(self,
>                   text = "this is a draw!!", fg = "blue", font = ("Arial", 
> 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         elif computer_guess == "paper":
>             Label(self,
>                   text = "you lose paper smothers rock", fg = "blue", font = 
> ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         else:
>             Label(self,
>                   text = "you win rock smashes scissors", fg = "blue", font 
> = ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
> 
>     def scissors(self):
>         value = "scissors"
>         computer_guess == random.choice(["scissors", "paper", "rock"])
> 
>         if computer_guess == "rock":
>             Label(self,
>                   text = "computer wins rock smashes scissors", fg = "blue", 
> font = ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         elif computer_guess == "paper":
>             Label(self,
>                   text = "you win rock smaches scissors", fg = "blue", font 
> = ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         else:
>             Label(self,
>                   text = "this is a draw", fg = "blue", font = ("Arial", 14, 
> "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
> def paper(self):
>         value = "paper"
>         computer_guess == random.choice(["scissors", "paper", "rock"])
> 
>         if computer_guess == "rock":
>             Label(self,
>                   text = "yau win paper smothers rock", fg = "blue", font = 
> ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         elif computer_guess == "paper":
>             Label(self,
>                   text = "this is a draw", fg = "blue", font = ("Arial", 14, 
> "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
>         else:
>             Label(self,
>                   text = "computer wins scissors cut paper", fg = "blue", 
> font = ("Arial", 14, "bold"),
>                   ).grid(row = 9, column = 0, sticky = W)
> 
> 
> 
> 
> 
> 
> root=Tk()
> root.title("scissors paper rock")
> root.geometry("600x600")
> app = Application(root)
> 
> _________________________________________________________________
> Advertisement: Ministry of Sound's Sessions 4 has arrived. Have a listen! 
> http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=788&referral=hotmailtagline&URL=http://music.ninemsn.com.au/playlist.aspx?sectionid=2465&sectionname=artistfeature&subsectionid=9961&subsectionname=sessions4&categoryid=2602
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From rabidpoobear at gmail.com  Fri Jun 22 13:15:39 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Fri, 22 Jun 2007 06:15:39 -0500
Subject: [Tutor] (no subject)
In-Reply-To: <467BAE34.6020008@tds.net>
References: <BAY107-F1646A7780694FAD17E70819F170@phx.gbl>
	<467BAE34.6020008@tds.net>
Message-ID: <467BAF5B.7030605@gmail.com>

Kent Johnson wrote:
> Nick Treloar wrote:
>   
>> im not sure why this progrm isnt running properly  one of the button wont 
>> open and it teel me a computer_guess is not defined
>>     
>
> Please include the exact error message and traceback when you report 
> errors, they include much useful information.
>
> Which button won't open?
>
> Your __init__() method calls self.computer_guess() but there is no 
> computer_guess() method, that is probably the source of the 
> computer_guess error. I don't think you need that call at all since the 
> guessing happens inside the rock, paper, scissors methods.
>
> You should call root.mainloop() as the last line of your program, 
> otherwise the buttons will not respond to clicks.
>
> Kent
>   
Also, PLEASE USE A SUBJECT.
Whenever another (no subject) thread starts up, I have to scroll up 2 
pages in my mail reader every time there's a new message.
it doesn't even have to be a meaningful subject.  Just anything but (no 
subject.)
thanks,
-Luke

From kent37 at tds.net  Fri Jun 22 13:17:10 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 22 Jun 2007 07:17:10 -0400
Subject: [Tutor] Online Rock Paper Sizzors
In-Reply-To: <759230.74954.qm@web86101.mail.ird.yahoo.com>
References: <759230.74954.qm@web86101.mail.ird.yahoo.com>
Message-ID: <467BAFB6.6090805@tds.net>

> From: Amadeo Bellotti <amadeo.bellotti at gmail.com>
> 
> no this isn't a home work assignment. Ive never done web programming 
> before i am pretty skilled in python i dont want an application like on 
> a web browser. i want a client that each person can download. honestly i 
> have no clue where to start with a web app once i get started i can 
> probably take over

A downloadable client is an application like any other. Since you know 
Python you can start with that. You can use the pickle module to keep a 
list of high scores.

Why do you call this a web app if it is downloadable? How will it be 
different from a standalone application? If you want the high scores to 
be shared between different users you will have to make the application 
talk to a server of some kind. A simple way to do this is by making 
requests to a web server. You could also use XML-RPC. Python has modules 
to support both of these.

Kent

> 
> On 6/21/07, *Alan Gauld* <alan.gauld at btinternet.com 
> <mailto:alan.gauld at btinternet.com>> wrote:
> 
>     "Amadeo Bellotti" <amadeo.bellotti at gmail.com
>     <mailto:amadeo.bellotti at gmail.com>> wrote
> 
>      > any body know where i start with this I want to be able to enter
>      > user names and keep score for the persons wins and loses anybody
>      > know how i can  do this?
> 
>     I recommend you write a web application.
> 
>     There are many web frameworks available in Python from
>     basic CGI to Zope and all levels in between.
> 
>     I use TurboGears which includes login and security as
>     part of the framework.
> 
>     Now, what else do you not understand? If you ask more specific
>     questions you will get more specific answers. Also gicve us some
>     context.Are you an experienced programmer? Are you experienced
>     in writing web apps in some other language? In Python? At
>     what point are you stuck?
> 
>     Or is it a homework assignment? If so we need to see your
>     attempts before giving hints.
> 
>     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 <mailto: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  Fri Jun 22 13:26:32 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 22 Jun 2007 07:26:32 -0400
Subject: [Tutor] using shelve
In-Reply-To: <83A86DC0-4635-459C-BEA3-BA0BE7DE2AFC@reedobrien.com>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
	<83A86DC0-4635-459C-BEA3-BA0BE7DE2AFC@reedobrien.com>
Message-ID: <467BB1E8.1080903@tds.net>

Reed O'Brien wrote:
> have a gander at:
> http://codeidol.com/python/python3/Databases-and-Persistence/

That URL points to a (presumably) stolen copy of the book Programming 
Python by Mark Lutz. If you like it I hope you will buy a copy.
http://www.oreilly.com/catalog/python3/index.html

They even took the promotional text from O'Reilly's web site! Compare
http://codeidol.com/python/ with the second paragraph from
http://www.oreilly.com/catalog/python3/index.html#top

Kent

From datulaida.ali at gmail.com  Fri Jun 22 10:36:15 2007
From: datulaida.ali at gmail.com (datulaida ali)
Date: Fri, 22 Jun 2007 16:36:15 +0800
Subject: [Tutor] Apple Pie Parser in Python
Message-ID: <3b927740706220136p7ca80119m3da3a35d6edde54b@mail.gmail.com>

hi,
1) how to integrate apple pie parser with python?.. any suggestion?

2) how to import or integrate .exe file in python?

tq..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/56d13d66/attachment.html 

From kent37 at tds.net  Fri Jun 22 13:31:50 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 22 Jun 2007 07:31:50 -0400
Subject: [Tutor] SSH client for python ?
In-Reply-To: <467B98C8.50209@vladoportos.sk>
References: <467B98C8.50209@vladoportos.sk>
Message-ID: <467BB326.8060906@tds.net>

Vladimir Strycek wrote:
> Hi all,
> 
> is there any nice ssh module for python ? for example if i wanna to 
> write script which will connect to e.g 5 linux servers and execute some 
> commands and at last save this output in file....

http://article.gmane.org/gmane.comp.python.tutor/40895/

Kent

From alan.gauld at btinternet.com  Fri Jun 22 12:23:14 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 22 Jun 2007 11:23:14 +0100
Subject: [Tutor] Online Rock Paper Sizzors
References: <759230.74954.qm@web86101.mail.ird.yahoo.com>
Message-ID: <f5g7uo$vl6$1@sea.gmane.org>

> From: Amadeo Bellotti <amadeo.bellotti at gmail.com>
> no this isn't a home work assignment.

Ok, Just checking :-)

> Ive never done web programming before i am pretty skilled
> in python i dont want an application like on a web browser.

OK, That would have been the simplest form of online game but...

> i want a client that each person can download.

OK, I assume from this that you want a multi player
game - for rock,paper,scissors I assume multi = 2? - rather
than just an interactive game against the computer?

> honestly i have no clue where to start with a web app

OK, If we are going for a networked game between
multiple users you have a choice to run a server centrally
with all clients connecting to that or to run on a peer to per
basis with the two participating machines forming a direct
connection. The latter is easy to program for the game
but more complex to set up the initial configuration. A
central server makes the game slightly more comlex
but setup is easier.

I'd probably opt for the server approach but keep it really
simple initially. Only allow two connections and simply
relay the results. This can all be done using simple
sockets (see my network programming topic on my tutor).

The sequence will be something like:

server awaiting connections
client A connects, server gives back (empty) list of other clients
client B connects,
server notifies all clients of user list
client B challenges A (or vice versa)
server notifies A that he has been challenged
A accepts and server henceforth refuses any more connections
server asks players to select a weapon
clients send responses
server compares responses and sends notification to both cliernts of 
score
repeat for as many turns as desired then report final score
open up for more connections
client C connects
server notifies all clients of new user list
client A challenges C
repeat as above...

Hopefully that's enough to give you somne ideas and get started.
Once you get that working you can enhance it to support multiple
games at once etc. Keep high scores, league tables etc etc.
Also you can introduce security with logins etc.

But get the basic game structure working first.

HTH,


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



From kent37 at tds.net  Fri Jun 22 13:37:18 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 22 Jun 2007 07:37:18 -0400
Subject: [Tutor] Apple Pie Parser in Python
In-Reply-To: <3b927740706220136p7ca80119m3da3a35d6edde54b@mail.gmail.com>
References: <3b927740706220136p7ca80119m3da3a35d6edde54b@mail.gmail.com>
Message-ID: <467BB46E.5090601@tds.net>

datulaida ali wrote:
> hi,
> 1) how to integrate apple pie parser with python?.. any suggestion?

Apparently this is a C program. If it includes a library version you 
might be able to interface with it using the ctypes module.
> 
> 2) how to import or integrate .exe file in python?

os.system() or the functions in the subprocess module.

Kent

From reed at reedobrien.com  Fri Jun 22 14:46:15 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Fri, 22 Jun 2007 08:46:15 -0400
Subject: [Tutor] using shelve
In-Reply-To: <467BB1E8.1080903@tds.net>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
	<83A86DC0-4635-459C-BEA3-BA0BE7DE2AFC@reedobrien.com>
	<467BB1E8.1080903@tds.net>
Message-ID: <9CD330CD-003C-492B-9AAE-5F47A0A54728@reedobrien.com>

On Jun 22, 2007, at 7:26 AM, Kent Johnson wrote:

> Reed O'Brien wrote:
>> have a gander at:
>> http://codeidol.com/python/python3/Databases-and-Persistence/
>
> That URL points to a (presumably) stolen copy of the book  
> Programming Python by Mark Lutz. If you like it I hope you will buy  
> a copy.
> http://www.oreilly.com/catalog/python3/index.html
>
> They even took the promotional text from O'Reilly's web site! Compare
> http://codeidol.com/python/ with the second paragraph from
> http://www.oreilly.com/catalog/python3/index.html#top
>
> Kent


Thanks for the heads up, Kent.  I didn't realize that was a copy of  
Lutz's book.  I sent notice to infringement at oreilly.com.
It did seem like an awfully rich comparison of python persistence  
options.

If they follow up with me I will follow up with the list.

~r

From freebsd at scottevil.com  Fri Jun 22 16:12:34 2007
From: freebsd at scottevil.com (Scott Oertel)
Date: Fri, 22 Jun 2007 09:12:34 -0500
Subject: [Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"
In-Reply-To: <1181816053.e051f8f93c8aa@mail.bg>
References: <mailman.29516.1181765640.32030.tutor@python.org>
	<1181816053.e051f8f93c8aa@mail.bg>
Message-ID: <467BD8D2.9020908@scottevil.com>

emilia12 at mail.bg wrote:
> hi list,
>
> how to choose between "#!/usr/bin/env python" and
> "#!/usr/local/bin/python" in the beginning of the script ?
> e.
>
>
>
> -----------------------------
>
> SCENA - ???????????? ????????? ???????? ?? ??????? ??????????? ? ??????????.
> http://www.bgscena.com/
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   

One of the main dis-advantages to using '/usr/bin/env python' is that
you have to either A) make sure the environment is initialized, or B) 
initialize the environment  manually before executing the script.  If
you, for example, want to use a python script at boot time, before the
environment is initialized, i strongly recommend using an absolute path.


-Scott Oertel


From broek at cc.umanitoba.ca  Fri Jun 22 16:57:02 2007
From: broek at cc.umanitoba.ca (Brian van den Broek)
Date: Fri, 22 Jun 2007 10:57:02 -0400
Subject: [Tutor] subprocess and launching an editor
Message-ID: <467BE33E.9010403@cc.umanitoba.ca>

Hi all,

I want to have a script launch an editor open to a particular file and 
wait until that editor has closed before continuing. The aim is to 
allow the user to make edits to the file, have to script know that the 
edits are completed, and then make use of the newly saved file contents.

gedit is the default text editor on my ubuntu feisty system, so in the 
first instance, I've tried to do this with gedit. The subprocess.call:

 >>> subprocess.call("gedit somefilename", shell=True)

works just fine *provided* that no instance of gedit is running when I 
invoke .call. However, if there is a gedit window up and running 
(there usually is on my system ;-), the .call immediately returns exit 
status 0:

 >>> subprocess.Popen("ps -e|grep gedit", shell=True)
<subprocess.Popen object at 0xb7d06b4c>
 >>> 26066 pts/2    00:00:01 gedit

 >>> subprocess.call("gedit somefilename", shell=True)
0
 >>> # The exit code is produced instantaneously

Interestingly, it works just fine if I use emacs in place of gedit, 
irrespective of whether emacs was running before the subprocess.call 
invocation or not. Is there any way to get it to work with gedit as it 
is with emacs?

I am largely ignorant of the family of modules which subprocess was 
designed to replace, and also of the details of processes on linux. 
(In particular, I've no clue why gedit and emacs behave differently in 
this respect.)

Thanks and best,

Brian vdB

From jason.massey at gmail.com  Fri Jun 22 17:36:31 2007
From: jason.massey at gmail.com (Jason Massey)
Date: Fri, 22 Jun 2007 10:36:31 -0500
Subject: [Tutor] subprocess and launching an editor
In-Reply-To: <467BE33E.9010403@cc.umanitoba.ca>
References: <467BE33E.9010403@cc.umanitoba.ca>
Message-ID: <7e3eab2c0706220836l3662c517m41a06f2bfa18a78e@mail.gmail.com>

I'm running Feisty as well.

I launched python in two separate consoles and tried this:

1st console
----------------
>>>import subprocess
>>>subprocess.call('gedit --new-window window1',shell=True)

gedit launches with a blank file called window1.  The python shell is now
waiting for gedit to exit before it does anything else.

2nd console
---------------
>>>import subprocess
>>>subprocess.call('gedit --new-window window2',shell=True)

Another instance of gedit launches with a blank file called window2.  The
difference here is that the 2nd python shell instantly returns an exit code
of 0.

So you can definately launch multiple instances, but I'm not sure how you
would determine when the user was done editing the file after the first
instance of gedit has been launched.

Perhaps you could use this:

http://live.gnome.org/Gedit/PythonPluginHowTo

If you're going to stick with gedit.

On 6/22/07, Brian van den Broek <broek at cc.umanitoba.ca> wrote:
>
> Hi all,
>
> I want to have a script launch an editor open to a particular file and
> wait until that editor has closed before continuing. The aim is to
> allow the user to make edits to the file, have to script know that the
> edits are completed, and then make use of the newly saved file contents.
>
> gedit is the default text editor on my ubuntu feisty system, so in the
> first instance, I've tried to do this with gedit. The subprocess.call:
>
> >>> subprocess.call("gedit somefilename", shell=True)
>
> works just fine *provided* that no instance of gedit is running when I
> invoke .call. However, if there is a gedit window up and running
> (there usually is on my system ;-), the .call immediately returns exit
> status 0:
>
> >>> subprocess.Popen("ps -e|grep gedit", shell=True)
> <subprocess.Popen object at 0xb7d06b4c>
> >>> 26066 pts/2    00:00:01 gedit
>
> >>> subprocess.call("gedit somefilename", shell=True)
> 0
> >>> # The exit code is produced instantaneously
>
> Interestingly, it works just fine if I use emacs in place of gedit,
> irrespective of whether emacs was running before the subprocess.call
> invocation or not. Is there any way to get it to work with gedit as it
> is with emacs?
>
> I am largely ignorant of the family of modules which subprocess was
> designed to replace, and also of the details of processes on linux.
> (In particular, I've no clue why gedit and emacs behave differently in
> this respect.)
>
> Thanks and best,
>
> Brian vdB
> _______________________________________________
> 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/20070622/183b9683/attachment.html 

From alan.gauld at btinternet.com  Fri Jun 22 18:17:55 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 22 Jun 2007 17:17:55 +0100
Subject: [Tutor] subprocess and launching an editor
References: <467BE33E.9010403@cc.umanitoba.ca>
Message-ID: <f5gsnp$die$1@sea.gmane.org>

"Brian van den Broek" <broek at cc.umanitoba.ca> wrote

> gedit is the default text editor on my ubuntu feisty system, so in 
> the
> first instance, I've tried to do this with gedit. The 
> subprocess.call:
>
> >>> subprocess.call("gedit somefilename", shell=True)
>

You should probably check the VISUAL and EDITOR environment
settings to find out the users preferred editor. Traditionally VISUAL
outguns EDITOR...

> works just fine *provided* that no instance of gedit is running when 
> I
> invoke .call.

That must be a feature of gedit that it only allows one instance
of gedit to run at a time.

What happens if you try to invoke two instances from an OS prompt?

> Interestingly, it works just fine if I use emacs in place of gedit,

Yep, emacs is happy with multiple instances (or can use emacs
server to ensure multiple calls go to the same client to save 
resources)

> Is there any way to get it to work with gedit as it
> is with emacs?

Change gedit I suspect. At least its open source!

> (In particular, I've no clue why gedit and emacs behave differently 
> in

Almost certainly this is behaviour built into the application.
subprocess.call is pretty much a straight equivalent to os.system
and just returns whatever the app returns...

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



From amadeo.bellotti at gmail.com  Fri Jun 22 19:31:55 2007
From: amadeo.bellotti at gmail.com (Amadeo Bellotti)
Date: Fri, 22 Jun 2007 13:31:55 -0400
Subject: [Tutor] Online Rock Paper Sizzors
In-Reply-To: <f5g7uo$vl6$1@sea.gmane.org>
References: <759230.74954.qm@web86101.mail.ird.yahoo.com>
	<f5g7uo$vl6$1@sea.gmane.org>
Message-ID: <d7253a230706221031v5d285f8i44e1603102ba0640@mail.gmail.com>

thank you very much ill start on it right away its just going to be a text
based game client cause i want it to work on my old computer Pentium 1

On 6/22/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> > From: Amadeo Bellotti <amadeo.bellotti at gmail.com>
> > no this isn't a home work assignment.
>
> Ok, Just checking :-)
>
> > Ive never done web programming before i am pretty skilled
> > in python i dont want an application like on a web browser.
>
> OK, That would have been the simplest form of online game but...
>
> > i want a client that each person can download.
>
> OK, I assume from this that you want a multi player
> game - for rock,paper,scissors I assume multi = 2? - rather
> than just an interactive game against the computer?
>
> > honestly i have no clue where to start with a web app
>
> OK, If we are going for a networked game between
> multiple users you have a choice to run a server centrally
> with all clients connecting to that or to run on a peer to per
> basis with the two participating machines forming a direct
> connection. The latter is easy to program for the game
> but more complex to set up the initial configuration. A
> central server makes the game slightly more comlex
> but setup is easier.
>
> I'd probably opt for the server approach but keep it really
> simple initially. Only allow two connections and simply
> relay the results. This can all be done using simple
> sockets (see my network programming topic on my tutor).
>
> The sequence will be something like:
>
> server awaiting connections
> client A connects, server gives back (empty) list of other clients
> client B connects,
> server notifies all clients of user list
> client B challenges A (or vice versa)
> server notifies A that he has been challenged
> A accepts and server henceforth refuses any more connections
> server asks players to select a weapon
> clients send responses
> server compares responses and sends notification to both cliernts of
> score
> repeat for as many turns as desired then report final score
> open up for more connections
> client C connects
> server notifies all clients of new user list
> client A challenges C
> repeat as above...
>
> Hopefully that's enough to give you somne ideas and get started.
> Once you get that working you can enhance it to support multiple
> games at once etc. Keep high scores, league tables etc etc.
> Also you can introduce security with logins etc.
>
> But get the basic game structure working first.
>
> 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/20070622/b862c036/attachment.htm 

From alan.gauld at btinternet.com  Fri Jun 22 18:21:43 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 22 Jun 2007 17:21:43 +0100
Subject: [Tutor] subprocess and launching an editor
References: <467BE33E.9010403@cc.umanitoba.ca>
	<7e3eab2c0706220836l3662c517m41a06f2bfa18a78e@mail.gmail.com>
Message-ID: <f5gsut$edv$1@sea.gmane.org>


"Jason Massey" <jason.massey at gmail.com> wrote

> gedit launches with a blank file called window1.  The python shell 
> is now
> waiting for gedit to exit before it does anything else.
>
> 2nd console
> ---------------
>>>>import subprocess
>>>>subprocess.call('gedit --new-window window2',shell=True)
>
> Another instance of gedit launches with a blank file called window2. 
> The
> difference here is that the 2nd python shell instantly returns an 
> exit code
> of 0.

Interesting. I suspect this sets a second thread of the same process
off. Can you do a ps to see how many gedit processes are running?

The Gedit Python link might be worth investigatying if you insist
on using gedit. But then your solution might not work for anyone
else... I do with apps wouldn't try to be too clever.

Alan G.




From Yang at pyboo.com  Fri Jun 22 22:22:51 2007
From: Yang at pyboo.com (Yang Yang)
Date: Sat, 23 Jun 2007 04:22:51 +0800
Subject: [Tutor] Hi,every one
Message-ID: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>

i am a newman for python world

i have some word want to ask


1.what is the best book for python study.

2.what's is the better IDE for python



Thanks for all
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070623/c18d71a6/attachment.htm 

From mi1492 at cox.net  Fri Jun 22 23:03:51 2007
From: mi1492 at cox.net (Lucio Arteaga)
Date: Fri, 22 Jun 2007 16:03:51 -0500
Subject: [Tutor] executionable file
Message-ID: <001201c7b510$d602cb40$6400a8c0@bilbilis>

Can any body tell me how I can make an executive file from a file.py?
My knowledge of binaries is minimum. So please if you are sending  me some method please do not be too sophisticated.
Lucio Arteaga
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/0defdfd1/attachment.htm 

From keridee at jayco.net  Fri Jun 22 19:34:06 2007
From: keridee at jayco.net (Jacob S.)
Date: Fri, 22 Jun 2007 17:34:06 -0000
Subject: [Tutor] (no subject)
References: <BAY107-F1646A7780694FAD17E70819F170@phx.gbl>
Message-ID: <013d01c7b4f3$8cac1950$05fce004@JSLAPTOP>

Here the same thing

>    def rock(self):
>        value = "rock"
>        computer_guess == random.choice(["scissors", "paper", "rock"])

>    def scissors(self):
>        value = "scissors"
>        computer_guess == random.choice(["scissors", "paper", "rock"])

> def paper(self):
>        value = "paper"
>        computer_guess == random.choice(["scissors", "paper", "rock"])

In all three functions you have the line
computer_guess == random.choice(["scissors", "paper", "rock"])

This line compares the (undefined) variable "computer_guess" against the 
result of the function call to random.choice. Even if computer_guess was 
defined, it would still discard the result of the comparison. Surely you 
mean to use only *one* equals sign. 


From finalyugi at sapo.pt  Fri Jun 22 23:49:12 2007
From: finalyugi at sapo.pt (Rolando Pereira)
Date: Fri, 22 Jun 2007 22:49:12 +0100
Subject: [Tutor] Hi,every one
In-Reply-To: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>
References: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>
Message-ID: <467C43D8.4010907@sapo.pt>

Yang Yang escreveu:
> i am a newman for python world
> 
> i have some word want to ask
> 
> 
> 1.what is the best book for python study.
> 

I like Dive into Python.
( http://www.diveintopython.org/ )

> 2.what's is the better IDE for python
> 

That depends on what OS you are.

> 
> Thanks for all
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
                       _
ASCII ribbon campaign ( )
 - against HTML email  X
             & vCards / \

From jrmorrisnc at gmail.com  Sat Jun 23 02:00:25 2007
From: jrmorrisnc at gmail.com (John Morris)
Date: Fri, 22 Jun 2007 20:00:25 -0400
Subject: [Tutor] executionable file
In-Reply-To: <001201c7b510$d602cb40$6400a8c0@bilbilis>
References: <001201c7b510$d602cb40$6400a8c0@bilbilis>
Message-ID: <6216eba0706221700qaa0a55co1482f21f02a6a6e7@mail.gmail.com>

On 6/22/07, Lucio Arteaga <mi1492 at cox.net> wrote:
>
>  Can any body tell me how I can make an executive file from a file.py?
> My knowledge of binaries is minimum. So please if you are sending  me some
> method please do not be too sophisticated.
> Lucio Arteaga
>

On Windows:
http://www.py2exe.org/

I don't know of a equivalent for Unix/Linux platforms, however.

HTH,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/9dfee8f8/attachment.html 

From alan.gauld at btinternet.com  Sat Jun 23 02:16:14 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 23 Jun 2007 01:16:14 +0100
Subject: [Tutor] executionable file
References: <001201c7b510$d602cb40$6400a8c0@bilbilis>
Message-ID: <f5hool$70r$1@sea.gmane.org>

"Lucio Arteaga" <mi1492 at cox.net> wrote
> Can any body tell me how I can make an executive file from a 
> file.py?

Assuming you are on Windows you can use py2exe but
its non trivial to use. (Not hard, just not trivial)

But first ask why you need to.
I've been using Python for over 10 years now and never once needed
to do this. (I did it once just to see how, but I've never *needed* to
do it)

Once Python is installed you can run any script by just double
clicking in explorer.

And you can build installers that will install python if its not
already there and then add your script. There are few cases
where you really need an exe file. IMHO.

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



From alan.gauld at btinternet.com  Sat Jun 23 02:11:53 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 23 Jun 2007 01:11:53 +0100
Subject: [Tutor] Hi,every one
References: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>
Message-ID: <f5hogg$6cp$1@sea.gmane.org>

"Yang Yang" <Yang at pyboo.com> wrote 

>i am a newman for python world

Are you new to programming? 
Or are you just new to python?

The answer to that question will affect the 
answers to the next.
 
> 1.what is the best book for python study.

Depends on above.
If you are brand new to programming I 
recommend you follow some of the online 
tutorials before buying a book.

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

You might even like mine! :-)

If you can program then start with the official 
tutorial on python.org then try one of several 
more advanced books:

Programming Python by Lutz
Dive into Python (available online)
Python Cookbook (common recipes)

Python in a Nutshell (best reference book)
Python Essential Reference (a close second)

And there are several good specialist books if 
you have a particular area of interest:

Python Network Programming
Text Processing in Python
and others:
TurboGears & Django web frameworks
TKinter, wxPython and pyQt GUI toolkits all have books
XML, Win32 etc etc.

> 2.what's is the better IDE for python

Thats a religious question with strong views.
People have different styles.
Start with IDLE or Pythonwin, see whats missing 
and find something that fills your needs.

Eclipse with PyDev and SPE are both striongly 
recommended by their fans. The former needs 
a powerful PC.

I still prefer a combination of:
vim, 
pyCrust shell and 
an OS console

YMMV,

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


From flaper87 at gmail.com  Sat Jun 23 02:54:28 2007
From: flaper87 at gmail.com (Flaper87)
Date: Fri, 22 Jun 2007 20:54:28 -0400
Subject: [Tutor] Catch event's on my computer
Message-ID: <da1c02120706221754t188ac398h49e79112c2d14d53@mail.gmail.com>

Hi everybody!!

First i have to say that my english may have some mistakes, so i'm sorry if
i commit any

my question is, How can i catch every event that have been done with the
pointer or the keyboard in my computer?

I mean, i need to catch every movement of the pointer, what its position is
everything. I've read that i can do that using my native system API, and
also pygame.

My idea is to do this with a thread. What can you suggest me?

Grettings and Thank's

-- 
Flavio Percoco Premoli, A.K.A. [Flaper87]
http://www.flaper87.com
Usuario Linux registrado #436538
Geek by nature, Linux by choice, Debian of course.
Key Fingerprint: CFC0 C67D FF73 463B 7E55  CF43 25D1 E75B E2DB 15C7

-- 
Flavio Percoco Premoli, A.K.A. [Flaper87]
http://www.flaper87.com
Usuario Linux registrado #436538
Geek by nature, Linux by choice, Debian of course.
Key Fingerprint: CFC0 C67D FF73 463B 7E55  CF43 25D1 E75B E2DB 15C7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/fb87c141/attachment.htm 

From David.Heiser at intelliden.com  Sat Jun 23 07:49:02 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Fri, 22 Jun 2007 23:49:02 -0600
Subject: [Tutor] Hi,every one
In-Reply-To: <f5hogg$6cp$1@sea.gmane.org>
References: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438> 
	<f5hogg$6cp$1@sea.gmane.org>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3C6@csoexc02.intelliden.net>

 
I seldom hear anyone mention "The Quick Python Book" by Daryl Harms and
Kenneth McDonald (Manning). It was the book I found most useful when I
started programming Python. I still keep it nearby and refer to it
occasionally as a familiar memory refresher, even though I have been
writing Python code every day for 6 years.


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Alan Gauld
Sent: Friday, June 22, 2007 6:12 PM
To: tutor at python.org
Subject: Re: [Tutor] Hi,every one

"Yang Yang" <Yang at pyboo.com> wrote 

>i am a newman for python world

Are you new to programming? 
Or are you just new to python?

The answer to that question will affect the answers to the next.
 
> 1.what is the best book for python study.

Depends on above.
If you are brand new to programming I
recommend you follow some of the online tutorials before buying a book.

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

You might even like mine! :-)

If you can program then start with the official tutorial on python.org
then try one of several more advanced books:

Programming Python by Lutz
Dive into Python (available online)
Python Cookbook (common recipes)

Python in a Nutshell (best reference book) Python Essential Reference (a
close second)

And there are several good specialist books if you have a particular
area of interest:

Python Network Programming
Text Processing in Python
and others:
TurboGears & Django web frameworks
TKinter, wxPython and pyQt GUI toolkits all have books XML, Win32 etc
etc.

> 2.what's is the better IDE for python

Thats a religious question with strong views.
People have different styles.
Start with IDLE or Pythonwin, see whats missing and find something that
fills your needs.

Eclipse with PyDev and SPE are both striongly recommended by their fans.
The former needs a powerful PC.

I still prefer a combination of:
vim,
pyCrust shell and
an OS console

YMMV,

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070622/ddc60083/attachment.htm 

From alan.gauld at btinternet.com  Sat Jun 23 10:16:13 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 23 Jun 2007 09:16:13 +0100
Subject: [Tutor] Catch event's on my computer
References: <da1c02120706221754t188ac398h49e79112c2d14d53@mail.gmail.com>
Message-ID: <f5iksk$452$1@sea.gmane.org>

"Flaper87" <flaper87 at gmail.com> wrote

> I mean, i need to catch every movement of the pointer, what its 
> position is
> everything. I've read that i can do that using my native system API, 
> and
> also pygame.

I don't know about pyGame but certainly the OS API should allow it.
What OS/GUI are you using? That will make a difference.

If its Windows then the ctypes module will give you access
to the Win32 API. You will need to refer to the Microsoft
documentation to figure out which API calls you need and
how to intercept them.

Its all pretty easy capturing them for your own app, but when
you try to track events outside your app it becomes pretty
low level and depends a lot on the individual OS, so we
can't really give general advice.

> My idea is to do this with a thread. What can you suggest me?

I'm not sure why a thread would help since its event driven.
You should just be able to catch the events as they come
in and update a data store of some kind. If anything I'd expect
the processing of the data store to be more likely running in
a thread.


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



From fburden at fastmail.fm  Sat Jun 23 04:55:51 2007
From: fburden at fastmail.fm (Frank Burden)
Date: Sat, 23 Jun 2007 12:55:51 +1000
Subject: [Tutor]  SPE - Stani's Python Editor ?
References: 7.0.1.0.2.20061231213332.06853e20@rcblue.com
Message-ID: <467C8BB7.8010401@fastmail.fm>

Hi Dick

I read your post and  wonder if you could mail me a copy of SPE for 
Python 2.5

//SPE-0.8.3.c.win32-py2.5.exe

I'd be most grateful as I've just switched from Python 2.3 to 2.5 and miss Stani's lovely editor.

Cheers

Frank

Frank Burden
548 Canning Street
Carlton North 
VIC 3054
Australia
P: +613 9380 9311
F: +613 8611 7960
M: 0408 306 466
e: fburden at fastmail.fm
//



From flaper87 at gmail.com  Sat Jun 23 18:44:52 2007
From: flaper87 at gmail.com (Flaper87)
Date: Sat, 23 Jun 2007 12:44:52 -0400
Subject: [Tutor] pyhook for Linux
Message-ID: <da1c02120706230944xaedbc02hbc67b0cc5529f4e7@mail.gmail.com>

Hi!

Does anyone knows an equivalence of pyhook for linux?

I need to catch the events of the mose (even the simple movement, or when it
focus an icon on Desktop), and the events of the keyboard.

Thank's

-- 
Flavio Percoco Premoli, A.K.A. [Flaper87]
http://www.flaper87.com
Usuario Linux registrado #436538
Geek by nature, Linux by choice, Debian of course.
Key Fingerprint: CFC0 C67D FF73 463B 7E55  CF43 25D1 E75B E2DB 15C7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070623/b714fad5/attachment.html 

From pine508 at hotmail.com  Sat Jun 23 18:52:56 2007
From: pine508 at hotmail.com (Che M)
Date: Sat, 23 Jun 2007 12:52:56 -0400
Subject: [Tutor] Tutor Digest, Vol 40, Issue 54
In-Reply-To: <mailman.30509.1182577754.32030.tutor@python.org>
Message-ID: <BAY105-F29C446419A313B932FE8BFE0160@phx.gbl>

regarding making an executable file from a python file, Alan Gauld said:

>Assuming you are on Windows you can use py2exe but
>its non trivial to use. (Not hard, just not trivial)
>
>But first ask why you need to.
>I've been using Python for over 10 years now and never once needed
>to do this. (I did it once just to see how, but I've never *needed* to
>do it)
>
>Once Python is installed you can run any script by just double
>clicking in explorer.
>
>And you can build installers that will install python if its not
>already there and then add your script. There are few cases
>where you really need an exe file. IMHO.

Though, yes, you never need to, perhaps you might *want* to, for reasons of 
"marketability".  For example...if I want to make an application for 
distribution to others, either for sale or as freeware, and I use the 
installers option as you mentioned, it is only proper to indicate this to 
the end user, such as, "In installing this application, the Python 
programming language and some other libraries will also be installed on your 
computer."

But that might trigger a common psychological response from the user, "Oh, 
no, not a whole complex set of things installed on my computer that I don't 
understand, have never heard of, and will only need for this one 
application"  But downloading a single .exe file and maybe a small folder of 
images or a few .dll files doesn't conjure that sense.  If I understand it 
right, the .exe has Python bundled into it anyway, so such an end user's 
response isn't strictly rational, but you can see how people might feel this 
way in an age when there are so many ways one should mistrust software.

Another reason is that, as I understand it, making it an .exe obscures the 
code (at least enough to make it take a bit more work to reveal the code).  
For some this might be a benefit?

I may be way off base here, just throwing it out as something I've wondered 
about.

_________________________________________________________________
Get a preview of Live Earth, the hottest event this summer - only on MSN 
http://liveearth.msn.com?source=msntaglineliveearthhm


From deliberatus at verizon.net  Sat Jun 23 17:58:06 2007
From: deliberatus at verizon.net (Kirk Bailey)
Date: Sat, 23 Jun 2007 12:58:06 -0300
Subject: [Tutor] ongoing saga
Message-ID: <467D430E.7070005@verizon.net>

well  now. I had a new idea, a product to let managers communicate to
workteramss in offices- sends messages to groups of people.

My approach is valuable because iit is so simple, and does not requirte the
opeininig of new ports in the fireewwall of a site- it opperates through
port 80, the http port. It is very easy to use at bothe ends, and only 1
program is employed to accomlish it's work.

Now here is  the intresting part- Sellinig it. As offices are so different
in their setup, using it takes some case by case 'fitting' to apply it to
each office. A house IT staff can install and adapt it to their situationb
on their own, or employ our firm to custom install it for them. Therefore,
we are going to GIVE IT AWAY, but offer support and installation services.

So here's the miravcle of the money tree- we make money by giving it away,
then letting people pay us to bring a ladder when they dig their own graves.
It  will become available to the public in a month.

So how's YOUR money tree growing?

-- 
Salute!
	-Kirk Bailey
           Think
          +-----+
          | BOX |
          +-----+
           knihT

Fnord.


From rabidpoobear at gmail.com  Sat Jun 23 20:14:06 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Sat, 23 Jun 2007 13:14:06 -0500
Subject: [Tutor] ongoing saga
In-Reply-To: <467D430E.7070005@verizon.net>
References: <467D430E.7070005@verizon.net>
Message-ID: <467D62EE.4080605@gmail.com>

Kirk Bailey wrote:
> well  now. I had a new idea, a product to let managers communicate to
> workteramss in offices- sends messages to groups of people.
>
> My approach is valuable because iit is so simple, and does not requirte the
> opeininig of new ports in the fireewwall of a site- it opperates through
> port 80, the http port. It is very easy to use at bothe ends, and only 1
> program is employed to accomlish it's work.
>
> Now here is  the intresting part- Sellinig it. As offices are so different
> in their setup, using it takes some case by case 'fitting' to apply it to
> each office. A house IT staff can install and adapt it to their situationb
> on their own, or employ our firm to custom install it for them. Therefore,
> we are going to GIVE IT AWAY, but offer support and installation services.
>
> So here's the miravcle of the money tree- we make money by giving it away,
> then letting people pay us to bring a ladder when they dig their own graves.
> It  will become available to the public in a month.
>
> So how's YOUR money tree growing?
I was under the impression that managers e-mailed their workteams if 
they needed to talk to groups of people.
If the people are on an intranet, there shouldn't be any firewalls 
blocking their communication.
The firewall would be between the computers and the internet, correct?

The point of a firewall is to block all traffic which may be harmful to 
computers behind it.
If your software listens on port 80, this is an abuse of the firewall 
spec, IMHO.
The reason people are willing to open port 80 is because they know the 
only thing that will be listening
on the other end is Microsoft IIS or Apache, both applications which 
have been under constant, stable development for years
and have good security.  Putting an application you just wrote from 
scratch with no regard to the security of it provides
hackers an entrypoint into your network via your application.

In addition, I doubt the managers would move to universally supporting 
your application - many of them would desire to continue to use
e-mail for communication - and this would result in the workers having 
just another intrusive application they have to leave open all the time,
as they're already required to leave an e-mail client active, I would guess.

Anyway, I'm just a college kid with no experience in this kind of stuff, 
so if I'm completely wrong then correct me,
but that's how I'd see it as working.

P.S. my money tree's a little dried up right now but I hope with some 
water and some love it'll be rejuvenated soon.
-Luke


From rabidpoobear at gmail.com  Sat Jun 23 20:25:13 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Sat, 23 Jun 2007 13:25:13 -0500
Subject: [Tutor] Tutor Digest, Vol 40, Issue 54
In-Reply-To: <BAY105-F29C446419A313B932FE8BFE0160@phx.gbl>
References: <BAY105-F29C446419A313B932FE8BFE0160@phx.gbl>
Message-ID: <467D6589.6070301@gmail.com>

Che M wrote:
> regarding making an executable file from a python file, Alan Gauld said:
>
>   
>> Assuming you are on Windows you can use py2exe but
>> its non trivial to use. (Not hard, just not trivial)
>>
>> But first ask why you need to.
>> I've been using Python for over 10 years now and never once needed
>> to do this. (I did it once just to see how, but I've never *needed* to
>> do it)
>>
>> Once Python is installed you can run any script by just double
>> clicking in explorer.
>>
>> And you can build installers that will install python if its not
>> already there and then add your script. There are few cases
>> where you really need an exe file. IMHO.
>>     
>
> Though, yes, you never need to, perhaps you might *want* to, for reasons of 
> "marketability".  For example...if I want to make an application for 
> distribution to others, either for sale or as freeware, and I use the 
> installers option as you mentioned, it is only proper to indicate this to 
> the end user, such as, "In installing this application, the Python 
> programming language and some other libraries will also be installed on your 
> computer."
>   
And what about all the commercial applications that require you to 
install the .NET framework, or Java, to work?
Or games that require DirectX?
People don't have problems with these.
As far as I'm concerned, I'd rather have 45k of source plus the data 
files, than an extra 10mb for Python that I already have installed.
Game downloads don't include DirectX for this reason - it's an extra 100 
megs when most people will have it,
or will have it after they play their first game.  So they put DirectX 
on the CD, and in the game install,
they ask you if you'd like to download and install DirectX if you don't 
have it already.
That's how I think python installs should work.
Just have a little check box that says "Download and install Python if 
you don't have x version or later installed."
That's not any more intrusive than these other applications that force 
you to install stuff.
In fact, it's less intrusive than .NET applications.  It takes forever 
to install the .NET framework,
and I have to navigate through web pages on microsoft.com just to find it!
> But that might trigger a common psychological response from the user, "Oh, 
> no, not a whole complex set of things installed on my computer that I don't 
> understand, have never heard of, and will only need for this one 
> application"
So add it to the 'custom' install path, and on the 'default' install 
path, just scan for Python and install it automatically for them
if they don't already have it.  Applications do this all the time.
>   But downloading a single .exe file and maybe a small folder of 
> images or a few .dll files doesn't conjure that sense.
That's essentially what the Python install is - some exes and some 
folders, that the end user never needs to look inside.
>   If I understand it 
> right, the .exe has Python bundled into it anyway, so such an end user's 
> response isn't strictly rational, but you can see how people might feel this 
> way in an age when there are so many ways one should mistrust software.
>   
Of course you have a valid point - but only because of other people's 
irrationalities.
> Another reason is that, as I understand it, making it an .exe obscures the 
> code (at least enough to make it take a bit more work to reveal the code).  
> For some this might be a benefit?
>   
That's not how py2exe works.  It makes an exe and a library.zip that 
contains all the python code.
so one could simply extract the code from library.zip and use it that way.
And you might say 'well, the code can be byte-compiled to make it more 
obscure.'
Sure, you could do that.  You could also do that without py2exe'ing it.
I believe py2app or pyinstaller or something like that actually includes 
your code in the .exe,
but py2exe doesn't.
> I may be way off base here, just throwing it out as something I've wondered 
> about.
>   
No, everyone thinks about this stuff whenever they consider if they 
should make .exe versions.
Personally, I find in most cases it's just a waste of bandwidth and time 
to make .exe versions.
But then, I haven't sold anything I've written yet, and my target 
audience is usually other programmers.

Honestly, though, Python's easy and quick to install, especially 
compared to Java.
I don't think it should be a big deal.

This sort of thing has to be taken on a case by case basis - determining 
who's the user base,
their level of technical knowledge, their aversion to installers 
including things they've never heard of,
things like this.

HTH,
-Luke
> _________________________________________________________________
> Get a preview of Live Earth, the hottest event this summer - only on MSN 
> http://liveearth.msn.com?source=msntaglineliveearthhm
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   


From deliberatus at verizon.net  Sat Jun 23 20:46:11 2007
From: deliberatus at verizon.net (Kirk Bailey)
Date: Sat, 23 Jun 2007 15:46:11 -0300
Subject: [Tutor] ongoing saga
In-Reply-To: <467D430E.7070005@verizon.net>
References: <467D430E.7070005@verizon.net>
Message-ID: <467D6A73.5020209@verizon.net>

I jujst mounted it in my code website so I can d emo it over the web- using
exactly the same script in a FreeBSD server as my windows 2000 laptop is
using- and it works.

The control station form:
http://www.tinylist.org/podium.html

The user's end view:
http://www.tinylist.org/frametest.html


-- 
Salute!
	-Kirk Bailey
           Think
          +-----+
          | BOX |
          +-----+
           knihT

Fnord.


From sridhar.ratna at gmail.com  Sat Jun 23 21:31:47 2007
From: sridhar.ratna at gmail.com (Sridhar Ratna)
Date: Sun, 24 Jun 2007 01:01:47 +0530
Subject: [Tutor] Hi,every one
In-Reply-To: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>
References: <004701c7b50b$1c750fd0$6601a8c0@d11593a090cf438>
Message-ID: <7c73a13a0706231231q3a622d6cm4d0bb03c42d91001@mail.gmail.com>

On 6/23/07, Yang Yang <Yang at pyboo.com> wrote:
>
> 1.what is the best book for python study.

Try "Byte of Python"
  http://byteofpython.info/

>
> 2.what's is the better IDE for python
>

Start off with IDLE, which comes with the Python installer. Go through
this IDLE tutorial,
  http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/

(If you're not satisfied, there are numerous Python IDEs available)

-- 
http://srid.nearfar.org/

From deliberatus at verizon.net  Sat Jun 23 20:46:34 2007
From: deliberatus at verizon.net (Kirk Bailey)
Date: Sat, 23 Jun 2007 15:46:34 -0300
Subject: [Tutor] ongoing saga
In-Reply-To: <467D62EE.4080605@gmail.com>
References: <467D430E.7070005@verizon.net> <467D62EE.4080605@gmail.com>
Message-ID: <467D6A8A.5030406@verizon.net>



Luke Paireepinart wrote:

> I was under the impression that managers e-mailed their workteams if 
> they needed to talk to groups of people.
indivigual messages. many offices have teams working on customer service or
some group task where a leader needs to address the team, NOW, and often in
these environments, will do this by ANNOUNCING messages. This distracts, and
disrupts.
> If the people are on an intranet, there shouldn't be any firewalls 
> blocking their communication.
> The firewall would be between the computers and the internet, correct?
That is the general idea. Some places have several submets and for security
reasons channelize and limit communications between them. This is simple
enoug to install that the group manager's workstation can mount a simple
server for it  to use, avoiding the need to breach the wall. banks come to
mind as a place where there is considerable need for ligh level security
within the firm, devloping something which is classified is another office
environment  where it would be needed.
> 
> The point of a firewall is to block all traffic which may be harmful to 
> computers behind it.
Ah, but the possibility of human trojan agents is why many office use
diskless computers, and internal security. there are situations where one
must guard against iinternal threats.
> If your software listens on port 80, this is an abuse of the firewall 
> spec, IMHO.
Ho so? A web serveris working normally on port 8o. MANY applications are
acccessed through browsers, and through a webserver. So?
> The reason people are willing to open port 80 is because they know the 
> only thing that will be listening
> on the other end is Microsoft IIS or Apache, both applications which 
> have been under constant, stable development for years
> and have good security.  Putting an application you just wrote from 
> scratch with no regard to the security of it provides
> hackers an entrypoint into your network via your application.
But sir,  it IS accessed THROUGH apache, or IIS.
> 
> In addition, I doubt the managers would move to universally supporting 
> your application - many of them would desire to continue to use
> e-mail for communication - and this would result in the workers having 
> just another intrusive application they have to leave open all the time,
> as they're already required to leave an e-mail client active, I would 
> guess.
email sits there waiting for you to look at the email client. this displays
the message  within seconds of sending it- no client must come to the top of
the d esk to be visible, it already is. Please look at the example on the
link I posted to see what I mean.
> 
> Anyway, I'm just a college kid with no experience in this kind of stuff, 
> so if I'm completely wrong then correct me,
> but that's how I'd see it as working.
The dialog is good, and dodging bullets is good mental exercise. raise the
objections, let's see if they draw any blood.
> 
> P.S. my money tree's a little dried up right now but I hope with some 
> water and some love it'll be rejuvenated soon.
> -Luke
The money tree for me is pretty simple; give it away,  let them look at the
example, sell them install and support service. And as it is written in
python, this community of snake charmers are all potential tech support
personell for it. Does that offer any possibility of revenue stream to you?

The example PAGES are on the server now, just look at the source code. Want
to see the script? Let me know.
> 
> 
> 

-- 
Salute!
	-Kirk Bailey
           Think
          +-----+
          | BOX |
          +-----+
           knihT

Fnord.


From alan.gauld at btinternet.com  Sat Jun 23 23:58:38 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 23 Jun 2007 22:58:38 +0100
Subject: [Tutor] pyhook for Linux
References: <da1c02120706230944xaedbc02hbc67b0cc5529f4e7@mail.gmail.com>
Message-ID: <f5k52l$c6m$1@sea.gmane.org>


"Flaper87" <flaper87 at gmail.com> wrote

> Does anyone knows an equivalence of pyhook for linux?

Nope.

> I need to catch the events of the mose (even the simple movement, or 
> when it
> focus an icon on Desktop), and the events of the keyboard.

I think you need to look at the basic X windows event model.
In particular look at how Window Managers like twm/fvwm are
written.

Or the ubiquitous xeyes applet. It tracks the mouse all over
the screen so must catch the mouse events before forwarding
them to the applications.

These are written in C but should give you a clue as to which
events to catch and which windows/event queues to monitor
or API calls to make.

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  Sun Jun 24 00:11:06 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 23 Jun 2007 23:11:06 +0100
Subject: [Tutor] Tutor Digest, Vol 40, Issue 54
References: <mailman.30509.1182577754.32030.tutor@python.org>
	<BAY105-F29C446419A313B932FE8BFE0160@phx.gbl>
Message-ID: <f5k5q2$e8k$1@sea.gmane.org>


"Che M" <pine508 at hotmail.com> wrote in

>>And you can build installers that will install python if its not
>>already there and then add your script. There are few cases
>>where you really need an exe file. IMHO.
>
> Though, yes, you never need to, perhaps you might *want* to, for 
> reasons of
> "marketability".  For example...if I want to make an application for
> distribution to others, either for sale or as freeware, and I use 
> the
> installers option as you mentioned, it is only proper to indicate 
> this to
> the end user, such as, "In installing this application, the Python
> programming language and some other libraries will also be installed 
> on your
> computer."

You could but most Java applications don't warn you that they
are installing the Sun Java JRE onto your system they just do it.
And VB apps don't usually say they are installing VB DLLs on
the system. Of course Python is more than a DLL and you might
like to delete the documentation and sample programs to save
the user space. But a more realistic example is programs which
turn on Active Scripting on a Windows PC. This enables people
to write and run VBScript of JScript programs. Very similar to
Python.

> application"  But downloading a single .exe file and maybe a small 
> folder of
> images or a few .dll files doesn't conjure that sense.  If I 
> understand it
> right, the .exe has Python bundled into it anyway, so such an end 
> user's
> response isn't strictly rational,

So why bother the user, they just get a typical install bundle and
don't need to worry about what run time environment has been
installed?

> Another reason is that, as I understand it, making it an .exe
> obscures the code (at least enough to make it take a bit
> more work to reveal the code).

This is valid but its arguable by how much and whether it would
deter a dishonest pirate much more than a compiled python module.
Or  you might prefer to do a Jython version of your code and
distribute as a Java program instead.

> I may be way off base here, just throwing it out as something
> I've wondered about.

These are valid points but I think they are often grossly over played
and the reality is most folks just think exe because its what they
are used to. IMO Its very much a Windows thing, its very rarely done
in Unix land because there people are accustom,ed to interpreted
applications (in sh, awk, perl, tcl, m4 etc) and their need of an
interpreter. If Unix users can live without it why not Windows users.
Its a matter of changing culture rather than any real technical
advantage. (There may also be a false assumption that an exe
file is somehow inherently faster)

Alan G. 



From learner404 at gmail.com  Sun Jun 24 11:44:14 2007
From: learner404 at gmail.com (learner404)
Date: Sun, 24 Jun 2007 11:44:14 +0200
Subject: [Tutor] pyhook for Linux
In-Reply-To: <da1c02120706230944xaedbc02hbc67b0cc5529f4e7@mail.gmail.com>
References: <da1c02120706230944xaedbc02hbc67b0cc5529f4e7@mail.gmail.com>
Message-ID: <13a83ca10706240244n3b363af3v8756bae27af04add@mail.gmail.com>

Hi,

You could also use the evdev driver:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/2d7e3791381bdeb5/a03d438f64ec5ac8?lnk=gst&q=francois+schnell&rnum=2#a03d438f64ec5ac8

If you successfully use another way I'm interested by your feedback. Thanks.


On 6/23/07, Flaper87 <flaper87 at gmail.com> wrote:
> Hi!
>
> Does anyone knows an equivalence of pyhook for linux?
>
> I need to catch the events of the mose (even the simple movement, or when it
> focus an icon on Desktop), and the events of the keyboard.
>
> Thank's
>
> --
> Flavio Percoco Premoli, A.K.A. [Flaper87]
> http://www.flaper87.com
> Usuario Linux registrado #436538
> Geek by nature, Linux by choice, Debian of course.
> Key Fingerprint: CFC0 C67D FF73 463B 7E55  CF43 25D1 E75B E2DB 15C7
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Francois Schnell

From hieu.d.hoang at gmail.com  Sun Jun 24 11:59:10 2007
From: hieu.d.hoang at gmail.com (=?UTF-8?Q?Hi=E1=BA=BFu_Ho=C3=A0ng?=)
Date: Sun, 24 Jun 2007 16:59:10 +0700
Subject: [Tutor] SPE - Stani's Python Editor ?
In-Reply-To: <467C8BB7.8010401@fastmail.fm>
References: <467C8BB7.8010401@fastmail.fm>
Message-ID: <4f12b0dd0706240259h34a19119i9f4ef6aac0a7207@mail.gmail.com>

The SPE is pure Python, you can run it on 2.5 without change. I think
Fuzzyman makes a zip file that can be used for all versions. Just
wxPython need to be compiled against 2.5 specifically.

http://prdownload.berlios.de/python/SPE-0.8.3.c-wx2.6.1.0-no_setup.zip

should be what you need. The subversion version can now run on
wxPython 2.8 reliably, and he's moving up to wxPy 2.8.

SPE's site is now http://pythonide.blogspot.com

From alan.gauld at btinternet.com  Sun Jun 24 16:25:50 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 24 Jun 2007 15:25:50 +0100
Subject: [Tutor] SPE - Stani's Python Editor ?
References: <467C8BB7.8010401@fastmail.fm>
	<4f12b0dd0706240259h34a19119i9f4ef6aac0a7207@mail.gmail.com>
Message-ID: <f5lutm$frk$1@sea.gmane.org>

"Hi?u Ho?ng" <hieu.d.hoang at gmail.com> wrote

> http://prdownload.berlios.de/python/SPE-0.8.3.c-wx2.6.1.0-no_setup.zip
>
> should be what you need. The subversion version can now run on
> wxPython 2.8 reliably, and he's moving up to wxPy 2.8.

I managed to get the standard download working with wxPy 2.8
just by moving one line of code in the init method of  Throbber
in Menu.py

So far that has worked fine...

Alan G.



From chrispython at mac.com  Sun Jun 24 18:33:36 2007
From: chrispython at mac.com (chrispython at mac.com)
Date: Sun, 24 Jun 2007 09:33:36 -0700
Subject: [Tutor] using shelve
In-Reply-To: <5e58f2e40706211927o6766a96o140b73fd6b2d021@mail.gmail.com>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>
	<5e58f2e40706211927o6766a96o140b73fd6b2d021@mail.gmail.com>
Message-ID: <EC2D8857-0113-1000-8E0A-F22FB844510F-Webmail-10006@mac.com>

 
Sorry it took me so long to get back - from your posts and my experimentation I can see that when you access one item in the shelve dictionary, it only gets the one item, not all of them. I am going to use shelve, and only refactor or change if performance becomes an issue - which I don't see happening for a long time.
On Thursday, June 21, 2007, at 10:27PM, "John Fouhy" <john at fouhy.net> wrote:
>On 22/06/07, chrispython at mac.com <chrispython at mac.com> wrote:
>> I created a shelf called 'myshelf' and put two objects in it, a string and a list. When I open the shelf I get:
>>
>> >>> d=shelve.open('/Users/development/Desktop/myshelf')
>> >>> d.keys()
>> ['dir1', 'dir2']
>> >>> d
>> {'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 'dir1': ['.DS_Store', '.localized', 'access the latest version', 'Python Quick Reference.webloc', 'rssdb', 'workspace']}
>>
>> It seems that when you use shelve.open(), it actually brings the entire shelf dictionary into memory, accessible through d.
>
>Well ... all that tells me is that when you ask python for a string
>representation of a shelf, it reads the entire thing.
>
>> What if you had 100 objects in myshelf, or 1000 or 100,000? Wouldn't it get bogged down?
>
>If you try to print out the whole thing, probably.  Let's try some test:
>
>>>> import shelve
>>>> d = shelve.open('test.shelf')
>>>> for i in range(1000):
>...  d[str(i)] = 'x'*i
>...
>>>> d.close()
>
>Morpork:~/tmp repton$ ls -l test.shelf
>-rw-r--r--   1 repton  repton       1M Jun 22 14:23 test.shelf
>
>First, we'll measure how long it takes python to open the shelf using
>shelve.open:
>
>Morpork:~/tmp repton$ python -m timeit -s 'import shelve' 'd =
>shelve.open("test.shelf")'
>1000 loops, best of 3: 1.95 msec per loop
>
>Now we'll measure how long it takes python to open a shelf and turn it
>into a string:
>
>Morpork:~/tmp repton$ python -m timeit -s 'import shelve' 'd =
>shelve.open("test.shelf")' 'str(d)'
>10 loops, best of 3: 51.5 msec per loop
>
>So, that's about a factor of 25 difference.
>
>HTH!
>
>-- 
>John.
>
>

From cappy2112 at gmail.com  Sun Jun 24 20:08:28 2007
From: cappy2112 at gmail.com (Tony Cappellini)
Date: Sun, 24 Jun 2007 11:08:28 -0700
Subject: [Tutor] Tutor Digest, Vol 40, Issue 55
In-Reply-To: <mailman.49.1182592811.1881.tutor@python.org>
References: <mailman.49.1182592811.1881.tutor@python.org>
Message-ID: <8249c4ac0706241108j5cb94436w5bdcf4aabaab4521@mail.gmail.com>

Take a look at pyHook

>    1. Re: Catch event's on my computer (Alan Gauld)
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Catch event's on my computer
> To: tutor at python.org
> Message-ID: <f5iksk$452$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>         reply-type=original
>
> "Flaper87" <flaper87 at gmail.com> wrote
>
> > I mean, i need to catch every movement of the pointer, what its
> > position is
> > everything. I've read that i can do that using my native system API,
> > and
> > also pygame.

From dos.fool at gmail.com  Mon Jun 25 04:59:21 2007
From: dos.fool at gmail.com (max .)
Date: Sun, 24 Jun 2007 20:59:21 -0600
Subject: [Tutor] python port scanner
Message-ID: <857e4c3d0706241959y7b97dcaep5d2e05e4b677c044@mail.gmail.com>

hello i am looking into writing a simple python port scanner but i cant find
any good tutorials online if anyone can help or knows of any tutorials that
could help it would be great. this would be my first program like this so i
might need a little extra help


thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070624/c7ec5549/attachment.htm 

From alan.gauld at btinternet.com  Mon Jun 25 07:06:02 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 25 Jun 2007 06:06:02 +0100
Subject: [Tutor] python port scanner
References: <857e4c3d0706241959y7b97dcaep5d2e05e4b677c044@mail.gmail.com>
Message-ID: <f5nig2$h72$1@sea.gmane.org>

"max ." <dos.fool at gmail.com> wrote

> hello i am looking into writing a simple python port scanner but i 
> cant find
> any good tutorials online if anyone can help or knows of any 
> tutorials that
> could help it would be great.

Well you could start with my network programming topic in my tutor.

It covers the basics of sockets and ports. You don;t give any clues
as to how much you already know so its hard to give specific advice.

One thing you might find useful is the book "Python Network
Programming" published by Apress. It is a very complete book on
all aspects of network programming in Python, although not aimed
at beginners.

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



From noufal at airtelbroadband.in  Mon Jun 25 12:10:38 2007
From: noufal at airtelbroadband.in (Noufal Ibrahim)
Date: Mon, 25 Jun 2007 15:40:38 +0530
Subject: [Tutor] Python maintenance taks
Message-ID: <467F949E.7080001@airtelbroadband.in>

Hello everyone,
	I seem to recall that there was a site (on the python wiki IIRC) that 
listed relatively simple python bugs (in the actual C code inside the 
interpreter) that needed to be fixed. It was advertised as good starting 
point for novices. I can't seem to find it. Does anyone here have an 
idea of where this is (if it exists)?

Thanks much.


-- 
~noufal

From andreas at kostyrka.org  Mon Jun 25 12:31:44 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Mon, 25 Jun 2007 12:31:44 +0200
Subject: [Tutor] python port scanner
In-Reply-To: <857e4c3d0706241959y7b97dcaep5d2e05e4b677c044@mail.gmail.com>
References: <857e4c3d0706241959y7b97dcaep5d2e05e4b677c044@mail.gmail.com>
Message-ID: <467F9990.5060000@kostyrka.org>

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

Well, take a look at the socket module and nonblocking mode.

But truly, it's not a good "first" program, not for Python, not for C.

Andreas

max . wrote:
> hello i am looking into writing a simple python port scanner but i cant
> find
> any good tutorials online if anyone can help or knows of any tutorials that
> could help it would be great. this would be my first program like this so i
> might need a little extra help
> 
> 
> thanks
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGf5mPHJdudm4KnO0RAjM0AKChWMXvTVp1+0ihZTau+A+RLnYzMACg4SJc
B7ypBQx/I9EIwYIfosxjNTI=
=LMoL
-----END PGP SIGNATURE-----

From janos.juhasz at VELUX.com  Mon Jun 25 12:59:21 2007
From: janos.juhasz at VELUX.com (=?ISO-8859-1?Q?J=E1nos_Juh=E1sz?=)
Date: Mon, 25 Jun 2007 12:59:21 +0200
Subject: [Tutor] python port scanner
In-Reply-To: <mailman.37.1182765611.8674.tutor@python.org>
Message-ID: <OFBF8FE3A9.8C8ABA27-ONC1257305.003B9D03-C1257305.003C5CDE@velux.com>

Dear dos,

>>hello i am looking into writing a simple python port scanner but i cant 
find
>>any good tutorials online if anyone can help or knows of any tutorials 
that
>>could help it would be great. this would be my first program like this 
so i
>>might need a little extra help

I just recommend to take a look on twisted 
http://www.oreilly.com/catalog/twistedadn/
It is a nice book.

There is an example on how to do it with twisted among the examples in 
chapter 2.


You can read it on safari.

Janos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070625/bd367803/attachment.htm 

From sigzero at gmail.com  Tue Jun 26 00:20:30 2007
From: sigzero at gmail.com (Robert Hicks)
Date: Mon, 25 Jun 2007 18:20:30 -0400
Subject: [Tutor] Fastest way to iterate through a file
Message-ID: <f5pf3g$drd$1@sea.gmane.org>

I have a script at work where I have a list of id numbers and I am doing a:

for line in ehFile:
     for id in line:
	
I am then going through that file and finding the line the id is on and 
printing the next line out. It takes a few seconds to see the output to 
the screen (the Perl version whips by) which got me to thinking I could 
be doing it faster (as I want to move it from Perl to Python).

If you need all the code I can post that tomorrow or I can try any ideas 
posted to this.

Thanks!

Robert


From kent37 at tds.net  Tue Jun 26 01:33:41 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 25 Jun 2007 19:33:41 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <f5pf3g$drd$1@sea.gmane.org>
References: <f5pf3g$drd$1@sea.gmane.org>
Message-ID: <468050D5.3020403@tds.net>

Robert Hicks wrote:
> I have a script at work where I have a list of id numbers and I am doing a:
> 
> for line in ehFile:

That is fine

>      for id in line:

I don't know what this is for - line is a string, iterating it will give 
you every character is the line.
> 	
> I am then going through that file and finding the line the id is on and 
> printing the next line out. It takes a few seconds to see the output to 
> the screen (the Perl version whips by) which got me to thinking I could 
> be doing it faster (as I want to move it from Perl to Python).
> 
> If you need all the code I can post that tomorrow or I can try any ideas 
> posted to this.

A bit more code would help.

Kent

From sarliz73 at yahoo.com  Tue Jun 26 03:56:57 2007
From: sarliz73 at yahoo.com (Sara Johnson)
Date: Mon, 25 Jun 2007 18:56:57 -0700 (PDT)
Subject: [Tutor] Bundle help!
Message-ID: <253827.73093.qm@web35102.mail.mud.yahoo.com>

I'm to use the bundle method to append some information to a list.  I have no idea how to do that!  I have Python for Dummies and I think I need Python for Complete Idiots because I am not seeing how to do this!!  I have basic C+ knowledge and about 6 programs to write (in one month's time!) and I know NOTHING!!  HELP!!!
   
  Sara

 
---------------------------------
8:00? 8:25? 8:40?  Find a flick in no time
 with theYahoo! Search movie showtime shortcut.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070625/88d7b525/attachment.html 

From kent37 at tds.net  Tue Jun 26 05:07:22 2007
From: kent37 at tds.net (Kent Johnson)
Date: Mon, 25 Jun 2007 23:07:22 -0400
Subject: [Tutor] Bundle help!
In-Reply-To: <253827.73093.qm@web35102.mail.mud.yahoo.com>
References: <253827.73093.qm@web35102.mail.mud.yahoo.com>
Message-ID: <468082EA.3090306@tds.net>

Sara Johnson wrote:
> I'm to use the bundle method to append some information to a list.  I 
> have no idea how to do that!

What is the bundle method? What have you tried so far? What are you 
trying to accomplish?

Kent

From reed at reedobrien.com  Tue Jun 26 05:54:05 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Mon, 25 Jun 2007 23:54:05 -0400
Subject: [Tutor] Bundle help!
In-Reply-To: <253827.73093.qm@web35102.mail.mud.yahoo.com>
References: <253827.73093.qm@web35102.mail.mud.yahoo.com>
Message-ID: <16FD7E58-416F-4EE8-A86F-E623DF5DA5C5@reedobrien.com>


On Jun 25, 2007, at 9:56 PM, Sara Johnson wrote:

> I'm to use the bundle method to append some information to a list.   
> I have no idea how to do that!  I have Python for Dummies and I  
> think I need Python for Complete Idiots because I am not seeing how  
> to do this!!  I have basic C+ knowledge and about 6 programs to  
> write (in one month's time!) and I know NOTHING!!  HELP!!!
>
> Sara
>
> 8:00? 8:25? 8:40? Find a flick in no time
> with theYahoo! Search movie showtime shortcut.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


Sara:

Guessing:
http://numpy.scipy.org/
http://www.danbbs.dk/~kibria/software.html#qpnumpy
close?


But if it is as simple as just adding to a list:
In [2]: L = [1,2,3,4,5,6]

In [3]: L.append(['a','b', 'c'])

In [4]: L.append(7)

In [5]: L
Out[5]: [1, 2, 3, 4, 5, 6, ['a', 'b', 'c'], 7]

HTH
~r
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070625/7a07757c/attachment.htm 

From carroll at tjc.com  Tue Jun 26 07:23:08 2007
From: carroll at tjc.com (Terry Carroll)
Date: Mon, 25 Jun 2007 22:23:08 -0700 (PDT)
Subject: [Tutor] Getting at sqlite schema info from within Python?
Message-ID: <Pine.LNX.4.44.0706252214550.29108-100000@violet.rahul.net>


Is there any way of getting to the schema of an sqlite database from 
within Python? In particular, a list of tables in the DB.

>From the sqlite command line, I can use the sqlite 

 .tables

command to get a list of tables in the database; and then the 

 PRAGMA TABLE_INFO(tablename)

to get the information on the various fields in the table.

>From within Python, though, I can't find a way to get the table names.  
If I know the table names, the PRAGMA approach works to get at the field
info; but I can't figure out how to find the table names first.

Trying to use the sqlite .tables command via Python gives me:

>>> c.execute(".tables;")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.OperationalError: near ".": syntax error

...which makes some sense; it isn't SQL.


From john at fouhy.net  Tue Jun 26 07:26:08 2007
From: john at fouhy.net (John Fouhy)
Date: Tue, 26 Jun 2007 17:26:08 +1200
Subject: [Tutor] Getting at sqlite schema info from within Python?
In-Reply-To: <Pine.LNX.4.44.0706252214550.29108-100000@violet.rahul.net>
References: <Pine.LNX.4.44.0706252214550.29108-100000@violet.rahul.net>
Message-ID: <5e58f2e40706252226o17153b0awef18b55590cd3e10@mail.gmail.com>

On 26/06/07, Terry Carroll <carroll at tjc.com> wrote:
>
> Is there any way of getting to the schema of an sqlite database from
> within Python? In particular, a list of tables in the DB.

Try 'select * from sqlite_master'.

-- 
John.

From carroll at tjc.com  Tue Jun 26 07:33:21 2007
From: carroll at tjc.com (Terry Carroll)
Date: Mon, 25 Jun 2007 22:33:21 -0700 (PDT)
Subject: [Tutor] Getting at sqlite schema info from within Python?
In-Reply-To: <5e58f2e40706252226o17153b0awef18b55590cd3e10@mail.gmail.com>
Message-ID: <Pine.LNX.4.44.0706252231020.29108-100000@violet.rahul.net>

On Tue, 26 Jun 2007, John Fouhy wrote:

> On 26/06/07, Terry Carroll <carroll at tjc.com> wrote:
> >
> > Is there any way of getting to the schema of an sqlite database from
> > within Python? In particular, a list of tables in the DB.
> 
> Try 'select * from sqlite_master'.

You rock.  Thanks.

And, now that I know that trick, googling on sqlite_master leads me to 
http://www.sqlite.org/faq.html#q7 which explains the format.

Honest, I really did spend quite some time reading the sqlite docs and
trying things; somehow I missed the FAQ.


From Andy.cheesman at bristol.ac.uk  Tue Jun 26 12:35:36 2007
From: Andy.cheesman at bristol.ac.uk (Andy Cheesman)
Date: Tue, 26 Jun 2007 11:35:36 +0100
Subject: [Tutor] Animating changes with Numpy arrays
Message-ID: <4680EBF8.9000403@bristol.ac.uk>

Hi people

Thanks to people's most excellent help with the Automatic generation of
an "all possible combinations" array. I've got a beta version of my
program working.
However, I was wondering if there is an "easy" way to animate changes
between arrays and to show the number of the loop which the program is
running i.e a print out which changes at a controlable rate I've looked
for ascii art stuff with python but there are no pointers.
At the moment, I'm review the changes by walking through a screen print
out of all changes making pattern changes hard to spot but as this is
just a minor debuging tool, I don't want to spend weeks coding it in!

Thanks
Andy

Examples

from  	-=> 	to
1 1 1		1 2 1
1 2 1 		1 1 1
1 1 1 		1 1 1

From rabidpoobear at gmail.com  Tue Jun 26 12:41:32 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 26 Jun 2007 05:41:32 -0500
Subject: [Tutor] Animating changes with Numpy arrays
In-Reply-To: <4680EBF8.9000403@bristol.ac.uk>
References: <4680EBF8.9000403@bristol.ac.uk>
Message-ID: <4680ED5C.3060906@gmail.com>

Andy Cheesman wrote:
> Hi people
>
> Thanks to people's most excellent help with the Automatic generation of
> an "all possible combinations" array. I've got a beta version of my
> program working.
> However, I was wondering if there is an "easy" way to animate changes
> between arrays and to show the number of the loop which the program is
> running i.e a print out which changes at a controlable rate I've looked
> for ascii art stuff with python but there are no pointers.
> At the moment, I'm review the changes by walking through a screen print
> out of all changes making pattern changes hard to spot but as this is
> just a minor debuging tool, I don't want to spend weeks coding it in!
>   
Andy -
Look into the Console module if you're on Windows
and Pycurses if you're on a Unix variant.
These let you have a character map of the terminal,
versus a top-to-bottom line printing mode.
HTH,
-Luke


From johnnyjiv at gmail.com  Tue Jun 26 15:11:35 2007
From: johnnyjiv at gmail.com (Johnny Jelinek)
Date: Tue, 26 Jun 2007 08:11:35 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
Message-ID: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>

Hello, I'm a beginner to python; I wanted to make a fun little game, so I
started with something simple: Rock, Paper, Scissors.

The program I made satisfies me, but I want to add graphics.  I installed
pygame, and have some svg's that I want to render into graphics.  I
installed cairo, but then realized that it is only used to draw svg's and
other graphics into files, not render them on the screen.  Any ideas how to
start turning this into a graphical game?  Feel free to add any other
suggestions as well :D:D:D! Thanks.

Here is the source code:

#! /usr/bin/env python
##########Rock Paper Scissors, By: John Jelinek IV##########
##########GLOBAL VARS#######################################
import random
import os
random = random.Random()
##########FUNCTIONS#########################################
def clear():        # Clear's the screen
    os.system("clear")
def rounds():        # Asks how many rounds
    rnum = input("How many rounds?!?: ")
    while rnum == 1 or rnum%2 == 0 or rnum <= -1:
        print "Must be an odd number of rounds and more than 1, try again!"
        rnum = input("How many rounds?!?: ")
    return rnum
def rps(rounds):    # Begins the real game

    win = 0
    lose = 0
    tie = 0

    for i in range(1,rounds+1):
        decision = ('rock', 'paper', 'scissors')
        player = ''
        ai = random.choice(decision)

        while player != 'r' and player != 'p' and player != 's':
            print "\nROUND ", + i
            player = raw_input('What will YOU choose? (r)ock, (p)aper,
(s)cissors: ')

        if player == 'r':
            player = 'rock'
        elif player == 'p':
            player = 'paper'
        else:
            player = 'scissors'

        print "====================="
        print "you chose " + player.upper(),
        print ":: I choose " + ai.upper()

        if player.upper() == 'ROCK' and ai.upper() == 'SCISSORS':
            win += 1
            print "You WIN by CRUSHING those SCISSORS!"
        elif player.upper() == 'PAPER' and ai.upper() == 'ROCK':
            win += 1
            print "You WIN by WRAPPING that ROCK!"
        elif player.upper() == 'SCISSORS' and ai.upper() == 'PAPER':
            win += 1
            print "You WIN by CUTTING that PAPER!"
        elif player.upper() == ai.upper():
            tie += 1
            print "YOU TIE!"
        else:
            lose += 1
            print "YOU LOSE!"

    print "\nRounds Won: ", + win
    print "\nRounds Lost: ", + lose
    print "\nRounds Tied: ", + tie
##########BEGIN PROGRAM#####################################
clear()
print "Welcome to ROCK PAPER SCISSORS!  PREPARE FOR BATTEL!!\n\n"
rounds = rounds()
rps(rounds)
##########END PROGRAM#######################################
print "\n\nThanks for playing!\n"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070626/a62fc599/attachment.htm 

From sigzero at gmail.com  Tue Jun 26 15:19:07 2007
From: sigzero at gmail.com (Robert Hicks)
Date: Tue, 26 Jun 2007 09:19:07 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <468050D5.3020403@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org> <468050D5.3020403@tds.net>
Message-ID: <f5r3oc$464$1@sea.gmane.org>

Kent Johnson wrote:
> Robert Hicks wrote:
>> I have a script at work where I have a list of id numbers and I am doing a:
>>
>> for line in ehFile:
> 
> That is fine
> 
>>      for id in line:
> 
> I don't know what this is for - line is a string, iterating it will give 
> you every character is the line.
>> 	
>> I am then going through that file and finding the line the id is on and 
>> printing the next line out. It takes a few seconds to see the output to 
>> the screen (the Perl version whips by) which got me to thinking I could 
>> be doing it faster (as I want to move it from Perl to Python).
>>
>> If you need all the code I can post that tomorrow or I can try any ideas 
>> posted to this.
> 
> A bit more code would help.
> 

This is the loop code:

for line in f2:
     for id in idList:
         if id in line:
             print "%s: %s" % (id, f2.next())
             found = "%s: %s" % (id, f2.next())
             f3.write(found)


I have an list, idList[], that contains a list of id numbers. That code 
will loop the the f2 file and for lines that have an id on it it will 
print the "next" line (so I can see what it is doing) and write it to a 
file. I will turn off that screen print after I get it going the way I 
want it to.

Robert


From kent37 at tds.net  Tue Jun 26 16:04:07 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 10:04:07 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <f5r3oc$464$1@sea.gmane.org>
References: <f5pf3g$drd$1@sea.gmane.org> <468050D5.3020403@tds.net>
	<f5r3oc$464$1@sea.gmane.org>
Message-ID: <46811CD7.10200@tds.net>

Robert Hicks wrote:
> This is the loop code:
> 
> for line in f2:
>      for id in idList:
>          if id in line:
>              print "%s: %s" % (id, f2.next())
>              found = "%s: %s" % (id, f2.next())
>              f3.write(found)
> 
> 
> I have an list, idList[], that contains a list of id numbers. That code 
> will loop the the f2 file and for lines that have an id on it it will 
> print the "next" line (so I can see what it is doing) and write it to a 
> file. I will turn off that screen print after I get it going the way I 
> want it to.

I don't see any particular reason this should be slow unless idList is 
large. Perhaps the output is being buffered somewhere and not appearing 
until the process is done? How are you running the program?

BTW the line that you print and the line that you save to the file are 
not the same; every time you call f2.next() it will fetch another line 
from the file. If you want them to be the same you could say
              found = "%s: %s" % (id, f2.next())
              print found
              f3.write(found)

Kent

From kent37 at tds.net  Tue Jun 26 16:11:36 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 10:11:36 -0400
Subject: [Tutor] Bundle help!
In-Reply-To: <770674.95615.qm@web35107.mail.mud.yahoo.com>
References: <770674.95615.qm@web35107.mail.mud.yahoo.com>
Message-ID: <46811E98.2070401@tds.net>

Sara Johnson wrote:
> Hi Kent,
>  
> I had a list to sort alphabetically (that included names and 
> percentages), then I had to apend that list to sort by the category 
> represented by the percentages.  I've tried to use something like:
>  
> mylist = [whatever...]
> mylist.append(whatever) and that doesn't seem to work.  Also with this 
> list being sorted by names and by percentages, and there are more than 
> just a few items, I don't think I could just list all of the items out as:
>  
> x = ['apple', 'pear', banana', 'orange'] ......an example from "For Dummies"
>  
> I've also looked at tuples and such.  This is probably something simple, 
> but what I've tried hasn't worked.  There isn't much on bundles in here 
> and I've looked at the python site too.  I got the alphabetical list to 
> work by creating a 'newlist.'  Then I tried 'newlist2' but I'm getting 
> strange results. 

I still don't know enough to help you much. It would help if you showed 
some real code and data. How are you storing the names and percentages? 
If you have a list of pairs of (name, percentage) then you should be 
able to sort it directly with the sort() method of the list. For example:

In [3]: data = [ ('Kent', 50), ('Sara', 80), ('Fred', 20) ]
In [4]: data.sort()
In [5]: data
Out[5]: [('Fred', 20), ('Kent', 50), ('Sara', 80)]

Use append() to add more data, then sort again to get it in order:
In [6]: data.append(('Joe', 90))
In [7]: data.sort()
In [8]: data
Out[8]: [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)]

What is a bundle? I don't know of any Python meaning for that term.

Kent

PS Please use Reply All to reply to the list.

From johnnyjiv at gmail.com  Tue Jun 26 16:44:32 2007
From: johnnyjiv at gmail.com (Johnny Jelinek)
Date: Tue, 26 Jun 2007 09:44:32 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
In-Reply-To: <ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>
References: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>
	<ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>
Message-ID: <b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>

sure, I wouldn't mind looking at your code :D!  Also, the graphical one you
sent me was using gif's, do you know how to render svg's on screen?  The
advantage to vector rather than raster is that you can resize it as big as
you could ever desire and it will never lose quality.  That means I could
make a resolution independent game :D!  Does anyone have any ideas on how to
go about doing that?

On 6/26/07, bhaaluu <bhaaluu at gmail.com> wrote:
>
> Greetings,
>
> I've attached a graphical Paper-Rock-Scissors game that I found
> using the Google Code Search engine. It came as a tarball, but
> I've put all the files in a ZIP file:
>
> Archive:  paperock.zip
>   Length     Date   Time    Name
> --------    ----   ----    ----
>     12899  11-25-06 03:34   rockpaperscissors16.py
>         0  06-24-07 11:46   data/
>      5974  09-29-06 07:33   data/computerklein.gif
>      4553  09-28-06 08:48   data/papierkleinc.gif
>      4574  09-28-06 08:48   data/papierklein.gif
>      4338  09-28-06 08:48   data/scherekleinc.gif
>      4353  09-28-06 08:48   data/schereklein.gif
>      4254  09-28-06 08:48   data/steinkleinc.gif
>      4245  09-28-06 08:48   data/steinklein.gif
> --------                   -------
>     45190                   9 files
>
> Here's the MD5SUM for the zip file:
>
> 9602c5b0dcbe38e1d8fffe20683c7902  paperock.zip
>
> It is pretty neat. I hope it helps.
> Thanks for posting your source code.
> I also wrote a Paper-Rock-Scissors game as a first Python program.
> It isn't graphical. If you'd like to take a look at it, let me know.
>
> Happy Programming! =)
> --
> bhaaluu at gmail dot com
>
> On 6/26/07, Johnny Jelinek <johnnyjiv at gmail.com> wrote:
> > Hello, I'm a beginner to python; I wanted to make a fun little game, so
> I
> > started with something simple: Rock, Paper, Scissors.
> >
> <snip>
> > _______________________________________________
> > 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/20070626/ccd87203/attachment.html 

From sigzero at gmail.com  Tue Jun 26 16:16:44 2007
From: sigzero at gmail.com (Robert Hicks)
Date: Tue, 26 Jun 2007 10:16:44 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <46811CD7.10200@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org>
	<468050D5.3020403@tds.net>	<f5r3oc$464$1@sea.gmane.org>
	<46811CD7.10200@tds.net>
Message-ID: <f5r74d$ii4$1@sea.gmane.org>

Kent Johnson wrote:
> Robert Hicks wrote:
>> This is the loop code:
>>
>> for line in f2:
>>      for id in idList:
>>          if id in line:
>>              print "%s: %s" % (id, f2.next())
>>              found = "%s: %s" % (id, f2.next())
>>              f3.write(found)
>>
>>
>> I have an list, idList[], that contains a list of id numbers. That code 
>> will loop the the f2 file and for lines that have an id on it it will 
>> print the "next" line (so I can see what it is doing) and write it to a 
>> file. I will turn off that screen print after I get it going the way I 
>> want it to.
> 
> I don't see any particular reason this should be slow unless idList is 
> large. Perhaps the output is being buffered somewhere and not appearing 
> until the process is done? How are you running the program?
> 
> BTW the line that you print and the line that you save to the file are 
> not the same; every time you call f2.next() it will fetch another line 
> from the file. If you want them to be the same you could say
>               found = "%s: %s" % (id, f2.next())
>               print found
>               f3.write(found)
> 

Thanks for that!

idList only has about 129 id numbers in it.

I am running it straight from a Linux console. I thought about buffering 
but I am not sure how Python handles that.

Do you know if Python has a "slower" startup time than Perl? That could 
be part of it though I suspect the buffering thing more.

Robert


From kent37 at tds.net  Tue Jun 26 17:28:30 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 11:28:30 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <f5r74d$ii4$1@sea.gmane.org>
References: <f5pf3g$drd$1@sea.gmane.org>	<468050D5.3020403@tds.net>	<f5r3oc$464$1@sea.gmane.org>	<46811CD7.10200@tds.net>
	<f5r74d$ii4$1@sea.gmane.org>
Message-ID: <4681309E.2050808@tds.net>

Robert Hicks wrote:
> idList only has about 129 id numbers in it.

That is quite a few times to be searching each line of the file. Try 
using a regular expression search instead, like this:

import re
regex = re.compile('|'.join(idList))
for line in f2:
   if regex.search(line):
     # process a hit

A simple test shows that to be about 25 times faster.

Searching for each of 100 id strings in another string:
In [6]: import timeit
In [9]: setup = "import re; import string; ids=[str(i) for i in 
range(1000, 1100)];line=string.letters"
In [10]: timeit.Timer('for i in ids: i in line', setup).timeit()
Out[10]: 15.298269987106323

Build a regular expression to match all the ids and use that to search:
In [11]: setup2=setup + ";regex=re.compile('|'.join(ids))"
In [12]: timeit.Timer('regex.search(line)', setup2).timeit()
Out[12]: 0.58947491645812988

In [15]: _10 / _12
Out[15]: 25.95236804820507

> I am running it straight from a Linux console. I thought about buffering 
> but I am not sure how Python handles that.

I don't think the console should be buffered.

> Do you know if Python has a "slower" startup time than Perl? That could 
> be part of it though I suspect the buffering thing more.

I don't know if it is slower than Perl but it doesn't take a few seconds 
on my computer. How long does it take you to get to the interpreter 
prompt if you just start Python? You could put a simple print at the 
start of your program to see when it starts executing.

Kent

From dkuhlman at rexx.com  Tue Jun 26 17:03:49 2007
From: dkuhlman at rexx.com (Dave Kuhlman)
Date: Tue, 26 Jun 2007 08:03:49 -0700
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <46811CD7.10200@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org> <468050D5.3020403@tds.net>
	<f5r3oc$464$1@sea.gmane.org> <46811CD7.10200@tds.net>
Message-ID: <20070626150349.GA910@cutter.rexx.com>

On Tue, Jun 26, 2007 at 10:04:07AM -0400, Kent Johnson wrote:
> Robert Hicks wrote:
> > This is the loop code:
> > 
> > for line in f2:
> >      for id in idList:
> >          if id in line:
> >              print "%s: %s" % (id, f2.next())
> >              found = "%s: %s" % (id, f2.next())
> >              f3.write(found)
> > 
> > 
> > I have an list, idList[], that contains a list of id numbers. That code 
> > will loop the the f2 file and for lines that have an id on it it will 
> > print the "next" line (so I can see what it is doing) and write it to a 
> > file. I will turn off that screen print after I get it going the way I 
> > want it to.
> 
> I don't see any particular reason this should be slow unless idList is 
> large. Perhaps the output is being buffered somewhere and not appearing 
> until the process is done? How are you running the program?
> 

I think Kent is right.  You probably have a solution that is good
enough.  Ask yourself whether it really is going to save any time
if you are able to optimize it.

But, if speed is important, then you might try a solution that uses
a regular expression in place of

     for id in idList:
         if id in line:

A regular expression of the form "(id1|id2|id2)", which you could
construct programmatically, might work for your problem:

    import re
    s1 = '|'.join(idList)
    s2 = '(%s)' % s1
    pat = re.compile(s2)

Then use something like:

    for mo in pat.finditer(line):

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman

From jason.massey at gmail.com  Tue Jun 26 17:55:33 2007
From: jason.massey at gmail.com (Jason Massey)
Date: Tue, 26 Jun 2007 10:55:33 -0500
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <4681309E.2050808@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org> <468050D5.3020403@tds.net>
	<f5r3oc$464$1@sea.gmane.org> <46811CD7.10200@tds.net>
	<f5r74d$ii4$1@sea.gmane.org> <4681309E.2050808@tds.net>
Message-ID: <7e3eab2c0706260855r5a08772ewf2836390e9fc1844@mail.gmail.com>

Also since you're writing your found results to a file there's no need to
print the results to the screen.  That should shave off some time,
especially if you have a lot of hits.

On 6/26/07, Kent Johnson <kent37 at tds.net> wrote:
>
> Robert Hicks wrote:
> > idList only has about 129 id numbers in it.
>
> That is quite a few times to be searching each line of the file. Try
> using a regular expression search instead, like this:
>
> import re
> regex = re.compile('|'.join(idList))
> for line in f2:
>    if regex.search(line):
>      # process a hit
>
> A simple test shows that to be about 25 times faster.
>
> Searching for each of 100 id strings in another string:
> In [6]: import timeit
> In [9]: setup = "import re; import string; ids=[str(i) for i in
> range(1000, 1100)];line=string.letters"
> In [10]: timeit.Timer('for i in ids: i in line', setup).timeit()
> Out[10]: 15.298269987106323
>
> Build a regular expression to match all the ids and use that to search:
> In [11]: setup2=setup + ";regex=re.compile('|'.join(ids))"
> In [12]: timeit.Timer('regex.search(line)', setup2).timeit()
> Out[12]: 0.58947491645812988
>
> In [15]: _10 / _12
> Out[15]: 25.95236804820507
>
> > I am running it straight from a Linux console. I thought about buffering
> > but I am not sure how Python handles that.
>
> I don't think the console should be buffered.
>
> > Do you know if Python has a "slower" startup time than Perl? That could
> > be part of it though I suspect the buffering thing more.
>
> I don't know if it is slower than Perl but it doesn't take a few seconds
> on my computer. How long does it take you to get to the interpreter
> prompt if you just start Python? You could put a simple print at the
> start of your program to see when it starts executing.
>
> 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/20070626/fed9a86e/attachment.html 

From sigzero at gmail.com  Tue Jun 26 17:45:22 2007
From: sigzero at gmail.com (Robert Hicks)
Date: Tue, 26 Jun 2007 11:45:22 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <4681309E.2050808@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org>	<468050D5.3020403@tds.net>	<f5r3oc$464$1@sea.gmane.org>	<46811CD7.10200@tds.net>	<f5r74d$ii4$1@sea.gmane.org>
	<4681309E.2050808@tds.net>
Message-ID: <f5rcai$89n$1@sea.gmane.org>

Kent Johnson wrote:
> Robert Hicks wrote:
>> idList only has about 129 id numbers in it.
> 
> That is quite a few times to be searching each line of the file. Try 
> using a regular expression search instead, like this:
> 
> import re
> regex = re.compile('|'.join(idList))
> for line in f2:
>    if regex.search(line):
>      # process a hit
> 

Since I am printing to a file like so:

[id]: [line]

I don't see how I can get the id back out of the regex.search like I 
could in my code.

Robert


From tinoloc at gmail.com  Tue Jun 26 18:20:18 2007
From: tinoloc at gmail.com (Tino Dai)
Date: Tue, 26 Jun 2007 12:20:18 -0400
Subject: [Tutor] Importing and creation on the fly
Message-ID: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>

Hi there,

     I've been banging my head on this for about two weeks, and I can't
figure out a solution to this. I'm wondering if you could assist me on this
pesky problem.

     I'm reading in an xml file that has the name of class, location, and
the filename into a dictionary. I want to import these classes and create
instances of them.  The code in question is as follows:

 36       for xmlKey in self.dictXML.keys():
 37             if not self.dictXML[xmlKey]['location'] in sys.path and \
 38             not self.dictXML[xmlKey]['location'] == os.getcwd():
 39                 sys.path.append(self.dictXML[xmlKey]['location'])
 40             try:
 41                 if os.stat(self.dictXML[xmlKey]['location'] + \
 42                 self.dictXML[xmlKey]['filename']):
 43                     eval('import ' + self.dictXML[xmlKey]["class"])
<-- syntax error here
 44                     actionStmt=self.dictXML[xmlKey]["class"] + '.' +
self.dictXML[xmlKey]["class"] + '()' 45
45                          self.objList.append(eval(actionStmt))
46             except:
 47                 pass


I have also tried: __import__(self.dictXML[xmlKey]["class"]), which gave me
an error when I did the eval(actionStmt). Could anybody shed some light on
this? Thanks in advance.

-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070626/ce9c26af/attachment.htm 

From kent37 at tds.net  Tue Jun 26 18:26:50 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 12:26:50 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <f5rcai$89n$1@sea.gmane.org>
References: <f5pf3g$drd$1@sea.gmane.org>	<468050D5.3020403@tds.net>	<f5r3oc$464$1@sea.gmane.org>	<46811CD7.10200@tds.net>	<f5r74d$ii4$1@sea.gmane.org>	<4681309E.2050808@tds.net>
	<f5rcai$89n$1@sea.gmane.org>
Message-ID: <46813E4A.8050600@tds.net>

Robert Hicks wrote:
> Kent Johnson wrote:
>> Robert Hicks wrote:
>>> idList only has about 129 id numbers in it.
>> That is quite a few times to be searching each line of the file. Try 
>> using a regular expression search instead, like this:
>>
>> import re
>> regex = re.compile('|'.join(idList))
>> for line in f2:
>>    if regex.search(line):
>>      # process a hit
>>
> 
> Since I am printing to a file like so:
> 
> [id]: [line]
> 
> I don't see how I can get the id back out of the regex.search like I 
> could in my code.

match = regex.search(line)
if match:
   idMatch = match.group()
   print idMatch, line

Note this will only find the first id match on a line. If you need to 
find multiple matches per line use findall() or finditer() as Dave suggests.

re docs are here:
http://docs.python.org/lib/module-re.html

Kent

From kent37 at tds.net  Tue Jun 26 18:31:18 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 12:31:18 -0400
Subject: [Tutor] using shelve
In-Reply-To: <9CD330CD-003C-492B-9AAE-5F47A0A54728@reedobrien.com>
References: <B2D41445-0113-1000-B832-31EEF368CA51-Webmail-10010@mac.com>	<83A86DC0-4635-459C-BEA3-BA0BE7DE2AFC@reedobrien.com>	<467BB1E8.1080903@tds.net>
	<9CD330CD-003C-492B-9AAE-5F47A0A54728@reedobrien.com>
Message-ID: <46813F56.4000501@tds.net>

Reed O'Brien wrote:
> Thanks for the heads up, Kent.  I didn't realize that was a copy of  
> Lutz's book.  I sent notice to infringement at oreilly.com.
> It did seem like an awfully rich comparison of python persistence  
> options.
> 
> If they follow up with me I will follow up with the list.

I also emailed O'Reilly, just got a thank-you email back from them 
saying they will "investigate and take appropriate action".

Kent

From sigzero at gmail.com  Tue Jun 26 18:56:15 2007
From: sigzero at gmail.com (Robert Hicks)
Date: Tue, 26 Jun 2007 12:56:15 -0400
Subject: [Tutor] Fastest way to iterate through a file
In-Reply-To: <46813E4A.8050600@tds.net>
References: <f5pf3g$drd$1@sea.gmane.org>	<468050D5.3020403@tds.net>	<f5r3oc$464$1@sea.gmane.org>	<46811CD7.10200@tds.net>	<f5r74d$ii4$1@sea.gmane.org>	<4681309E.2050808@tds.net>	<f5rcai$89n$1@sea.gmane.org>
	<46813E4A.8050600@tds.net>
Message-ID: <f5rgff$og9$1@sea.gmane.org>

Kent Johnson wrote:
> Robert Hicks wrote:
>> Kent Johnson wrote:
>>> Robert Hicks wrote:
>>>> idList only has about 129 id numbers in it.
>>> That is quite a few times to be searching each line of the file. Try 
>>> using a regular expression search instead, like this:
>>>
>>> import re
>>> regex = re.compile('|'.join(idList))
>>> for line in f2:
>>>    if regex.search(line):
>>>      # process a hit
>>>
>> Since I am printing to a file like so:
>>
>> [id]: [line]
>>
>> I don't see how I can get the id back out of the regex.search like I 
>> could in my code.
> 
> match = regex.search(line)
> if match:
>    idMatch = match.group()
>    print idMatch, line
> 
> Note this will only find the first id match on a line. If you need to 
> find multiple matches per line use findall() or finditer() as Dave suggests.
> 
> re docs are here:
> http://docs.python.org/lib/module-re.html
> 

I was just reading that.  : )

That worked...and while the first one was probably "good" enough, I have 
learned something new today thanks to you and the others.

TYVM

Robert


From kent37 at tds.net  Tue Jun 26 19:18:34 2007
From: kent37 at tds.net (Kent Johnson)
Date: Tue, 26 Jun 2007 13:18:34 -0400
Subject: [Tutor] Importing and creation on the fly
In-Reply-To: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
References: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
Message-ID: <46814A6A.9000206@tds.net>

Tino Dai wrote:
> Hi there,
> 
>      I've been banging my head on this for about two weeks, and I can't 
> figure out a solution to this. I'm wondering if you could assist me on 
> this pesky problem.
> 
>      I'm reading in an xml file that has the name of class, location, 
> and the filename into a dictionary. I want to import these classes and 
> create instances of them.  The code in question is as follows:
> 
>  36       for xmlKey in self.dictXML.keys():
>  37             if not self.dictXML[xmlKey]['location'] in sys.path and \
>  38             not self.dictXML[xmlKey]['location'] == os.getcwd():
>  39                 sys.path.append(self.dictXML[xmlKey]['location'])
>  40             try:
>  41                 if os.stat(self.dictXML[xmlKey]['location'] + \
>  42                 self.dictXML[xmlKey]['filename']):
>  43                     eval('import ' + 
> self.dictXML[xmlKey]["class"])   <-- syntax error here
>  44                     actionStmt=self.dictXML[xmlKey]["class"] + '.' + 
> self.dictXML [xmlKey]["class"] + '()' 45                    
> 45                          self.objList.append(eval(actionStmt))
> 46             except:
>  47                 pass
> 
> 
> I have also tried: __import__( self.dictXML[xmlKey]["class"]), which 
> gave me an error when I did the eval(actionStmt). Could anybody shed 
> some light on this? Thanks in advance.

eval() won't work because it evaluates expressions; import is a 
statement, not an expression. You might have better luck with exec for 
the import.

__import__() doesn't put the imported module into the global namespace 
the way an import statement does; it returns a reference to the module 
which you assign to a name. So I think you would need something like
module = __import__(self.dictXML[xmlKey]["class"])
obj = getattr(module, self.dictXML[xmlKey]["class"])()

Kent

From dkuhlman at rexx.com  Tue Jun 26 19:29:38 2007
From: dkuhlman at rexx.com (Dave Kuhlman)
Date: Tue, 26 Jun 2007 10:29:38 -0700
Subject: [Tutor] Importing and creation on the fly
In-Reply-To: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
References: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
Message-ID: <20070626172938.GA2457@cutter.rexx.com>

On Tue, Jun 26, 2007 at 12:20:18PM -0400, Tino Dai wrote:
> Hi there,
> 
>     I've been banging my head on this for about two weeks, and I can't
> figure out a solution to this. I'm wondering if you could assist me on this
> pesky problem.
> 
>     I'm reading in an xml file that has the name of class, location, and
> the filename into a dictionary. I want to import these classes and create
> instances of them.  The code in question is as follows:
> 
> 36       for xmlKey in self.dictXML.keys():
> 37             if not self.dictXML[xmlKey]['location'] in sys.path and \
> 38             not self.dictXML[xmlKey]['location'] == os.getcwd():
> 39                 sys.path.append(self.dictXML[xmlKey]['location'])
> 40             try:
> 41                 if os.stat(self.dictXML[xmlKey]['location'] + \
> 42                 self.dictXML[xmlKey]['filename']):
> 43                     eval('import ' + self.dictXML[xmlKey]["class"])
> <-- syntax error here
> 44                     actionStmt=self.dictXML[xmlKey]["class"] + '.' +
> self.dictXML[xmlKey]["class"] + '()' 45
> 45                          self.objList.append(eval(actionStmt))
> 46             except:
> 47                 pass
> 
> 
> I have also tried: __import__(self.dictXML[xmlKey]["class"]), which gave me
> an error when I did the eval(actionStmt). Could anybody shed some light on
> this? Thanks in advance.

For the task of importing, look at the "imp" module:

    http://docs.python.org/lib/module-imp.html

Also, the "inspect" module may be of help:

    http://docs.python.org/lib/module-inspect.html

In particular, look at the the inspect.getmembers() and
inspect.isclass() methods.

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman

From tinoloc at gmail.com  Tue Jun 26 20:18:34 2007
From: tinoloc at gmail.com (Tino Dai)
Date: Tue, 26 Jun 2007 14:18:34 -0400
Subject: [Tutor] Importing and creation on the fly
In-Reply-To: <20070626172938.GA2457@cutter.rexx.com>
References: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
	<20070626172938.GA2457@cutter.rexx.com>
Message-ID: <e033edfb0706261118i5fc5f697sc81715186c7b304b@mail.gmail.com>

On 6/26/07, Dave Kuhlman <dkuhlman at rexx.com> wrote:
>
> On Tue, Jun 26, 2007 at 12:20:18PM -0400, Tino Dai wrote:
> > Hi there,
> >
> >     I've been banging my head on this for about two weeks, and I can't
> > figure out a solution to this. I'm wondering if you could assist me on
> this
> > pesky problem.
> >
> >     I'm reading in an xml file that has the name of class, location, and
> > the filename into a dictionary. I want to import these classes and
> create
> > instances of them.  The code in question is as follows:
> >
> > 36       for xmlKey in self.dictXML.keys():
> > 37             if not self.dictXML[xmlKey]['location'] in sys.path and \
> > 38             not self.dictXML[xmlKey]['location'] == os.getcwd():
> > 39                 sys.path.append(self.dictXML[xmlKey]['location'])
> > 40             try:
> > 41                 if os.stat(self.dictXML[xmlKey]['location'] + \
> > 42                 self.dictXML[xmlKey]['filename']):
> > 43                     eval('import ' + self.dictXML[xmlKey]["class"])
> > <-- syntax error here
> > 44                     actionStmt=self.dictXML[xmlKey]["class"] + '.' +
> > self.dictXML[xmlKey]["class"] + '()' 45
> > 45                          self.objList.append(eval(actionStmt))
> > 46             except:
> > 47                 pass
> >
> >
> > I have also tried: __import__(self.dictXML[xmlKey]["class"]), which gave
> me
> > an error when I did the eval(actionStmt). Could anybody shed some light
> on
> > this? Thanks in advance.
>
> For the task of importing, look at the "imp" module:
>
>     http://docs.python.org/lib/module-imp.html
>
> Also, the "inspect" module may be of help:
>
>     http://docs.python.org/lib/module-inspect.html
>
> In particular, look at the the inspect.getmembers() and
> inspect.isclass() methods.
>
> Dave


 Thanks guys. I will look into that this afternoon

-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070626/372c24d8/attachment.htm 

From rabidpoobear at gmail.com  Tue Jun 26 22:47:00 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 26 Jun 2007 15:47:00 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
In-Reply-To: <b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>
References: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>	<ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>
	<b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>
Message-ID: <46817B44.3030900@gmail.com>

Johnny Jelinek wrote:
> sure, I wouldn't mind looking at your code :D!  Also, the graphical 
> one you sent me was using gif's, do you know how to render svg's on 
> screen?  The advantage to vector rather than raster is that you can 
> resize it as big as you could ever desire and it will never lose 
> quality.  That means I could make a resolution independent game :D!  
> Does anyone have any ideas on how to go about doing that?
Render it to a file, display the file in Pygame.
IF you're using Pygame already, you'll know the resolution of the screen 
that the user is using, so you'll be able to render them in the highest 
quality possible for that specific resolution.


From johnnyjiv at gmail.com  Wed Jun 27 01:44:45 2007
From: johnnyjiv at gmail.com (Johnny Jelinek)
Date: Tue, 26 Jun 2007 18:44:45 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
In-Reply-To: <46817B44.3030900@gmail.com>
References: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>
	<ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>
	<b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>
	<46817B44.3030900@gmail.com>
Message-ID: <b85797f20706261644u60b841c3u385a92761944ef40@mail.gmail.com>

how would I go about rendering an .svg to another file before showing it on
screen?  Could you point me to some resources or examples?  Thanks!

On 6/26/07, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> Johnny Jelinek wrote:
> > sure, I wouldn't mind looking at your code :D!  Also, the graphical
> > one you sent me was using gif's, do you know how to render svg's on
> > screen?  The advantage to vector rather than raster is that you can
> > resize it as big as you could ever desire and it will never lose
> > quality.  That means I could make a resolution independent game :D!
> > Does anyone have any ideas on how to go about doing that?
> Render it to a file, display the file in Pygame.
> IF you're using Pygame already, you'll know the resolution of the screen
> that the user is using, so you'll be able to render them in the highest
> quality possible for that specific resolution.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070626/aea213a4/attachment.html 

From rabidpoobear at gmail.com  Wed Jun 27 02:08:16 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Tue, 26 Jun 2007 19:08:16 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
In-Reply-To: <b85797f20706261644u60b841c3u385a92761944ef40@mail.gmail.com>
References: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>	
	<ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>	
	<b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>	
	<46817B44.3030900@gmail.com>
	<b85797f20706261644u60b841c3u385a92761944ef40@mail.gmail.com>
Message-ID: <4681AA70.9040405@gmail.com>

Johnny Jelinek wrote:
> how would I go about rendering an .svg to another file before showing 
> it on screen?  Could you point me to some resources or examples?  Thanks!
You just mentioned that Cairo renders svgs to a file, didn't you?
So can you just use pyCairo?
Google would tell you of other python modules that can render svg files.
I don't have any resources for doing this, I just assumed since you 
mentioned Cairo could do it that you knew
how to use Cairo to do it.
-Luke

From Dean.Gardner at barco.com  Wed Jun 27 11:58:50 2007
From: Dean.Gardner at barco.com (Gardner, Dean)
Date: Wed, 27 Jun 2007 11:58:50 +0200
Subject: [Tutor] Regular Expression help
Message-ID: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>

Hi 

I have a text file that I would like to split up so that I can use it in
Excel to filter a certain field. However as it is a flat text file I
need to do some processing on it so that Excel can correctly import it.

File Example:
tag 		desc			VR	VM
(0012,0042) Clinical Trial Subject Reading ID LO 1 
(0012,0050) Clinical Trial Time Point ID LO 1 
(0012,0051) Clinical Trial Time Point Description ST 1 
(0012,0060) Clinical Trial Coordinating Center Name LO 1 
(0018,0010) Contrast/Bolus Agent LO 1 
(0018,0012) Contrast/Bolus Agent Sequence SQ 1 
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1 
(0018,0015) Body Part Examined CS 1 

What I essentially want is to use python to process this file to give me



(0012,0042); Clinical Trial Subject Reading ID; LO; 1 
(0012,0050); Clinical Trial Time Point ID; LO; 1 
(0012,0051); Clinical Trial Time Point Description; ST; 1 
(0012,0060); Clinical Trial Coordinating Center Name; LO; 1 
(0018,0010); Contrast/Bolus Agent; LO; 1 
(0018,0012); Contrast/Bolus Agent Sequence; SQ ;1 
(0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1 
(0018,0015); Body Part Examined; CS; 1 

so that I can import to excel using a delimiter. 

This file is extremely long and all I essentially want to do is to break
it into it 'fields'

Now I suspect that regular expressions are the way to go but I have only
basic experience of using these and I have no idea what I should be
doing.
Can anyone help.

Thanks




DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070627/744761fa/attachment.html 

From tktucker at gmail.com  Wed Jun 27 14:26:17 2007
From: tktucker at gmail.com (Tom Tucker)
Date: Wed, 27 Jun 2007 08:26:17 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <2a278ffe0706270526w1a0b2a5au78a7c8ea575e4db2@mail.gmail.com>

I think I have a solution.

File
############################
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1


Script
#############################
#!/usr/bin/python

import re

#matchstr regex flow
# (\(\d+,\d+\))     # (0018,0014)
# \s                   # [space]
# (..*)                # Contrast/Bolus Administration Route Sequence
# \s                   # space
# ([a-z]{2})         # SQ - two letters and no more
# \s                  # [space]
# (\d)                # 1 - single digit
# re.I)               # case insensitive

matchstr = re.compile(r"(\(\d+,\d+\))\s(..*)\s([a-z]{2})\s(\d)",re.I)
myfile = open('/tmp/file','r')

for line in myfile.readlines():
        regex_match = matchstr.match(line)
        if regex_match:
                print regex_match.group(1) + ";" + regex_match.group(2) +
";" + regex_match.group(3) + ";" + regex_match.group(4)


Output
#####################
(0012,0042);Clinical Trial Subject Reading ID;LO;1
(0012,0050);Clinical Trial Time Point ID;LO;1
(0012,0051);Clinical Trial Time Point Description;ST;1
(0012,0060);Clinical Trial Coordinating Center Name;LO;1
(0018,0010);Contrast/Bolus Agent;LO;1
(0018,0012);Contrast/Bolus Agent Sequence;SQ;1
(0018,0014);Contrast/Bolus Administration Route Sequence;SQ;1
(0018,0015);Body Part Examined;CS;1


On 6/27/07, Gardner, Dean <Dean.Gardner at barco.com> wrote:
>
>  Hi
>
> I have a text file that I would like to split up so that I can use it in
> Excel to filter a certain field. However as it is a flat text file I need to
> do some processing on it so that Excel can correctly import it.
>
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
>
> What I essentially want is to use python to process this file to give me
>
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
>
> so that I can import to excel using a delimiter.
>
> This file is extremely long and all I essentially want to do is to break
> it into it 'fields'
>
> Now I suspect that regular expressions are the way to go but I have only
> basic experience of using these and I have no idea what I should be doing.
>
> Can anyone help.
>
> Thanks
>
> DISCLAIMER:
> Unless indicated otherwise, the information contained in this message is
> privileged and confidential, and is intended only for the use of the
> addressee(s) named above and others who have been specifically authorized to
> receive it. If you are not the intended recipient, you are hereby notified
> that any dissemination, distribution or copying of this message and/or
> attachments is strictly prohibited. The company accepts no liability for any
> damage caused by any virus transmitted by this email. Furthermore, the
> company does not warrant a proper and complete transmission of this
> information, nor does it accept liability for any delays. If you have
> received this message in error, please contact the sender and delete the
> message. Thank you.
>
> _______________________________________________
> 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/20070627/43800ea0/attachment.htm 

From johnnyjiv at gmail.com  Wed Jun 27 14:58:36 2007
From: johnnyjiv at gmail.com (Johnny Jelinek)
Date: Wed, 27 Jun 2007 07:58:36 -0500
Subject: [Tutor] Beginner Game: Rock, Paper, Scissors
In-Reply-To: <4681AA70.9040405@gmail.com>
References: <b85797f20706260611i7550bbc4v32dd37bc64bc6368@mail.gmail.com>
	<ea979d70706260653r13b04341va628fe7cb0a32089@mail.gmail.com>
	<b85797f20706260744h5702abft88890cd3710a01a6@mail.gmail.com>
	<46817B44.3030900@gmail.com>
	<b85797f20706261644u60b841c3u385a92761944ef40@mail.gmail.com>
	<4681AA70.9040405@gmail.com>
Message-ID: <b85797f20706270558g63f6cc22o713aa89a9aaad9d3@mail.gmail.com>

Cairo does do it to files, but -- that's from your source.  That's for if
you draw something with python and then want to save it to an svg.  It
doesn't take something that's already an svg and convert it or display it.
PIL will let me take advantage of all kind of graphical formats, but not any
that are vector, to my knowledge.  I want to take advantage of the vector,
if possible :D!

On 6/26/07, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> Johnny Jelinek wrote:
> > how would I go about rendering an .svg to another file before showing
> > it on screen?  Could you point me to some resources or
> examples?  Thanks!
> You just mentioned that Cairo renders svgs to a file, didn't you?
> So can you just use pyCairo?
> Google would tell you of other python modules that can render svg files.
> I don't have any resources for doing this, I just assumed since you
> mentioned Cairo could do it that you knew
> how to use Cairo to do it.
> -Luke
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070627/eeb30bc4/attachment.html 

From kent37 at tds.net  Wed Jun 27 15:55:07 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 8:55:07 -0500
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <20070627085507.TRES3.261835.root@webfep12>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
    match = fieldsRe.match(line)
    if match:
        print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your 
example; Excel wants a single-character delimiter.

Kent

From kent37 at tds.net  Wed Jun 27 15:36:49 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 09:36:49 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <468267F1.1080407@tds.net>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
     match = fieldsRe.match(line)
     if match:
         print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your 
example; Excel wants a single-character delimiter.

Kent

From Mike.Hansen at atmel.com  Wed Jun 27 16:26:39 2007
From: Mike.Hansen at atmel.com (Mike Hansen)
Date: Wed, 27 Jun 2007 08:26:39 -0600
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <57B026980605A64F9B23484C5659E32E852CD5@poccso.US.ad.atmel.com>

Argh... My e-mail program really messed up the threads. I didn't notice
that there was already multiple replies to this message.

Doh!

Mike

From Mike.Hansen at atmel.com  Wed Jun 27 16:24:22 2007
From: Mike.Hansen at atmel.com (Mike Hansen)
Date: Wed, 27 Jun 2007 08:24:22 -0600
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <57B026980605A64F9B23484C5659E32E852CD3@poccso.US.ad.atmel.com>

 

> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Gardner, Dean
> Sent: Wednesday, June 27, 2007 3:59 AM
> To: tutor at python.org
> Subject: [Tutor] Regular Expression help
> 
> Hi 
> 
> I have a text file that I would like to split up so that I 
> can use it in Excel to filter a certain field. However as it 
> is a flat text file I need to do some processing on it so 
> that Excel can correctly import it.
> 
> File Example: 
> tag             desc                    VR      VM 
> (0012,0042) Clinical Trial Subject Reading ID LO 1 
> (0012,0050) Clinical Trial Time Point ID LO 1 
> (0012,0051) Clinical Trial Time Point Description ST 1 
> (0012,0060) Clinical Trial Coordinating Center Name LO 1 
> (0018,0010) Contrast/Bolus Agent LO 1 
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1 
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1 
> (0018,0015) Body Part Examined CS 1 
> 
> What I essentially want is to use python to process this file 
> to give me 
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1 
> (0012,0050); Clinical Trial Time Point ID; LO; 1 
> (0012,0051); Clinical Trial Time Point Description; ST; 1 
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1 
> (0018,0010); Contrast/Bolus Agent; LO; 1 
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1 
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1 
> (0018,0015); Body Part Examined; CS; 1 
> 
> so that I can import to excel using a delimiter. 
> 
> This file is extremely long and all I essentially want to do 
> is to break it into it 'fields' 
> 
> Now I suspect that regular expressions are the way to go but 
> I have only basic experience of using these and I have no 
> idea what I should be doing.
> 
> Can anyone help. 
> 
> Thanks 
> 

Hmmmm... You might be able to do this without the need for regular
expressions. You can split the row on spaces which will give you a list.
Then you can reconstruct the row inserting your delimiter as needed and
joining the rest with spaces again.

In [63]: row = "(0012,0042) Clinical Trial Subject Reading ID LO 1"

In [64]: row_items = row.split(' ')

In [65]: row_items
Out[65]: ['(0012,0042)', 'Clinical', 'Trial', 'Subject', 'Reading',
'ID', 'LO',
'1']

In [66]: tag = row_items.pop(0)

In [67]: tag
Out[67]: '(0012,0042)'

In [68]: vm = row_items.pop()

In [69]: vm
Out[69]: '1'

In [70]: vr = row_items.pop()

In [71]: vr
Out[71]: 'LO'

In [72]: desc = ' '.join(row_items)

In [73]: new_row = "%s; %s; %s; %s" %(tag, desc, vr, vm, )

In [74]: new_row
Out[74]: '(0012,0042); Clinical Trial Subject Reading ID; LO; 1'

Someone might think of a better way with them thar fancy lambdas and
list comprehensions thingys, but I think this will work. 

Mike

From reed at reedobrien.com  Wed Jun 27 17:08:22 2007
From: reed at reedobrien.com (Reed O'Brien)
Date: Wed, 27 Jun 2007 11:08:22 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <57B026980605A64F9B23484C5659E32E852CD3@poccso.US.ad.atmel.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
	<57B026980605A64F9B23484C5659E32E852CD3@poccso.US.ad.atmel.com>
Message-ID: <4D43E839-84C1-45D5-9AC3-16A27BCB9919@reedobrien.com>


On Jun 27, 2007, at 10:24 AM, Mike Hansen wrote:

>
>
>> -----Original Message-----
>> From: tutor-bounces at python.org
>> [mailto:tutor-bounces at python.org] On Behalf Of Gardner, Dean
>> Sent: Wednesday, June 27, 2007 3:59 AM
>> To: tutor at python.org
>> Subject: [Tutor] Regular Expression help
>>
>> Hi
>>
>> I have a text file that I would like to split up so that I
>> can use it in Excel to filter a certain field. However as it
>> is a flat text file I need to do some processing on it so
>> that Excel can correctly import it.
>>
>> File Example:
>> tag             desc                    VR      VM
>> (0012,0042) Clinical Trial Subject Reading ID LO 1
>> (0012,0050) Clinical Trial Time Point ID LO 1
>> (0012,0051) Clinical Trial Time Point Description ST 1
>> (0012,0060) Clinical Trial Coordinating Center Name LO 1
>> (0018,0010) Contrast/Bolus Agent LO 1
>> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
>> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
>> (0018,0015) Body Part Examined CS 1
>>
>> What I essentially want is to use python to process this file
>> to give me
>>
>>
>> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
>> (0012,0050); Clinical Trial Time Point ID; LO; 1
>> (0012,0051); Clinical Trial Time Point Description; ST; 1
>> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
>> (0018,0010); Contrast/Bolus Agent; LO; 1
>> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
>> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
>> (0018,0015); Body Part Examined; CS; 1
>>
>> so that I can import to excel using a delimiter.
>>
>> This file is extremely long and all I essentially want to do
>> is to break it into it 'fields'
>>
>> Now I suspect that regular expressions are the way to go but
>> I have only basic experience of using these and I have no
>> idea what I should be doing.
>>
>> Can anyone help.
>>
>> Thanks
>>
>
> Hmmmm... You might be able to do this without the need for regular
> expressions. You can split the row on spaces which will give you a  
> list.
> Then you can reconstruct the row inserting your delimiter as needed  
> and
> joining the rest with spaces again.
>
> In [63]: row = "(0012,0042) Clinical Trial Subject Reading ID LO 1"
>
> In [64]: row_items = row.split(' ')
>
> In [65]: row_items
> Out[65]: ['(0012,0042)', 'Clinical', 'Trial', 'Subject', 'Reading',
> 'ID', 'LO',
> '1']
>
> In [66]: tag = row_items.pop(0)
>
> In [67]: tag
> Out[67]: '(0012,0042)'
>
> In [68]: vm = row_items.pop()
>
> In [69]: vm
> Out[69]: '1'
>
> In [70]: vr = row_items.pop()
>
> In [71]: vr
> Out[71]: 'LO'
>
> In [72]: desc = ' '.join(row_items)
>
> In [73]: new_row = "%s; %s; %s; %s" %(tag, desc, vr, vm, )
>
> In [74]: new_row
> Out[74]: '(0012,0042); Clinical Trial Subject Reading ID; LO; 1'
>
> Someone might think of a better way with them thar fancy lambdas and
> list comprehensions thingys, but I think this will work.
>
>
I sent this to Dean this morning:

Dean,

I would do something like this (if your pattern is always the same.)

  foo =['(0012,0042) Clinical Trial Subject Reading ID LO 1 ',
  '(0012,0050) Clinical Trial Time Point ID LO 1 ',
  '(0012,0051) Clinical Trial Time Point Description ST 1 ',
  '(0012,0060) Clinical Trial Coordinating Center Name LO 1 ',
  '(0018,0010) Contrast/Bolus Agent LO 1 ',
  '(0018,0012) Contrast/Bolus Agent Sequence SQ 1 ',
  '(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1 ',
  '(0018,0015) Body Part Examined CS 1',]

import csv
writer = csv.writer(open('/Users/reed/tmp/foo.csv', 'w'), delimiter=';')

for lin in foo:
     lin = lin.split()
     row = (lin[0], ' '.join(lin[1:-2]), lin[-2], lin[-1])
     writer.writerow(row)


more foo.csv
(0012,0042);Clinical Trial Subject Reading ID;LO;1
(0012,0050);Clinical Trial Time Point ID;LO;1
(0012,0051);Clinical Trial Time Point Description;ST;1
(0012,0060);Clinical Trial Coordinating Center Name;LO;1
(0018,0010);Contrast/Bolus Agent;LO;1
(0018,0012);Contrast/Bolus Agent Sequence;SQ;1
(0018,0014);Contrast/Bolus Administration Route Sequence;SQ;1
(0018,0015);Body Part Examined;CS;1


HTH,
~reed



From strider1551 at gmail.com  Wed Jun 27 17:26:17 2007
From: strider1551 at gmail.com (Adam A. Zajac)
Date: Wed, 27 Jun 2007 11:26:17 -0400
Subject: [Tutor] Removing a file from a tar
Message-ID: <20070627112617.274a35a2@lavos>

I was reading over the documentation for the tarfile module and it
occurred to me that there didn't seem to be a way to remove an
individual file from the tar.

For example, suppose I did this:

import tarfile
tar = tarfile.open("sample.tar", "w")
tar.add("unwanted")
tar.add("wanted")
tar.close()

At this point, how could I come back and remove "unwanted" from the tar?

From kent37 at tds.net  Wed Jun 27 18:22:36 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 12:22:36 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <2a278ffe0706270526w1a0b2a5au78a7c8ea575e4db2@mail.gmail.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
	<2a278ffe0706270526w1a0b2a5au78a7c8ea575e4db2@mail.gmail.com>
Message-ID: <46828ECC.50207@tds.net>

Tom Tucker wrote:
> #matchstr regex flow
> # (\(\d+,\d+\))     # (0018,0014)
> # \s                   # [space]
> # (..*)                # Contrast/Bolus Administration Route Sequence
> # \s                   # space
> # ([a-z]{2})         # SQ - two letters and no more
> # \s                  # [space]
> # (\d)                # 1 - single digit
> # re.I)               # case insensitive
> 
> matchstr = re.compile(r"(\(\d+,\d+\))\s(..*)\s([a-z]{2})\s(\d)",re.I)

You should learn about re.VERBOSE:
http://docs.python.org/lib/node46.html#l2h-414

With this flag, your commented version could be the actual regex, 
instead of repeating it in code with the whitespace and comments removed:

matchstr = re.compile(r'''
(\(\d+,\d+\))        # (0018,0014)
\s                   # [space]
(..*)                # Contrast/Bolus Administration Route Sequence
\s                   # space
([a-z]{2})           # SQ - two letters and no more
\s                  # [space]
(\d)                # 1 - single digit
re.I)               # case insensitive
''', re.I|re.VERBOSE)

Kent

From kent37 at tds.net  Wed Jun 27 15:38:06 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 09:38:06 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <4682683E.308@tds.net>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
     match = fieldsRe.match(line)
     if match:
         print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your 
example; Excel wants a single-character delimiter.

Kent

From kent37 at tds.net  Wed Jun 27 15:35:21 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 09:35:21 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <46826799.20305@tds.net>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
     match = fieldsRe.match(line)
     if match:
         print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your 
example; Excel wants a single-character delimiter.

Kent

From kent37 at tds.net  Wed Jun 27 15:54:01 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 09:54:01 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <46826BF9.5020100@tds.net>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
     match = fieldsRe.match(line)
     if match:
         print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your
example; Excel wants a single-character delimiter.

Kent


From kent37 at tds.net  Wed Jun 27 20:08:18 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 14:08:18 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <46826BF9.5020100@tds.net>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
	<46826BF9.5020100@tds.net>
Message-ID: <4682A792.3040201@tds.net>

Yikes! Sorry about all the duplicate postings. Thunderbird was telling 
me the send failed so I kept retrying; I guess it was actually sending!

Kent

From david at graniteweb.com  Wed Jun 27 22:38:14 2007
From: david at graniteweb.com (David Rock)
Date: Wed, 27 Jun 2007 15:38:14 -0500
Subject: [Tutor] Removing a file from a tar
In-Reply-To: <20070627112617.274a35a2@lavos>
References: <20070627112617.274a35a2@lavos>
Message-ID: <20070627203814.GA19144@wdfs.graniteweb.com>

* Adam A. Zajac <strider1551 at gmail.com> [2007-06-27 11:26]:
> I was reading over the documentation for the tarfile module and it
> occurred to me that there didn't seem to be a way to remove an
> individual file from the tar.
> 
> For example, suppose I did this:
> 
> import tarfile
> tar = tarfile.open("sample.tar", "w")
> tar.add("unwanted")
> tar.add("wanted")
> tar.close()
> 
> At this point, how could I come back and remove "unwanted" from the tar?

Wel, it looks like tar's --remove-files is not supported yet, you would
probably have to reopen the tarfile, write it to a new one file-by-file,
excluding the ones you don't want.  Messy :-(

-- 
David Rock
david at graniteweb.com

From laurenb01 at gmail.com  Wed Jun 27 23:31:57 2007
From: laurenb01 at gmail.com (Lauren)
Date: Wed, 27 Jun 2007 17:31:57 -0400
Subject: [Tutor] Finding all locations of a sequence
Message-ID: <91120f90706271431v15809b3et8499ec4c4fa512ac@mail.gmail.com>

Firstly, I'd like to thank everyone for their help. I ended up throwing
something together using dictionaries (because I understood those best out
of what I had), that was a lot faster than my initial attempt, but have run
into a different problem, that I was hoping for help with. So, what I have
is all the subsequences that I was looking for in separate entries in the
dictionary, and where each of them is found as the value. If a subsequence
binds to more than one other item, I want to have the locations of the items
all together.
The closest I've been able to manage to get to what I want is this:

dict_of_bond_location = {}
dict1 = {'AAA':['UUU'], 'AAU':['UUG', 'UUA'], 'AAC':['UUG'], 'AAG':['UUC',
'UUU'], 'CCC':['GGG']}
dict2 = {'AAA':[1], 'AAU':[2], 'AAC':[3], 'AAG':[0, 4], 'GGG':[10]}
dict3 = {'UUU':[3, 5], 'UUG':[0], 'UUA':[1], 'UUC':[2], 'GGG':[14]}


for key in dict2:
    if key in dict1:
        matching_subseq = dict1.get(key)
        for item in matching_subseq:
            if item in dict3:
                location = dict3.get(item)
                dict_of_bond_location.setdefault(key, []).append(location)
print dict_of_bond_location

which gives this:
{'AAU': [[0], [1]], 'AAG': [[2], [3, 5]], 'AAA': [[3, 5]], 'AAC': [[0]]}

but what I want is
'AAU':[0, 1], 'AAG':[2, 3, 5], 'AAA':[3. 5], 'AAC':[0]

the setdefault(key, []).append(location) thing sort of does what I want, but
I don't want the result to be a list of lists...just one big list. The
production of a new dictionary is not necessary, but it made sense to me a
few hours ago. Anyway, is there a fast and dirty way to add lists together,
if the lists are not named (I think that's essentially what I want?)

Thanks again,

Lauren



On 19/06/07, tutor-request at python.org <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: iterating over a sequence question.. (Luke Paireepinart)
>    2. Re: Help converting base32 to base16 (Alan Gauld)
>    3. Re: Finding all locations of a sequence (fwd) (Danny Yoo)
>    4. Re: sockets ( Linus Nordstr?m )
>    5. Re: sockets (Alan Gauld)
>    6. Re: Finding all locations of a sequence (fwd) (Alan Gauld)
>    7. Re: cannot pickle instancemethod objects (hok kakada)
>    8. Re: Python and XSI (Vishal Jain)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 18 Jun 2007 13:37:21 -0500
> From: "Luke Paireepinart" <rabidpoobear at gmail.com>
> Subject: Re: [Tutor] iterating over a sequence question..
> To: "Simon Hooper" <simon at partex.co.uk>, tutor at python.org
> Message-ID:
>         <dfeb4470706181137x737f84b9l358a84c8c2043b16 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On 6/18/07, Simon Hooper <simon at partex.co.uk> wrote:
> >
> > Hi Luke,
> >
> > * On 17/06/07, Luke Paireepinart wrote:
> > > a more expanded version that accounts for either list being the longer
> > > one, or both being the same length, would be:
> > >
> > >  >>> if len(t) > len(l): x = len(t)
> > > else: x = len(l)
> > >  >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
> > > [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]
> >
> > Being the duffer that I am, I'm very pleased with myself that I came up
> > with a similar solution (albeit as a function rather than a list
> > comprehension) :)
> >
> > You do not need the if statement either,
>
>
> Yeah, I never knew about the max() function!
> I noticed someone else used it in one of their solutions.
> I'm pretty sure I've seen it a lot before, just didn't remember it.
> -Luke
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/tutor/attachments/20070618/1cf0ac67/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Mon, 18 Jun 2007 21:12:02 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Help converting base32 to base16
> To: tutor at python.org
> Message-ID: <f56oul$lah$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>         reply-type=original
>
>
> "Jason Massey" <jason.massey at gmail.com> wrote
>
> >  Nice entry at wikipedia:
> >
> > http://en.wikipedia.org/wiki/Base_32
> >
>
> Thanks for the link, I should have thought of oooking there!
> I've heardof Base64 for encoding email but never come
> across Base32 - any of the versions!
>
> Alan G.
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 18 Jun 2007 16:54:53 -0400 (EDT)
> From: Danny Yoo <dyoo at cs.wpi.edu>
> Subject: Re: [Tutor] Finding all locations of a sequence (fwd)
> To: tutor at python.org
> Message-ID: <Pine.LNX.4.63.0706181653280.18230 at cs.wpi.edu>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> Hi everyone,
>
> Can someone help Lauren?  I apologize for this, but I am very time
> constrained at this moment, and won't be able to reply back for at least a
> few hours.  His question is below.  Thanks!
>
>
> ---------- Forwarded message ----------
> Date: Mon, 18 Jun 2007 16:41:39 -0400
> From: Lauren <laurenb01 at gmail.com>
> To: Danny Yoo <dyoo at cs.wpi.edu>
> Subject: Re: [Tutor] Finding all locations of a sequence
>
> Ok, these may be useful. I do have a potentially embarrassing problem,
> however I will preface this with I'm practically computer illiterate. Ok
> after I download the one you wrote (which I think I understand better than
> the one listed previous...famous last words, I'm sure), but when I ask to
> import the ahocorasick module, it says it can't find it :( Is it possible
> to
> get step by step instructions on how to open the module? Do I need
> something
> other than the latest download for it?
> Again, I'm not good at this programming thing, so I'm sure I'm missing
> something obvious
>
> Thank you for your help,
>
> Lauren
>
> On 18/06/07, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> >
> >
> >
> >> Ok, what I have is a RNA sequence (about 5 million nucleotides
> >> [characters] long) and have (4100) subsequences (from another sequence)
> >> and the sub-sequences are 6 characters long, that I want to find in it.
> >
> > Hi Lauren,
> >
> > I am positive that this problem has been tackled before.  Have you
> talked
> > to any of your fellow bioinformaticists?  It might not be effective to
> ask
> > on Python-tutor because, for typical problems, regexes are sufficient.
> > For your particular scenario, regexes may not be, so you may want to ask
> > specialists like those on the Biopython mailing lists:
> >
> >      http://biopython.org/wiki/Mailing_lists
> >
> > It may seem like a simple extension of regular expression search, but as
> > you may have noticed, feeding 4100 regex searches across that RNA
> sequence
> > is going to take some time.  And trying to feed all of those
> subsequences
> > as a single regular expression (using ORs) is probably not going to work
> > too well either: the engine has limitations on how large the pattern can
> > be before it starts behaving very badly.
> >
> >
> > To scale to this problem, we need to do something different.  What
> you're
> > probably looking for is more typically known as the keyword matching
> > problem, and there are algorithms specifically used for keyword
> matching.
> > For example, take a look at Nicholas Lehuen's Pytst package, which
> > implements ternary search trees:
> >
> >      http://nicolas.lehuen.com/index.php/category/Pytst
> >
> > I've also written a different package that uses the "Aho-Corasick"
> > automata matcher, but to tell the truth I've let the code stale a bit,
> and
> > can't support it (too busy with other work).  But if you're interested
> in
> > tinkering with it, it's here:
> > http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/<
> http://hkn.eecs.berkeley.edu/%7Edyoo/python/ahocorasick/>
> > .
> >
> >
> > If you're going to do more string-matching stuff, I'd recommend a look
> > into "Algorithms on Strings, Trees, and Sequences".
> >
> >      http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198
> >
> > It's one of the better books on bioinformatics string algorithms, and it
> > specifically covers this class of sequence-searching problems.
> >
>
>
>
> --
> Lauren
>
> Laurenb01 at gmail.com
>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 19 Jun 2007 01:19:45 +0200
> From: " Linus Nordstr?m " <linusno at gmail.com>
> Subject: Re: [Tutor] sockets
> To: Tutor at python.org
> Message-ID:
>         <1eb3a0e10706181619r762bdacdqf64424148d0749dd at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> gusse i use this thread as my own little help thread.. :)
>
> im having problem whit recv. It will not break the loop if ther are
> nothing more to recive. It dose recv all tit should, but then it go
> another round in the loop and get stuck on recv, as far as print
> debugging has showed,  Dont realy know waht ells information i could
> write sown to make my problem anny clrearer, so ask if anythin is
> unclear :)
>
> And on another note, is there a way to use the self. less, it might be
> just me but it looks rather ugly :)
>
> def recive(self):
>          all_data = []
>          while 1:
>              self.buf = self.s.recv(4096)
>              if not self.buf: break
>              all_data.append(self.buf)
>          return all_data
>
>
> On 6/18/07, Linus Nordstr?m <linus at linusnordstrom.com> wrote:
> > Hello
> > I'm trying to rewrite a chat-program i did in school this spring in
> > python, the school program was in java. All this to leran python.
> >
> > Anyway. I m trying to send a message using udp to a server that
> > conntains the message 3 0 0 0, it has to be in network byte order and
> > unsigned. I have tried to send it like a string "3000" but get an
> > error message from the server saying that it did recive 4 bytes, but
> > that it was an unknown message
> >
> > So what i am wondering is if there are anny special byte arrays, or
> > some thing i should use. or if there are anny other way than to send
> > the message than a string.
> >
>
>
> ------------------------------
>
> Message: 5
> Date: Tue, 19 Jun 2007 00:34:28 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] sockets
> To: tutor at python.org
> Message-ID: <f574q7$tlr$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>         reply-type=original
>
> "Linus Nordstr?m" <linusno at gmail.com> wrote
>
> > im having problem whit recv. It will not break the loop if ther are
> > nothing more to recive.
>
> Take a look at the client side of the address book
> example in my network profgramming topic. It shows
> an example of breaking out of a recv loop.
>
> Another option is to use the select module services
>
> > And on another note, is there a way to use the self. less,
> > it might be just me but it looks rather ugly :)
>
> No, it's good practice, it distinguishes between class level
> variables and local variables. The use of self/this etc is usually
> required in industrial coding standards for C++ and Java
> (eg Dept of defense/Government etc) for the same reason,
> even though those languages don't require it. As in many
> things python is simply enforcing what is already considered
> good practice elsewhere.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Tue, 19 Jun 2007 00:37:46 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Finding all locations of a sequence (fwd)
> To: tutor at python.org
> Message-ID: <f5750e$u4o$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>         reply-type=original
>
>
> > From: Lauren <laurenb01 at gmail.com>
> > To: Danny Yoo <dyoo at cs.wpi.edu>
> > Subject: Re: [Tutor] Finding all locations of a sequence
> >
> > after I download the one you wrote (which I think I understand
> > better than
> > the one listed previous...famous last words, I'm sure), but when I
> > ask to
> > import the ahocorasick module, it says it can't find it :(
>
> You will need to ocate and download the module too.
> Either store it along with your program or in the site-packages
> folder in your python installation.
>
> > get step by step instructions on how to open the module?
>
> You just import it.
> You can read more about that in my modules and functions topic
> if that helps.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Tue, 19 Jun 2007 12:19:31 +0700
> From: hok kakada <hokkakada at khmeros.info>
> Subject: Re: [Tutor] cannot pickle instancemethod objects
> To: tutor-python <tutor at python.org>
> Message-ID: <200706191219.32263.hokkakada at khmeros.info>
> Content-Type: text/plain;  charset="utf-8"
>
> ?????? ??? 13 ?????? 2007 19:09, Kent Johnson ??????????????
> > hok kakada wrote:
> > >> What kind of object is matcher? Does it have any attributes that are
> > >> functions? (Not methods you defined for the class, but functions or
> > >> methods that you assign to attributes of self.)
> > >
> > > Actually, I use the translate-toolkit from
> > > http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/
> > > in translate/search/match.py:
> > >         if comparer is None:
> > >             comparer = lshtein.LevenshteinComparer(max_length)
> > >
> >  >         self.comparer = comparer
> > >
> > > I just found the problem that it is because of the
> LevenshteinComparer.
> > > Once I assign self.comparer = None, the I can dump the matcher
> > > successfully. However, I still don't understand what could be wrong
> with
> > > LevenshteinComparer.
> >
> > I think the problem is this code in LevenshteinComparer.__init__():
> >
> >          if Levenshtein:
> >              self.distance = self.native_distance
> >          else:
> >              self.distance = self.python_distance
> >
> > which assigns an instance method to an instance attribute; this is the
> > instancemethod that can't be pickled.
> Ok...but how can we deal with it?
>
> Kind Regards,
> da
>
>
> ------------------------------
>
> Message: 8
> Date: Tue, 19 Jun 2007 12:08:36 +0400
> From: "Vishal Jain" <vishal.thebigv at gmail.com>
> Subject: Re: [Tutor] Python and XSI
> To: tutor at python.org
> Message-ID:
>         <5f3b7ddd0706190108y7ebe22ax2e859fb3760d1ee2 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Yes XSI is a 3D package from Avid. Also knows as Softimage|XSI
>
> By everything failed I mean that XSI isnt registering Python resulting in
> I
> cant select scripitng langauge as Python inside XSI. After running the
> said
> script the command prompt says "Python:Registered" but no error messages.
>
> Yes XSI supports only ActiveX Scripts.
>
> If everything goes good I expect to select scripting langauge as Python
> inside XSI and start scripting. But apparently eveything went good as per
> the manuals and docs except my luck :(
>
> I did search google but will search more as per your guidlines. And I am a
> beginner too in Python. I never coded before.
>
> Thanks a lot for ur suggestions and concern.
>
> By the way are you the same Alan Gauld who posts in XSI Base and CG Talk??
>
> Vishal
>
> Message: 6
> Date: Mon, 18 Jun 2007 16:09:35 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Python and XSI
> To: tutor at python.org
> Message-ID: <f5677j$e1f$1 at sea.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>        reply-type=original
>
> "Vishal Jain" <vishal.thebigv at gmail.com> wrote
>
> > I am trying to get Python registered with XSI but
> > everything described in docs failed.
>
> OK, I'm assuming that XSI is the 3D Graphics software from Avid?
>
> Can you tell us which docs and what exactly 'failed' means?
> What did you do and what actually happened?
> Any error messages?
>
> > C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py
>
> ISTR that as being the script for registering Python as an
> Active Scripting language for WSH and the IE ActiveX engine.
>
> I assume from that, that XSI uses active scripting?
>
> What did you expect to happen after running it?
> And what did happen?
>
> > still no luck. Is anybody else also facing the same situation? I am
> > not very
> > sure how many people here uses Python for XSI but still hoping to
> > get some
>
> I had to do a Google search...
> You might have more luck on the main comp.lang.python list or
> maybe even in the pyGame list. This group is for beginners to Python
> and XSI looks a tad advanced for most beginners, going by the couple
> of pages I browsed. OTOH there is usually somebody here with an
> interest in most things...
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/tutor/attachments/20070619/ded2eb30/attachment.htm
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 40, Issue 46
> *************************************
>



-- 
Lauren

Laurenb01 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070627/715d7501/attachment.htm 

From rabidpoobear at gmail.com  Wed Jun 27 23:48:42 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Wed, 27 Jun 2007 16:48:42 -0500
Subject: [Tutor] Finding all locations of a sequence
In-Reply-To: <91120f90706271431v15809b3et8499ec4c4fa512ac@mail.gmail.com>
References: <91120f90706271431v15809b3et8499ec4c4fa512ac@mail.gmail.com>
Message-ID: <4682DB3A.5080802@gmail.com>

Lauren wrote:
> Firstly, I'd like to thank everyone for their help. I ended up 
> throwing something together using dictionaries (because I understood 
> those best out of what I had), that was a lot faster than my initial 
> attempt, but have run into a different problem, that I was hoping for 
> help with. So, what I have is all the subsequences that I was looking 
> for in separate entries in the dictionary, and where each of them is 
> found as the value. If a subsequence binds to more than one other 
> item, I want to have the locations of the items all together.
> The closest I've been able to manage to get to what I want is this:
>
> dict_of_bond_location = {}
> dict1 = {'AAA':['UUU'], 'AAU':['UUG', 'UUA'], 'AAC':['UUG'], 
> 'AAG':['UUC', 'UUU'], 'CCC':['GGG']}
> dict2 = {'AAA':[1], 'AAU':[2], 'AAC':[3], 'AAG':[0, 4], 'GGG':[10]}
> dict3 = {'UUU':[3, 5], 'UUG':[0], 'UUA':[1], 'UUC':[2], 'GGG':[14]}
>
>
> for key in dict2:
>     if key in dict1:
>         matching_subseq = dict1.get(key)
>         for item in matching_subseq:
>             if item in dict3:
>                 location = dict3.get(item)
>                 dict_of_bond_location.setdefault(key, 
> []).append(location)
> print dict_of_bond_location
>
> which gives this:
> {'AAU': [[0], [1]], 'AAG': [[2], [3, 5]], 'AAA': [[3, 5]], 'AAC': [[0]]}
>
> but what I want is
> 'AAU':[0, 1], 'AAG':[2, 3, 5], 'AAA':[3. 5], 'AAC':[0]
>                
> the setdefault(key, []).append(location) thing sort of does what I 
> want, but I don't want the result to be a list of lists...just one big 
> list. The production of a new dictionary is not necessary, but it made 
> sense to me a few hours ago. Anyway, is there a fast and dirty way to 
> add lists together, if the lists are not named (I think that's 
> essentially what I want?)
Lauren,
Try this:
 >>> x = ['a']
 >>> y = x.extend(['b','c'])
 >>> x
['a', 'b', 'c']

But note that
 >>> print y
None

Because the extend method doesn't return anything.
HTH,
-Luke

From dos.fool at gmail.com  Thu Jun 28 02:15:37 2007
From: dos.fool at gmail.com (max .)
Date: Wed, 27 Jun 2007 18:15:37 -0600
Subject: [Tutor] python port scanner
In-Reply-To: <OFBF8FE3A9.8C8ABA27-ONC1257305.003B9D03-C1257305.003C5CDE@velux.com>
References: <mailman.37.1182765611.8674.tutor@python.org>
	<OFBF8FE3A9.8C8ABA27-ONC1257305.003B9D03-C1257305.003C5CDE@velux.com>
Message-ID: <857e4c3d0706271715l5ba72684i6265bc3e95d49412@mail.gmail.com>

thanks evryone for your help am starting on the project :)

On 6/25/07, J?nos Juh?sz <janos.juhasz at velux.com> wrote:
>
>
> Dear dos,
>
> >>hello i am looking into writing a simple python port scanner but i cant
> find
> >>any good tutorials online if anyone can help or knows of any tutorials
> that
> >>could help it would be great. this would be my first program like this
> so i
> >>might need a little extra help
>
> I just recommend to take a look on twisted
> http://www.oreilly.com/catalog/twistedadn/
> It is a nice book.
>
> There is an example on how to do it with twisted among the examples in
> chapter 2.
>
>
> You can read it on safari.
>
> Janos
> _______________________________________________
> 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/20070627/7671b578/attachment.htm 

From kent37 at tds.net  Wed Jun 27 15:39:20 2007
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 27 Jun 2007 09:39:20 -0400
Subject: [Tutor] Regular Expression help
In-Reply-To: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
Message-ID: <46826888.1050607@tds.net>

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it in 
> Excel to filter a certain field. However as it is a flat text file I 
> need to do some processing on it so that Excel can correctly import it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1
> (0012,0050); Clinical Trial Time Point ID; LO; 1
> (0012,0051); Clinical Trial Time Point Description; ST; 1
> (0012,0060); Clinical Trial Coordinating Center Name; LO; 1
> (0018,0010); Contrast/Bolus Agent; LO; 1
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1
> (0018,0014); Contrast/Bolus Administration Route Sequence; SQ; 1
> (0018,0015); Body Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to break 
> it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have only 
> basic experience of using these and I have no idea what I should be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
     match = fieldsRe.match(line)
     if match:
         print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your 
example; Excel wants a single-character delimiter.

Kent

From tinoloc at gmail.com  Thu Jun 28 15:24:20 2007
From: tinoloc at gmail.com (Tino Dai)
Date: Thu, 28 Jun 2007 09:24:20 -0400
Subject: [Tutor] Importing and creation on the fly
In-Reply-To: <e033edfb0706261118i5fc5f697sc81715186c7b304b@mail.gmail.com>
References: <e033edfb0706260920n167c2da5sdf47af09cdb0052b@mail.gmail.com>
	<20070626172938.GA2457@cutter.rexx.com>
	<e033edfb0706261118i5fc5f697sc81715186c7b304b@mail.gmail.com>
Message-ID: <e033edfb0706280624l70fc3f83q63622cd09f15552b@mail.gmail.com>

On 6/26/07, Tino Dai <tinoloc at gmail.com> wrote:
>
> On 6/26/07, Dave Kuhlman <dkuhlman at rexx.com> wrote:
>
> > On Tue, Jun 26, 2007 at 12:20:18PM -0400, Tino Dai wrote:
> > > Hi there,
> > >
> > >     I've been banging my head on this for about two weeks, and I can't
> > > figure out a solution to this. I'm wondering if you could assist me on
> > this
> > > pesky problem.
> > >
> > >     I'm reading in an xml file that has the name of class, location,
> > and
> > > the filename into a dictionary. I want to import these classes and
> > create
> > > instances of them.  The code in question is as follows:
> > >
> > > 36       for xmlKey in self.dictXML.keys():
> > > 37             if not self.dictXML[xmlKey]['location'] in sys.path and
> > \
> > > 38             not self.dictXML[xmlKey]['location'] == os.getcwd():
> > > 39                 sys.path.append(self.dictXML[xmlKey]['location'])
> > > 40             try:
> > > 41                 if os.stat(self.dictXML[xmlKey]['location'] + \
> > > 42                 self.dictXML[xmlKey]['filename']):
> > > 43                     eval('import ' + self.dictXML[xmlKey]["class"])
> > > <-- syntax error here
> > > 44                     actionStmt=self.dictXML [xmlKey]["class"] + '.'
> > +
> > > self.dictXML[xmlKey]["class"] + '()' 45
> > > 45                          self.objList.append(eval(actionStmt))
> > > 46             except:
> > > 47                 pass
> > >
> > >
> > > I have also tried: __import__(self.dictXML[xmlKey]["class"]), which
> > gave me
> > > an error when I did the eval(actionStmt). Could anybody shed some
> > light on
> > > this? Thanks in advance.
> >
> > For the task of importing, look at the "imp" module:
> >
> >     http://docs.python.org/lib/module-imp.html
> >
> > Also, the "inspect" module may be of help:
> >
> >     http://docs.python.org/lib/module-inspect.html
> >
> > In particular, look at the the inspect.getmembers() and
> > inspect.isclass() methods.
> >
> > Dave
>
>
>  Thanks guys. I will look into that this afternoon
>
> -Tino
>
> Hi Everybody,

      This is the solution that I came up with. Using Dave's advice:

      fp, pathname, description = imp.find_module(self.dictXML
[xmlKey]["class"])
      tarMod = imp.load_module('apacheLimiter',fp,pathname,description)
      tarClass = getattr(tarMod,self.dictXML[xmlKey]["class"])
      tarObj=tarClass()
      if hasattr(tarObj,'do'):
            self.objList.append(tarObj)

       So, I used the find_module to find the particular module that I
wanted, returning the filename, path to the module, and the description (see
the docs.python.org for more info). Next, I loaded the module from the info
provided to me. After loading the module, I "extracted" the class that I
wanted using the getattr function. After I had the class loaded, I created
an instance from it.

     I also checked out the exec function Kent. And one of my colleagues
recommended execfile. I felt like that was "hack" to get around a problem
(IHMO). Thanks for everything.

-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070628/86cdb57e/attachment.html 

From keridee at jayco.net  Thu Jun 28 12:03:53 2007
From: keridee at jayco.net (Jacob S.)
Date: Thu, 28 Jun 2007 10:03:53 -0000
Subject: [Tutor] Removing a file from a tar
References: <20070627112617.274a35a2@lavos>
	<20070627203814.GA19144@wdfs.graniteweb.com>
Message-ID: <00ed01c7b96b$a64f90e0$44fce004@JSLAPTOP>

>* Adam A. Zajac <strider1551 at gmail.com> [2007-06-27 11:26]:
>> I was reading over the documentation for the tarfile module and it
>> occurred to me that there didn't seem to be a way to remove an
>> individual file from the tar.
>>
>> For example, suppose I did this:
>>
>> import tarfile
>> tar = tarfile.open("sample.tar", "w")
>> tar.add("unwanted")
>> tar.add("wanted")
>> tar.close()
>>
>> At this point, how could I come back and remove "unwanted" from the tar?
>
> Wel, it looks like tar's --remove-files is not supported yet, you would
> probably have to reopen the tarfile, write it to a new one file-by-file,
> excluding the ones you don't want.  Messy :-(

Disclaimer: I was not alive during the described era. This information may 
be off or just plain wrong. Perhaps someone who was alive then will correct 
any errors(?).

Remove is not supported because of the way tar s were designed. They were 
designed for tape drive backups, that is 'tar' Tape ARchive. Because they 
were designed as a backup scheme for tape drives, there was no need to have 
a remove function.

|  File1 | File2 | File3 |
Remove File2
| File1 |       | File3|

Moving file3 up would mean that the tape would have to rock back and forth, 
something that tapes just weren't supposed to do. Not moving file3 up would 
very nearly defeat the purpose of deleting file2 in the first place: to save 
space. (Which was important then - and should be now... tsk, tsk Microsoft)

Anyway, there was no need to have a remove function because people just did 
what Adam said - write a whole new tape. Now that tar is no longer widely 
used for tapes, there are other formats (like RAR) that *are* designed for 
modern storage equipment.

HTH,
Tiger12506 


From wildcard2007 at comcast.net  Thu Jun 28 20:55:00 2007
From: wildcard2007 at comcast.net (Terry)
Date: Thu, 28 Jun 2007 11:55:00 -0700
Subject: [Tutor] Money matters
Message-ID: <1183056900.1782.14.camel@localhost.localdomain>

I am going to need to be handling money calculations and was wondering
about the float problem 
in my calculations.

Should I simply run the results of all calculations through something
like this:

from __future__ import division
...
...
s=(int(round(s, 2)*100))/100

Or should I be using Decimal on all money calculations?

Or, is there another more preferred approach?







-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070628/3f6e4fab/attachment.html 

From broek at cc.umanitoba.ca  Fri Jun 29 00:09:39 2007
From: broek at cc.umanitoba.ca (Brian van den Broek)
Date: Thu, 28 Jun 2007 18:09:39 -0400
Subject: [Tutor] Money matters
In-Reply-To: <1183056900.1782.14.camel@localhost.localdomain>
References: <1183056900.1782.14.camel@localhost.localdomain>
Message-ID: <468431A3.5030206@cc.umanitoba.ca>

Terry said unto the world upon 06/28/2007 02:55 PM:
> I am going to need to be handling money calculations and was wondering
> about the float problem 
> in my calculations.
> 
> Should I simply run the results of all calculations through something
> like this:
> 
> from __future__ import division
> ...
> ...
> s=(int(round(s, 2)*100))/100
> 
> Or should I be using Decimal on all money calculations?
> 
> Or, is there another more preferred approach?


Hi Terry,

I'd say definitely use Decimal. Money calculations were a primary use 
case for the Decimal module. (Though a bit more needs to be done to 
get the right decimal precision. See 
<http://www.python.org/dev/peps/pep-0327/>.)

Best,

Brian vdB

From keridee at jayco.net  Thu Jun 28 21:37:26 2007
From: keridee at jayco.net (Tiger12506)
Date: Thu, 28 Jun 2007 19:37:26 -0000
Subject: [Tutor] Money matters
References: <1183056900.1782.14.camel@localhost.localdomain>
Message-ID: <000801c7b9bb$cead8650$8bfce004@JSLAPTOP>

> Should I simply run the results of all calculations through something
> like this:
>
> from __future__ import division
> ...
> ...
> s=(int(round(s, 2)*100))/100
>
> Or should I be using Decimal on all money calculations?

Firstly - that does not magically fix the imprecisions in floating point
numbers. If that would work, it would be hardcoded into the interpreter, no?

I think that Decimal is the way to go here, but you do have another option.
Whenever you put in a number, remove the decimal point and store it as an
integer. Do all of you calculations with integers. Every time you have to
display a total, convert it then (but don't overwrite the variable! Convert
a temp)

Obviously this is a tough way to go in an easy language like python. That is
a solution I am considering using C. (I might just make it too..) That's why
I encouraged Decimal.

If you're interested in the integer representation of floats, like this
particular efficiency & precision demon (me!), then you will have to work
out ways to multiply and divide using pseudo floats... Not too difficult.
Say you want to multiply an integer against say 5.5 %. Multiply the total by
ten, 55, then divide by a 100. In that order. Of course you will still have
problems. For example do it over and over and you will overflow your
integer, but nevermind. Am I rambling? Ooops.

HTH,
tiger12506


From maseriyer at yahoo.com  Fri Jun 29 03:05:51 2007
From: maseriyer at yahoo.com (Iyer)
Date: Thu, 28 Jun 2007 18:05:51 -0700 (PDT)
Subject: [Tutor] Iterating through two lists at the same time with
	manipulation..
Message-ID: <382997.67020.qm@web50706.mail.re2.yahoo.com>

I have 2 lists:

List 1 has lists in it, such as

list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]

There is another list2 such as

list2 = [[1,'AA'],[3,'CC'], [4,'DD']]

For eg,

I wish to iterate over both the lists and produce the output 

a = [[1,'A'],[1,'AA']]
b = [[2,'B']]
c = [[3,'C'],[3,'CC']]
d = [[4,'D'],[4,'DD']]

Or [a,b,c,d] where a,b,c,d are defined above

What would be the best and quickest way to carry this out ? This list comprehension doesn't seem to get the desired result:

[[x,y] for x in list1 for y in list2 if x[0]==y[0]]

the sub-list [2,'B'] in list1 is left out. i.e, the output is 
[[[1, 'A'], [1, 'AA']], [[3, 'C'], [3, 'CC']], [[4, 'D'], [4, 'DD']]]


       
---------------------------------
Moody friends. Drama queens. Your life? Nope! - their life, your story.
 Play Sims Stories at Yahoo! Games. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070628/ae4769ca/attachment.html 

From terry.kemmerer at gmail.com  Fri Jun 29 03:10:11 2007
From: terry.kemmerer at gmail.com (Terry)
Date: Thu, 28 Jun 2007 18:10:11 -0700
Subject: [Tutor] Money matters
Message-ID: <1183079411.5826.40.camel@localhost.localdomain>



Thanks! I am playing with Decimal suggested recipe now and it is just
way cool! Perfect!  In fact, more than perfect!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070628/51be69b7/attachment.htm 

From john at fouhy.net  Fri Jun 29 03:23:31 2007
From: john at fouhy.net (John Fouhy)
Date: Fri, 29 Jun 2007 13:23:31 +1200
Subject: [Tutor] Iterating through two lists at the same time with
	manipulation..
In-Reply-To: <382997.67020.qm@web50706.mail.re2.yahoo.com>
References: <382997.67020.qm@web50706.mail.re2.yahoo.com>
Message-ID: <5e58f2e40706281823r61eced51vc7acbe9e829a0adc@mail.gmail.com>

On 29/06/07, Iyer <maseriyer at yahoo.com> wrote:
> I have 2 lists:
>
> List 1 has lists in it, such as
>
> list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]
>
> There is another list2 such as
>
> list2 = [[1,'AA'],[3,'CC'], [4,'DD']]
>
> For eg,
>
> I wish to iterate over both the lists and produce the output
>
> a = [[1,'A'],[1,'AA']]
> b = [[2,'B']]
> c = [[3,'C'],[3,'CC']]
> d = [[4,'D'],[4,'DD']]

Your best choice is probably just to do it "by hand":

i1 = 0
i2 = 0
output = []
while True:
    # compare list1[i] and list2[i2]
    # produce appropriate output
    # advance i1 or i2

Alternatively, you could shove the data into a sqlite in-memory
database, then use SQL to pull it back out.

-- 
John.

From kent37 at tds.net  Fri Jun 29 04:37:48 2007
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 28 Jun 2007 22:37:48 -0400
Subject: [Tutor] Iterating through two lists at the same time
	with	manipulation..
In-Reply-To: <382997.67020.qm@web50706.mail.re2.yahoo.com>
References: <382997.67020.qm@web50706.mail.re2.yahoo.com>
Message-ID: <4684707C.2060300@tds.net>

Iyer wrote:
> I have 2 lists:
> 
> List 1 has lists in it, such as
> 
> list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]
> 
> There is another list2 such as
> 
> list2 = [[1,'AA'],[3,'CC'], [4,'DD']]
> 
> For eg,
> 
> I wish to iterate over both the lists and produce the output
> 
> a = [[1,'A'],[1,'AA']]
> b = [[2,'B']]
> c = [[3,'C'],[3,'CC']]
> d = [[4,'D'],[4,'DD']]
> 
> Or [a,b,c,d] where a,b,c,d are defined above
> 
> What would be the best and quickest way to carry this out ?

If you want the result ordered by  the first element, you can combine 
the two lists, sort the combined list, and use itertools.groupby() to 
collect the groups:

In [1]: list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]
In [2]: list2 = [[1,'AA'],[3,'CC'], [4,'DD']]
In [3]: import itertools, operator
In [4]: l=list1+list2
In [5]: l.sort()
In [7]: [ list(g) for k, g in itertools.groupby(l, 
key=operator.itemgetter(0))]
Out[7]:
[[[1, 'A'], [1, 'AA']],
  [[2, 'B']],
  [[3, 'C'], [3, 'CC']],
  [[4, 'D'], [4, 'DD']]]


If you don't care about order, you can use a dict to collect like items:
In [8]: d={}
In [9]: for i in l:
    ...:     d.setdefault(i[0], []).append(i)
In [11]: d.values()
Out[11]:
[[[1, 'A'], [1, 'AA']],
  [[2, 'B']],
  [[3, 'C'], [3, 'CC']],
  [[4, 'D'], [4, 'DD']]]

These are in order but in general they will not be.

If you want to preserve the original order then I think you will have to 
  do it "by hand" as John suggests.

Kent

From David.Heiser at intelliden.com  Fri Jun 29 06:01:42 2007
From: David.Heiser at intelliden.com (David Heiser)
Date: Thu, 28 Jun 2007 22:01:42 -0600
Subject: [Tutor] Iterating through two lists at the same time
	withmanipulation..
In-Reply-To: <5e58f2e40706281823r61eced51vc7acbe9e829a0adc@mail.gmail.com>
References: <382997.67020.qm@web50706.mail.re2.yahoo.com> 
	<5e58f2e40706281823r61eced51vc7acbe9e829a0adc@mail.gmail.com>
Message-ID: <DB30DA681DB9544886EA69FE9082737CCAF3D3@csoexc02.intelliden.net>


A dictionary would work well here. Read each element of the lists into
the dictionary using the integer as the key with a list of strings as
the values.

{1: ['A', 'AA'], 2: ['B'], 3: ['C', 'CC'], 4: ['D', 'DD']}

Then output the contents in the required format.

This may take more lines of code than other solutions, but it's simple
and flexible. If you can guarantee that this is not a class assignment,
I will pass on the code. It starts like this:

list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]
list2 = [[1,'AA'],[3,'CC'], [4,'DD']]
dictionary = {}
for i, j in list1+list2:


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of John Fouhy
Sent: Thursday, June 28, 2007 7:24 PM
To: Iyer
Cc: tutor at python.org
Subject: Re: [Tutor] Iterating through two lists at the same time
withmanipulation..

On 29/06/07, Iyer <maseriyer at yahoo.com> wrote:
> I have 2 lists:
>
> List 1 has lists in it, such as
>
> list1 = [[1,'A'],[2,'B'],[3,'C'],[4,'D']]
>
> There is another list2 such as
>
> list2 = [[1,'AA'],[3,'CC'], [4,'DD']]
>
> For eg,
>
> I wish to iterate over both the lists and produce the output
>
> a = [[1,'A'],[1,'AA']]
> b = [[2,'B']]
> c = [[3,'C'],[3,'CC']]
> d = [[4,'D'],[4,'DD']]

Your best choice is probably just to do it "by hand":

i1 = 0
i2 = 0
output = []
while True:
    # compare list1[i] and list2[i2]
    # produce appropriate output
    # advance i1 or i2

Alternatively, you could shove the data into a sqlite in-memory
database, then use SQL to pull it back out.

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

From deliberatus at verizon.net  Fri Jun 29 05:23:33 2007
From: deliberatus at verizon.net (Kirk Bailey)
Date: Fri, 29 Jun 2007 00:23:33 -0300
Subject: [Tutor] Python & cgi on win98--tinyweb problems, etc
Message-ID: <46847B35.6020405@verizon.net>

RE: TinyWeb running python in windows

PROBLEM: getting python scripts to execute.
SOLUTION: Insure the script ends in the name extension .py.

Windows associates all such files with the pythonw.exe interpreter program, 
and will use it to interpret them. IT IGNORES THE SHEBANG (the first line in 
a script which in the lovely world of un*x points to the interpreter 
program). Some servers have config files to tell the server what to use. 
TinyWeb does not, and relies on windows file associations to direct it to 
the proper interpreter.

Also note that it is possible for windows to conceal name extensions in some 
configurations, and also to create name extensions it does not display, 
resulting in some interesting hair pulling evenings chasing bugs.

Also note that tinyweb checks for the existence of a default page to use if 
none is specified in an incoming request. IF YOU CHANGE THE FILE NAME AFTER 
TINY LOADS IT WILL BARK LIKE A DOG. For instance, index.htm or index.html 
are equally acceptable. You had .htm. then you decided to change it to 
.html- and the server started woofing. It thinks the file index.htm still is 
there someplace and is looking for it! If you change the file name, restart 
the server.

I used tinyweb in supporting the development of windows wiki, and in all 
that crazy alpha stage flakiness, it NOT ONCE blew out. It is BULLETPROOF.

But it is it's own strange beast, and has it's own peculiarities.

-- 
Salute!
	-Kirk Bailey
           Think
          +-----+
          | BOX |
          +-----+
           knihT

Fnord.

From winglion1 at 163.com  Fri Jun 29 06:43:59 2007
From: winglion1 at 163.com (Yang)
Date: Fri, 29 Jun 2007 12:43:59 +0800
Subject: [Tutor] get pixel color form canvas ,
	or draw text on  image (Tkinter lib).
Message-ID: <468491BC.0F2C69.22385@m12-14.163.com>

    What I am trying to do is get the dot matrix
of chinese char, and then make  a font lib for embed system. 
    I had thought of print the char on a tk canvas,
and get dot color one bye one, but I found no mathod to get 
data form canvas.
    As for image, I can put and get dots on it, but I don't 
konw how to put a char on it!
    So, any ideas?  or should I consider using something like
gtk!



From Dean.Gardner at barco.com  Fri Jun 29 09:37:32 2007
From: Dean.Gardner at barco.com (Gardner, Dean)
Date: Fri, 29 Jun 2007 09:37:32 +0200
Subject: [Tutor] Regular Expression help
In-Reply-To: <20070627085507.TRES3.261835.root@webfep12>
References: <ED2EA636E2C9744A96B417491D4793BB812C16@KUUMEX03.barco.com>
	<20070627085507.TRES3.261835.root@webfep12>
Message-ID: <ED2EA636E2C9744A96B417491D4793BB858629@KUUMEX03.barco.com>

Thanks everyone for the replies all worked well, I adopted the string
splitting approach in favour of the regex one as it seemed to miss less
of the edge cases. I would like to thank everyone for their help once
again 




-----Original Message-----
From: Kent Johnson [mailto:kent37 at tds.net] 
Sent: 27 June 2007 14:55
To: tutor at python.org; Gardner, Dean
Subject: Re: [Tutor] Regular Expression help

Gardner, Dean wrote:
> Hi
> 
> I have a text file that I would like to split up so that I can use it 
> in Excel to filter a certain field. However as it is a flat text file 
> I need to do some processing on it so that Excel can correctly import
it.
> 
> File Example:
> tag             desc                    VR      VM
> (0012,0042) Clinical Trial Subject Reading ID LO 1
> (0012,0050) Clinical Trial Time Point ID LO 1
> (0012,0051) Clinical Trial Time Point Description ST 1
> (0012,0060) Clinical Trial Coordinating Center Name LO 1
> (0018,0010) Contrast/Bolus Agent LO 1
> (0018,0012) Contrast/Bolus Agent Sequence SQ 1
> (0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
> (0018,0015) Body Part Examined CS 1
> 
> What I essentially want is to use python to process this file to give 
> me
> 
> 
> (0012,0042); Clinical Trial Subject Reading ID; LO; 1 (0012,0050); 
> Clinical Trial Time Point ID; LO; 1 (0012,0051); Clinical Trial Time 
> Point Description; ST; 1 (0012,0060); Clinical Trial Coordinating 
> Center Name; LO; 1 (0018,0010); Contrast/Bolus Agent; LO; 1 
> (0018,0012); Contrast/Bolus Agent Sequence; SQ ;1 (0018,0014); 
> Contrast/Bolus Administration Route Sequence; SQ; 1 (0018,0015); Body 
> Part Examined; CS; 1
> 
> so that I can import to excel using a delimiter.
> 
> This file is extremely long and all I essentially want to do is to 
> break it into it 'fields'
> 
> Now I suspect that regular expressions are the way to go but I have 
> only basic experience of using these and I have no idea what I should
be doing.

This seems to work:

data = '''\
(0012,0042) Clinical Trial Subject Reading ID LO 1
(0012,0050) Clinical Trial Time Point ID LO 1
(0012,0051) Clinical Trial Time Point Description ST 1
(0012,0060) Clinical Trial Coordinating Center Name LO 1
(0018,0010) Contrast/Bolus Agent LO 1
(0018,0012) Contrast/Bolus Agent Sequence SQ 1
(0018,0014) Contrast/Bolus Administration Route Sequence SQ 1
(0018,0015) Body Part Examined CS 1'''.splitlines()

import re
fieldsRe = re.compile(r'^(\(\d+,\d+\)) (.*?) (\w+) (\d+)$')

for line in data:
    match = fieldsRe.match(line)
    if match:
        print ';'.join(match.group(1, 2, 3, 4))


I don't think you want the space after the ; that you put in your
example; Excel wants a single-character delimiter.

Kent


DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.

From jbertrand at businessloansandleasing.com  Fri Jun 29 15:54:12 2007
From: jbertrand at businessloansandleasing.com (Jason Bertrand)
Date: Fri, 29 Jun 2007 09:54:12 -0400
Subject: [Tutor] (no subject)
Message-ID: <20070629135412.410912009E@ws6-7.us4.outblaze.com>

Please remove me from the mailing list.

Thank you

Jason P Bertrand
JPB Enterprises
www.businessloansandleasing.com
(860) 982-5334




From kent37 at tds.net  Fri Jun 29 16:22:57 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 29 Jun 2007 10:22:57 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
References: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
Message-ID: <468515C1.4070500@tds.net>

Jason Bertrand wrote:
> Please remove me from the mailing list.

You can do this yourself using the link at the bottom of each posting to 
the list.

Kent

> 
> Thank you
> 
> Jason P Bertrand
> JPB Enterprises
> www.businessloansandleasing.com
> (860) 982-5334
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


From andreas at kostyrka.org  Fri Jun 29 16:26:22 2007
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Fri, 29 Jun 2007 16:26:22 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
References: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
Message-ID: <4685168E.8070703@kostyrka.org>

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

Please notice the link http://mail.python.org/mailman/listinfo/tutor in
the footer of every mailing list mail. It's not really very nice to
shoot into a big room with many persons in it "carry me out of the
room". Most people prefer to walk out of the room by themselves.

Andreas

Jason Bertrand wrote:
> Please remove me from the mailing list.
> 
> Thank you
> 
> Jason P Bertrand
> JPB Enterprises
> www.businessloansandleasing.com
> (860) 982-5334
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGhRaNHJdudm4KnO0RAvTiAJ9kLAhlYS/0L42UgDq/jL9PeZiC5ACfbOkk
BGyRc1uWvr+DF0twaxSNj4M=
=irHh
-----END PGP SIGNATURE-----

From michael at espersunited.com  Fri Jun 29 16:27:27 2007
From: michael at espersunited.com (Michael Sullivan)
Date: Fri, 29 Jun 2007 09:27:27 -0500
Subject: [Tutor] (no subject)
In-Reply-To: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
References: <20070629135412.410912009E@ws6-7.us4.outblaze.com>
Message-ID: <1183127247.17700.2.camel@camille.espersunited.com>

On Fri, 2007-06-29 at 09:54 -0400, Jason Bertrand wrote:
> Please remove me from the mailing list.
> 
> Thank you
> 
> Jason P Bertrand
> JPB Enterprises
> www.businessloansandleasing.com
> (860) 982-5334

No one can do that except you.   Look at the list headers to see how.


From alan.gauld at btinternet.com  Fri Jun 29 18:10:06 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 29 Jun 2007 17:10:06 +0100
Subject: [Tutor] Fastest way to iterate through a file
References: <f5pf3g$drd$1@sea.gmane.org> <468050D5.3020403@tds.net>
	<f5r3oc$464$1@sea.gmane.org>
Message-ID: <f63ata$s7i$1@sea.gmane.org>


"Robert Hicks" <sigzero at gmail.com> wrote 
> This is the loop code:
> 
> for line in f2:
>     for id in idList:
>         if id in line:
>             print "%s: %s" % (id, f2.next())
>             found = "%s: %s" % (id, f2.next())
>             f3.write(found)
> 

While I note that you got a solution using regex one general 
point worth noting is that you should, in nested loop cases like 
this, at least use break in the inner loop.

Here you search the line for each id - 129 searches, even 
if you find it first time. Thus adding a break inside the if block 
should save, on average 60 if tests. And given each test 
involves iterating over the line thats significant!

Alan G.
(Whos been away for a week)


From luke.jordan at gmail.com  Fri Jun 29 18:48:47 2007
From: luke.jordan at gmail.com (Luke Jordan)
Date: Fri, 29 Jun 2007 11:48:47 -0500
Subject: [Tutor] database question
Message-ID: <ea0feb800706290948t6d423a8bjdc3d2da7df5919e8@mail.gmail.com>

I've created a database as a shelve, where each value in the shelve file is
a record class instance that has attributes representing fields. Let's say I
enter 300 records in the shelve, then I decide to add a field to future
records, or remove a field from future records. How can I update the
existing records to include the new fields?

Thanks,

Luke


-- 
"If you think that was good, wait 'til you taste the antidote!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070629/a9e67514/attachment.htm 

From norman at khine.net  Fri Jun 29 19:12:46 2007
From: norman at khine.net (Norman Khine)
Date: Fri, 29 Jun 2007 19:12:46 +0200
Subject: [Tutor] Reading image dimensions before it is loaded from a web
 form using python.
Message-ID: <46853D8E.3080301@khine.net>

Hello,
I am writing an application that allows the user to upload an image to
their folder.
Is there a way to get the size of the file before it has been uploaded
onto the server and give an error if the size does not comply to the
maximum size.

So far, my apps loads the image and checks it and then returns the
error. Which is a bit pointless in that I should be able to get the file
info before it is loaded, but I am not sure where to go.

PIL reads the image size before it is loaded, but this is when I run
this on my local machine. There is also a post
http://mail.python.org/pipermail/python-list/2005-May/323018.html by
Will McGugan where he loads 1px and rejects it if its too big. But his
apps is an image scraper, so I suppose it fits his use case where he
checks the size and then pulls the image if it fits.

Anyone with ideas on how to deal with this.

Thanks

Norman


-- 
Norman Khine



From rabidpoobear at gmail.com  Fri Jun 29 20:22:09 2007
From: rabidpoobear at gmail.com (Luke Paireepinart)
Date: Fri, 29 Jun 2007 13:22:09 -0500
Subject: [Tutor] Reading image dimensions before it is loaded from a web
 form using python.
In-Reply-To: <46853D8E.3080301@khine.net>
References: <46853D8E.3080301@khine.net>
Message-ID: <46854DD1.8040706@gmail.com>

Norman Khine wrote:
> Hello,
> I am writing an application that allows the user to upload an image to
> their folder.
> Is there a way to get the size of the file before it has been uploaded
> onto the server and give an error if the size does not comply to the
> maximum size.
>   
[snip]
> Anyone with ideas on how to deal with this.
>   
You'll have to use javascript.
Unless you want to tell the people "download and run x.py on your image 
to determine if it will be rejected!"
if you want an auto check before they upload, you'll have to do 
client-side scripting.
Python's not available for this.  It only does server-side.
This is fine, but if you're processing the image dimensions server-side, 
that means they already sent it to you.
So look for a javascript image processing library.

Alternatively, if by 'size' you meant 'filesize' you could do this much 
more simply (using Javascript)
than having to process the actual image data to find the resolution.
HTH,

-Luke

From alan.gauld at btinternet.com  Fri Jun 29 22:20:58 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 29 Jun 2007 21:20:58 +0100
Subject: [Tutor] database question
References: <ea0feb800706290948t6d423a8bjdc3d2da7df5919e8@mail.gmail.com>
Message-ID: <f63pjl$dsg$1@sea.gmane.org>


"Luke Jordan" <luke.jordan at gmail.com> wrote

> I've created a database as a shelve, where each value in the shelve 
> file is
> a record class instance that has attributes representing fields. 
> Let's say I
> enter 300 records in the shelve, then I decide to add a field to 
> future
> records, or remove a field from future records. How can I update the
> existing records to include the new fields?

You will need to read in each record, update it and write it back 
again.
A shelve is not a relational database so you cannot do mass updates
in situ

Alan G 



From jsmith at medplus.com  Fri Jun 29 22:52:41 2007
From: jsmith at medplus.com (Smith, Jeff)
Date: Fri, 29 Jun 2007 16:52:41 -0400
Subject: [Tutor] DB switch
Message-ID: <288A3B43F7B2224D9C8441C9FC5D6A0201E5060B@EXCHMAIL01.corp.medplus.com>

We are converting a database from Oracle to SQL 2005.  We have a Python
script that currently uses Digital Creation's 'DCOracle' python module.
Any guidance on how to convert this for use with SQL 2005 is
appreciated.
 
Jeff
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070629/b2dfb4da/attachment.htm 

From kent37 at tds.net  Sat Jun 30 03:02:57 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 29 Jun 2007 21:02:57 -0400
Subject: [Tutor] Reading image dimensions before it is loaded from a web
 form using python.
In-Reply-To: <46853D8E.3080301@khine.net>
References: <46853D8E.3080301@khine.net>
Message-ID: <4685ABC1.2070805@tds.net>

Norman Khine wrote:
> Hello,
> I am writing an application that allows the user to upload an image to
> their folder.
> Is there a way to get the size of the file before it has been uploaded
> onto the server and give an error if the size does not comply to the
> maximum size.

I'm not at all clear what your environment is. Is you application 
running on the computer where the image originates, or on the server? If 
your app is running on the source computer then you can just check the 
file size. If you have a web app and you are uploading from the browser 
  then I don't know how to check. The trick in the email you reference 
might work.

Kent
> 
> So far, my apps loads the image and checks it and then returns the
> error. Which is a bit pointless in that I should be able to get the file
> info before it is loaded, but I am not sure where to go.
> 
> PIL reads the image size before it is loaded, but this is when I run
> this on my local machine. There is also a post
> http://mail.python.org/pipermail/python-list/2005-May/323018.html by
> Will McGugan where he loads 1px and rejects it if its too big. But his
> apps is an image scraper, so I suppose it fits his use case where he
> checks the size and then pulls the image if it fits.
> 
> Anyone with ideas on how to deal with this.
> 
> Thanks
> 
> Norman
> 
> 


From kent37 at tds.net  Sat Jun 30 03:12:27 2007
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 29 Jun 2007 21:12:27 -0400
Subject: [Tutor] DB switch
In-Reply-To: <288A3B43F7B2224D9C8441C9FC5D6A0201E5060B@EXCHMAIL01.corp.medplus.com>
References: <288A3B43F7B2224D9C8441C9FC5D6A0201E5060B@EXCHMAIL01.corp.medplus.com>
Message-ID: <4685ADFB.5030501@tds.net>

Smith, Jeff wrote:
> We are converting a database from Oracle to SQL 2005.  We have a Python 
> script that currently uses Digital Creation's 'DCOracle' python module.  
> Any guidance on how to convert this for use with SQL 2005 is appreciated.

Presuming you mean MS-SQL Server, there are quite a few choices. See
http://mail.python.org/pipermail/tutor/2006-September/049323.html
http://mail.python.org/pipermail/tutor/2006-September/049326.html
http://mail.python.org/pipermail/python-win32/2007-April/005727.html

Kent

From hunter92383 at gmail.com  Sat Jun 30 05:55:04 2007
From: hunter92383 at gmail.com (elis aeris)
Date: Fri, 29 Jun 2007 20:55:04 -0700
Subject: [Tutor] 200 dollar questions!
Message-ID: <674d5ce60706292055l4fe2e650s702be599f0d3660e@mail.gmail.com>

I am a 4 day python newbie, and already I am writing practical codes.

I want to learn as fast as possible so I am willing to pay for some
tutorials.

Please reply if you are interested, although 200 is not a lot of money.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070629/555e4306/attachment.htm 

From alan.gauld at btinternet.com  Sat Jun 30 09:40:23 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 30 Jun 2007 08:40:23 +0100
Subject: [Tutor] 200 dollar questions!
References: <674d5ce60706292055l4fe2e650s702be599f0d3660e@mail.gmail.com>
Message-ID: <f651dj$ek2$1@sea.gmane.org>

"elis aeris" <hunter92383 at gmail.com> wrote
>I am a 4 day python newbie, and already I am writing practical codes.
>
> I want to learn as fast as possible so I am willing to pay for some
> tutorials.
>
> Please reply if you are interested, although 200 is not a lot of 
> money.

I'm not sure exactly what you want but this list is intended to be
used by people like you to ask questions and get answers,
but its free. What exactly are you looking for beyond what this
list provides?

200 dollars will buy you a lot of Python books and there are many
free tutorials on the web to suit all levels of experience.

If you tell us what you expect to get for your $200  you might find
its already available for free.

Alan G 



From alan.gauld at btinternet.com  Sat Jun 30 12:57:57 2007
From: alan.gauld at btinternet.com (ALAN GAULD)
Date: Sat, 30 Jun 2007 10:57:57 +0000 (GMT)
Subject: [Tutor] 200 dollar questions!
Message-ID: <100452.41767.qm@web86103.mail.ird.yahoo.com>

Returning it to the List....

----- Original Message ----

http://www.eternite.co.uk/web_page/python_tutor_example.zip


that's the anwser i got from a questions,

because i was determined to go unstuck from this bunch that has entangled me for two days, i was willing to pay for a timely answer.


it's still being improved as i discuss with my consultant.

as with this mailing list i ll appreciate any feedback and am willing to enter a contact for specialized response. 





On 6/30/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
"elis aeris" <hunter92383 at gmail.com> wrote
>I am a 4 day python newbie, and already I am writing practical codes.
>
> I want to learn as fast as possible so I am willing to pay for some

> tutorials.
>
> Please reply if you are interested, although 200 is not a lot of
> money.

I'm not sure exactly what you want but this list is intended to be
used by people like you to ask questions and get answers,

but its free. What exactly are you looking for beyond what this
list provides?

200 dollars will buy you a lot of Python books and there are many
free tutorials on the web to suit all levels of experience.


If you tell us what you expect to get for your $200  you might find
its already available for free.

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/20070630/f8b55cab/attachment.html 

From alan.gauld at btinternet.com  Sat Jun 30 13:43:30 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 30 Jun 2007 12:43:30 +0100
Subject: [Tutor] 200 dollar questions!
References: <100452.41767.qm@web86103.mail.ird.yahoo.com>
Message-ID: <f65flf$fes$1@sea.gmane.org>

> http://www.eternite.co.uk/web_page/python_tutor_example.zip
> 
> that's the anwser i got from a questions,

I had a look but it didn't show up too well. It seems to relate to
a question about mouse events in a web page?

> because i was determined to go unstuck from this bunch 
> that has entangled me for two days, 

It looks like somebody was trying to give you pointers
but a lot depends on your basic skill level.

So before we can do any more can you tell us something 
about yourself and your problem? Specifically:

1) Can you already program in another language, 
if so which? And for how long? What kind of experience?

2) If you are a complete beginner what resources are 
you using to learn Python and programming?

3) Regarding your problem what are you trying to do at the most 
basic level? (eg write a game, build a web site, create a 
Windows GUI etc etc)

4) Within that problem what specifically are you trying 
to do that is not working? (Show us code if its less than 
100 lines or so) What have you tried? What happens?
(If you have any errors please sent the full error text.)

> i was willing to pay for a timely answer.

On the internet you rarely need to pay for speed. There 
are enough people reading that usually someone has the answer.
But the key is in providing the right level of information and 
asking a clear specific question.

Many useful tips are found here:

http://www.catb.org/~esr/faqs/smart-questions.html


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


From jeff at san-dc.com  Sat Jun 30 15:46:11 2007
From: jeff at san-dc.com (Jeff Johnson)
Date: Sat, 30 Jun 2007 06:46:11 -0700
Subject: [Tutor] 200 dollar questions!
In-Reply-To: <f65flf$fes$1@sea.gmane.org>
Message-ID: <001201c7bb1d$05a60300$5f01a8c0@dcsoftware.local>



From lisa.barrott at btinternet.com  Sat Jun 30 18:07:25 2007
From: lisa.barrott at btinternet.com (Lisa Barrott)
Date: Sat, 30 Jun 2007 17:07:25 +0100
Subject: [Tutor] Mouse clicking
Message-ID: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com>

Hello

I was wondering if there was any way to force a mouse click at a set
location using python
even when the another window is focussed.
I'm using Windows XP.

-Lawrence


From alan.gauld at btinternet.com  Sat Jun 30 22:57:21 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 30 Jun 2007 21:57:21 +0100
Subject: [Tutor] Mouse clicking
References: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com>
Message-ID: <f66g3t$427$1@sea.gmane.org>


"Lisa Barrott" <lisa.barrott at btinternet.com> wrote

> I was wondering if there was any way to force a mouse click at a set
> location using python even when the another window is focussed.
> I'm using Windows XP

Yes, you can use the Win32 API.
You need to get the target window handle with

-------------
HWND FindWindow(
    LPCTSTR lpClassName, // pointer to class name
    LPCTSTR lpWindowName  // pointer to window name
   );
 ---------------

or

--------------------
BOOL EnumWindows(
    WNDENUMPROC lpEnumFunc, // pointer to callback function
    LPARAM lParam  // application-defined value
   );
----------------------

Then you can use PostMessage() to generate a mouse event.

BOOL PostMessage(
    HWND hWnd, // handle of destination window
    UINT Msg, // message to post
    WPARAM wParam, // first message parameter
    LPARAM lParam  // second message parameter
   );

You can get the full docs on these functions on MSDN and the winall
package should provide access to them, or the ctypes module will
allow direct access for a bit more work.

There might be other more pythonic modules around that do the
heavy lifting for you, but these are not too hard to use.

HTH,

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



From hunter92383 at gmail.com  Sat Jun 30 23:00:15 2007
From: hunter92383 at gmail.com (elis aeris)
Date: Sat, 30 Jun 2007 14:00:15 -0700
Subject: [Tutor] Mouse clicking
In-Reply-To: <f66g3t$427$1@sea.gmane.org>
References: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com>
	<f66g3t$427$1@sea.gmane.org>
Message-ID: <674d5ce60706301400l5ea344a4tc909942c66390f39@mail.gmail.com>

what module should be imported?

On 6/30/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>
> "Lisa Barrott" <lisa.barrott at btinternet.com> wrote
>
> > I was wondering if there was any way to force a mouse click at a set
> > location using python even when the another window is focussed.
> > I'm using Windows XP
>
> Yes, you can use the Win32 API.
> You need to get the target window handle with
>
> -------------
> HWND FindWindow(
>     LPCTSTR lpClassName, // pointer to class name
>     LPCTSTR lpWindowName  // pointer to window name
>    );
> ---------------
>
> or
>
> --------------------
> BOOL EnumWindows(
>     WNDENUMPROC lpEnumFunc, // pointer to callback function
>     LPARAM lParam  // application-defined value
>    );
> ----------------------
>
> Then you can use PostMessage() to generate a mouse event.
>
> BOOL PostMessage(
>     HWND hWnd, // handle of destination window
>     UINT Msg, // message to post
>     WPARAM wParam, // first message parameter
>     LPARAM lParam  // second message parameter
>    );
>
> You can get the full docs on these functions on MSDN and the winall
> package should provide access to them, or the ctypes module will
> allow direct access for a bit more work.
>
> There might be other more pythonic modules around that do the
> heavy lifting for you, but these are not too hard to use.
>
> 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/20070630/2f306d10/attachment.html 

From hunter92383 at gmail.com  Sat Jun 30 23:44:18 2007
From: hunter92383 at gmail.com (elis aeris)
Date: Sat, 30 Jun 2007 14:44:18 -0700
Subject: [Tutor] Mouse clicking
In-Reply-To: <f66g3t$427$1@sea.gmane.org>
References: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com>
	<f66g3t$427$1@sea.gmane.org>
Message-ID: <674d5ce60706301444u55415cc9wa55a434b1e14bb26@mail.gmail.com>

win32gui <win32gui.html>.FindWindow

int = *FindWindow(className, WindowName *)

Retrieves a handle to the top-level window whose class name and window name
match the specified strings.

Parameters

*className* : int/string
*WindowName* : string


HWND FindWindow(
    LPCTSTR lpClassName, // pointer to class name
    LPCTSTR lpWindowName  // pointer to window name
   );





BOOL EnumWindows(
    WNDENUMPROC lpEnumFunc, // pointer to callback function
    LPARAM lParam  // application-defined value
   );

I am not sure what this is for @_@



BOOL PostMessage(
    HWND hWnd, // handle of destination window
    UINT Msg, // message to post
    WPARAM wParam, // first message parameter
    LPARAM lParam  // second message parameter
   );



with pywin32, shouldn't

win32api.keybd_event
win32api.GetFocus
win32api.mouse_event



be used instead?





On 6/30/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>
> "Lisa Barrott" <lisa.barrott at btinternet.com> wrote
>
> > I was wondering if there was any way to force a mouse click at a set
> > location using python even when the another window is focussed.
> > I'm using Windows XP
>
> Yes, you can use the Win32 API.
> You need to get the target window handle with
>
> -------------
> HWND FindWindow(
>     LPCTSTR lpClassName, // pointer to class name
>     LPCTSTR lpWindowName  // pointer to window name
>    );
> ---------------
>
> or
>
> --------------------
> BOOL EnumWindows(
>     WNDENUMPROC lpEnumFunc, // pointer to callback function
>     LPARAM lParam  // application-defined value
>    );
> ----------------------
>
> Then you can use PostMessage() to generate a mouse event.
>
> BOOL PostMessage(
>     HWND hWnd, // handle of destination window
>     UINT Msg, // message to post
>     WPARAM wParam, // first message parameter
>     LPARAM lParam  // second message parameter
>    );
>
> You can get the full docs on these functions on MSDN and the winall
> package should provide access to them, or the ctypes module will
> allow direct access for a bit more work.
>
> There might be other more pythonic modules around that do the
> heavy lifting for you, but these are not too hard to use.
>
> 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/20070630/63c6aca8/attachment.htm 

From hunter92383 at gmail.com  Sat Jun 30 23:54:07 2007
From: hunter92383 at gmail.com (elis aeris)
Date: Sat, 30 Jun 2007 14:54:07 -0700
Subject: [Tutor] Mouse clicking
In-Reply-To: <674d5ce60706301444u55415cc9wa55a434b1e14bb26@mail.gmail.com>
References: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com>
	<f66g3t$427$1@sea.gmane.org>
	<674d5ce60706301444u55415cc9wa55a434b1e14bb26@mail.gmail.com>
Message-ID: <674d5ce60706301454w7edfda7ate39a31cfb006420@mail.gmail.com>

Bit torrent .torrent file aquisition assistance.

Given a webpage of forum threads that links to download links of .torrent
files, the code should
download every .torrent files it can find within 2 levels of connections.




Bit torrent high performance client

Given that popular bit torrent clients cannot handle past 400 simultanuous
torrents activities,
A code can be written to selectively run only active torrents. If and when
an active torrent
download has been deemed less productive, alternatives should be initiated
until the most
productive option has been found.

This process should continue until when at least when the bandwiths
available has been saturated.
In the ideal scenario, both system computational power as well as the
internet connection should
be used to their maximum.





How do I do this?
It shoulbe be easy to run .py of the bit torrent client, I think it's all
about getting data
from the client so the code can have feedback. I am not sure how to do this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070630/7b459375/attachment.html 

From alan.gauld at btinternet.com  Sat Jun 30 23:57:19 2007
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 30 Jun 2007 22:57:19 +0100
Subject: [Tutor] Mouse clicking
References: <GEEMKFFCJHHJKMLBCGHHIEPBCDAA.lisa.barrott@btinternet.com><f66g3t$427$1@sea.gmane.org>
	<674d5ce60706301444u55415cc9wa55a434b1e14bb26@mail.gmail.com>
Message-ID: <f66jkc$cpt$1@sea.gmane.org>

"elis aeris" <hunter92383 at gmail.com> wrote 

> BOOL EnumWindows(
>    WNDENUMPROC lpEnumFunc, // pointer to callback function
>    LPARAM lParam  // application-defined value
>   );
> 
> I am not sure what this is for @_@

If you don't know the window class/title in advance you 
can get a list of all open windows and apply a function 
of your own devising to each one till you find the one 
you want. The enumeration will stop when your function 
returns FALSE

> with pywin32, shouldn't
> 
> win32api.keybd_event
> win32api.GetFocus
> win32api.mouse_event

Possibly, but I though GetFocus would require your own app 
take focus whereas Lisa wanted to post the mouse events 
to another window which already had focus.

mouse_event is a new one to me and yes, it looks like it might 
be even easier to use.

As ever when programming Windioze its best to ty a few 
experiments...

Alan G