Re: [Tutor] os.system() with NO_WAIT

2006-08-08 Thread János Juhász

Thanks Wesley,

 I lokked for
subprocess.Popen.

os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd",
"myarg") was to complicated for me based on the manual.


Yours sincerely, 
__
János Juhász 
VELUX Magyarország Fertődi Építőkomponens Kft. 
IT Department
Malom Köz 1, H-9431 Fertőd 
Telephone direct:    
 +36 99 537 939
Telephone office:      +36 99 537 920
Office fax:                +36
99 537 921
Telephone mobile:    +36 30 682 6331
@                    
        [EMAIL PROTECTED]
www                    
   www.VELUX.com






"wesley chun" <[EMAIL PROTECTED]>


2006.08.07 22:28



To
"János Juhász"
<[EMAIL PROTECTED]>

cc
tutor@python.org

Subject
Re: [Tutor] os.system()
with NO_WAIT



>         os.system('vedicom.exe')
>
> Have you got any idea how I can strart this windows GUI program with
not
> waiting its return.

instead of os.system(), you want to use the subprocess
module if you
are using Python 2.4+:
http://docs.python.org/lib/module-subprocess.html

calling subprocess.Popen(["/bin/mycmd",
"myarg"]) is "no wait."

to save the PID:

pid = subprocess.Popen(["/bin/mycmd", "myarg"]).pid

if you are using Python 2.3.x and older, you have
to use spawn*():

pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd",
"mycmd", "myarg")

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python

2006-08-08 Thread David Wilson
can you explain functions in python to me and give me some examples

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


Re: [Tutor] Community documentation framework?

2006-08-08 Thread Kent Johnson
> 
> From: "Bob Nienhuis" <[EMAIL PROTECTED]>
> 

> Features I would like to see:
> A Wikipedia-like capacity for community update-ability/modifiability
> of documentation submissions.

Fredrik Lundh has started wikis for the Python docs. I'm on vacation and don't 
have the links but you should be able to find them in the blog archives at 
effbot.org.

Kent

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

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


[Tutor] Regex search in HTML data

2006-08-08 Thread Basil Shubin

Hi friends,

Please, see the attachment and examine a code I have provide. The 
problem is, I want fetch data from Comments until the first 
 occurrence , but with my code data fetchind until the last  
in htmlData variable, but that is not what I want. So question is, what 
is my mistake?


Thanks in advance.

import re
import string

htmlData = """
Instructions

Preparation


  Lie supine on bench. Dismount barbell from rack over the upper chest
  using a wide oblique overhand grip.


Execution


  Lower weight to upper chest. Press bar until arms are extended. Repeat.


Comments


  None


Classification



 Utility:
http://www.exrx.net/WeightTraining/Glossary.html#anchor1270300";>Basic

 Mechanics:
http://www.exrx.net/WeightTraining/Glossary.html#anchor1271511";>Compound

 Force:
http://www.exrx.net/WeightTraining/Glossary.html#anchor400787";>Push




Muscles

http://www.exrx.net/WeightTraining/Glossary.html#anchor1274950";>Target


  http://www.exrx.net/Muscles/PectoralisSternal.html";>Pectoralis Major, Sternal


http://www.exrx.net/WeightTraining/Glossary.html#anchor1275394";>Synergists


  http://www.exrx.net/Muscles/PectoralisClavicular.html";>Pectoralis Major,
  Clavicular
  http://www.exrx.net/Muscles/DeltoidAnterior.html";>Deltoid, Anterior
  http://www.exrx.net/Muscles/TricepsBrachii.html";>Triceps Brachii


http://www.exrx.net/WeightTraining/Glossary.html#anchor1276508";>Dynamic Stabilizers


  http://www.exrx.net/Muscles/BicepsBrachii.html";>Biceps Brachii, Short Head





"""

if __name__ == '__main__':
# Extract comments
p = re.search('Comments(.+)', htmlData,
  re.I | re.S | re.M)
commentsHTML = string.strip(p.group(1))
print commentsHTML
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unusual behavior in readline

2006-08-08 Thread Tony Cappellini
I don't understand why readline is producing such unusual behavior.I don't remember it working like this previously. The docs say it is supposed to read a line at a time.this functiondef ProcessFile(self, Inputfile, Outputfile=None):
    
    try:    fh=open(Inputfile,"r")    except IOError:    print"\nError ocurred opening %s for input\n" % Inputfile    else:    FixedEntry = []

    Entry = ""    for Entry in fh.readline():    print"Entry = %s" % Entry            
fh.close()is producing this resultEntry = AEntry = lEntry = iEntry = aEntry = sEntry = ,Entry = PEntry = hEntry = oEntry = nEntry = eWith this input file

Alias,PhoneJANE SMITH,12131234567Readline is supposed to read an entire line on each call, yet it is only reading one character.

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


Re: [Tutor] Community documentation framework?

2006-08-08 Thread Mike Hansen
 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Bob Nienhuis
Sent: Sunday, August 06, 2006 3:56 PM
To: tutor@python.org
Subject: [Tutor] Community documentation framework?



Have you had the experience of finding a nifty bit of code on
the
web, trying it out, and then discovering that technique
only worked in version X.YY, or requires module Z that
is no longer available?

Well perhaps we can address this situation.

I would like to see an online system that facilitates
the collaborative production, cataloging and updating of 
community documentation. See an article, "Rethinking Community 
Documentation" by Andy Oram 

.

Features I would like to see:
A Wikipedia-like capacity for community
update-ability/modifiability
of documentation submissions.

Database for cataloging available packages, modules, FAQs,
How-Tos
tutorials, cookbook code fragments etc. Should have capacity
for 
developers to add and others to add to their contributions. 

Oram suggests a rating system for submissions so users can
assess
the quality of submissions, and point to parts that need
modification
or clarification..

Might use TurboGears, Django AJAX or other web framework?

I think main Python documentation is great, but there is a lot
of stuff out there that isn't documented so well, or needs
updating. This project is intended to adress that need.

What would you like to see?


You might take a look at

http://pyfaq.infogami.com/

Mike

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


Re: [Tutor] help regarding forms... (fwd)

2006-08-08 Thread Alan Gauld
>> I've been on the internet for over 20 years now and every mail
>> tool/newreader I've ever used has (at least) two reply options:
>> ...
>> I don't understand why this seems to come as a surprise?
>> What am I missing?
>
> Alan, I think you are judging based on technical lists, no?

There are other kinds?!! :-)

> mailing list, the more likely it is to be set up with a munged 
> `reply to' header.

What exactly does this mean? I still don't quite see how it works.
Does this mean a user hits Reply to reply to the whole list and
then Reply All - does what The same? What a waste!

Alan G. 

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


Re: [Tutor] Rock, Paper, Scissors

2006-08-08 Thread Alan Gauld
> This looks like a fun project to work on.  From
> reading the description, I feel this would be pretty
> straight forward game to program.  However, I have no
> idea how the computer would decide if it wanted a
> rock, paper, or a pair of scissors.  Any hints?

Assign a value to rock, paper and scissors.
then use the random module to generate one of the 3 values at random.

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


Re: [Tutor] Unusual behavior in readline

2006-08-08 Thread Luke Paireepinart
Tony Cappellini wrote:
>
> I don't understand why readline is producing such unusual behavior.
> I don't remember it working like this previously. The docs say it is 
> supposed to read a line at a time.
It does :)
>
> this function
>
> def ProcessFile(self, Inputfile, Outputfile=None):
>
> try:
> fh=open(Inputfile,"r")
> except IOError:
> print"\nError ocurred opening %s for input\n" % Inputfile
> else:
> FixedEntry = []
> Entry = ""
> for Entry in fh.readline():
what you're saying in this line is:
1. call the readline method of fh.
2. iterate over each item in the returned value, and assign each item 
the name 'Entry' while in the loop.

What does the readline method of fh return?
it returns a single line.
So you're looping over a single line,
which means that each time through the loop Entry points to a single 
character.

What you want to do is call readline through each iteration of the loop.
or, to make it much easier, you could just use readlines :)
'for Entry in fh.readlines():'

> [snip stuff]
> Readline is supposed to read an entire line on each call, yet it is 
> only reading one character.
>
No, it is, in fact, reading an entire line on _each_ call, the only 
problem being that you only call it once.
HTH,
-Luke

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

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


Re: [Tutor] python

2006-08-08 Thread Hugo González Monteverde
Hi David,

Have you read the grat explanation in Alan's tutorial? What problem 
specifically are you having with functions?

http://www.freenetpages.co.uk/hp/alan.gauld/

Get back to us with any questions...

David Wilson wrote:
> can you explain functions in python to me and give me some examples
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] try & except

2006-08-08 Thread Magnus Wirström
Hi

I'm playing around with try: and except: i have a code like this
try:
bibl=os.listdir("c:\\klientdata\\")
except:
wx.MessageBox("Kunde inte läsa käll 
biblioteket.","Säkerhetskopiering",wx.OK|wx.ICON_ERROR)

(yeah ... it's swedish :) )

So far i get how to use it but i would like to be able to execute the 
try block again after it jumped to the exception. How can i make it 
retry to read the directory?
Thanks
Magnus
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python

2006-08-08 Thread Danny Yoo


On Mon, 7 Aug 2006, David Wilson wrote:

> can you explain functions in python to me and give me some examples

Hi David,

Have you looked into a Python tutorial yet?

 http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Most of the tutorials there talk about functions.  If you could give us an 
example of what you're having trouble with, that would help us to give 
more specific examples that target that problem.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help regarding forms... (fwd)

2006-08-08 Thread Brian van den Broek
Alan Gauld said unto the world upon 08/08/06 12:59 PM:
>>> I've been on the internet for over 20 years now and every mail
>>> tool/newreader I've ever used has (at least) two reply options:
>>> ...
>>> I don't understand why this seems to come as a surprise?
>>> What am I missing?
>>
>> Alan, I think you are judging based on technical lists, no?
> 
> There are other kinds?!! :-)

:-)

>> mailing list, the more likely it is to be set up with a munged `reply 
>> to' header.
> 
> What exactly does this mean? I still don't quite see how it works.
> Does this mean a user hits Reply to reply to the whole list and
> then Reply All - does what The same? What a waste!
> 

I've never actually tried `Reply to all' on a munged list. But, since 
on such lists `Reply' is, in effect, an alias for `Reply to all' I 
assume that in addition to breaking expectations, munging is also, as 
you suspect, brought to you by the Department of Redundancy Department.

FWIW, the munging preference is pretty runs pretty deep, I think. I my 
case it took public shame caused by a `private' message that wasn't to 
see the light. :-[

Burned by the memory, I refuse to munge the class mailing lists I 
administer. But one day the complaints will wear me down . . . .

Best,

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


Re: [Tutor] python

2006-08-08 Thread Alan Gauld

> can you explain functions in python to me and give me some examples

There are many tutorials that do that, including mine.

Take a look at the Modules and functions topic...

Or if you are experienced in other programming 
languages try the official tutorial at python.org.

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regex search in HTML data

2006-08-08 Thread Alan Gauld
> Please, see the attachment and examine a code I have provide. The
> problem is, I want fetch data from Comments until the first
>  occurrence ,

Do you mean the unmatched /td that occurs after the dd section?

> import re
> import string
>
> htmlData = """
> Instructions
> Comments
>
> 
>  None
> 
> 

To this one here?
Its probably a bad idea to use a regular tag as a marker,
some browsers get confused by unmatched tags.
Using a comment is usually better.


> Classification
>
>  width="100%">
> 
>  Utility:

But regex don;t like working with nested tags, you have
a table cell inside another and writing regexs to match
that can get very tricky. So if you want to search into
this part of the string you should probably look at
using Beautiful Soup or similar HTML parser.

> if __name__ == '__main__':
># Extract comments
>p = re.search('Comments(.+)', htmlData,
>  re.I | re.S | re.M)

Looks like you are getting caught out by the "greedy" nature
of regex - they grab as much as they can.

You can control that by adding a ? immediately after the +
but given the nature of your html I'd try using BeautifulSoup instead.

You'll find a short section on greedy expressions in my regex
topic on my tutorial site.

HTH,

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

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


Re: [Tutor] Unusual behavior in readline

2006-08-08 Thread Alan Gauld

>I don't understand why readline is producing such unusual behavior.
> I don't remember it working like this previously. The docs say it is
> supposed to read a line at a time.

It does.

> def ProcessFile(self, Inputfile, Outputfile=None):
>
>try:
>fh=open(Inputfile,"r")
>except IOError:
>print"\nError ocurred opening %s for input\n" % Inputfile
>else:
>FixedEntry = []
>Entry = ""

You don't need to initialise Entry, the for loop does that for you.


>for Entry in fh.readline():

readline returns a string and the for loop iterates over it.
You need readl;ines to return all of the strings in the file.
Or nowadays just use

   for Entry in fh:

>print"Entry = %s" % Entry

BTW Why not just put all this stuff in the body of the try?
Thats what try/except is for, to stop cluttering up the code with
error handling sections and move that to the end out of the way
You should very rarely need an else clause when using try/except.

> Readline is supposed to read an entire line on each call,
> yet it is only reading one character.

No, it is reading a line, you are then iterating over that line
one character at a time.

HTH,

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

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


Re: [Tutor] try & except

2006-08-08 Thread John Fouhy
On 09/08/06, Magnus Wirström <[EMAIL PROTECTED]> wrote:
> Hi
>
> I'm playing around with try: and except: i have a code like this
>try:
>bibl=os.listdir("c:\\klientdata\\")
>except:
>wx.MessageBox("Kunde inte läsa käll
> biblioteket.","Säkerhetskopiering",wx.OK|wx.ICON_ERROR)
>
> (yeah ... it's swedish :) )
>
> So far i get how to use it but i would like to be able to execute the
> try block again after it jumped to the exception. How can i make it
> retry to read the directory?

What logic are you looking for?  Is it ---

  "Try to read directory.  If it doesn't work, try again.  If it still
doesn't work, abort."

or ---

   "Try to read directory.  If it doesn't work, keep trying until it does."

In the former case, you could just put another try block in your except block:

   try:
   bibl=os.listdir("c:\\klientdata\\")
   except:
   wx.MessageBox("Kunde inte läsa käll
biblioteket.","Säkerhetskopiering",wx.OK|wx.ICON_ERROR)
   try:
   bibl=os.listdir("c:\\klientdata\\")
   except:
   wx.MessageBox("Kunde inte läsa käll
biblioteket.","Säkerhetskopiering",wx.OK|wx.ICON_ERROR)

In the latter case, you probably want some kind of loop:

success = False
while not success:
   try:
   bibl=os.listdir("c:\\klientdata\\")
   success = True
   except:
   wx.MessageBox("Kunde inte läsa käll
biblioteket.","Säkerhetskopiering",wx.OK|wx.ICON_ERROR)

Of course, it would be nice to give the users another way out of the loop :-)

HTH!

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


Re: [Tutor] try & except

2006-08-08 Thread Alan Gauld
> I'm playing around with try: and except: i have a code like this
>try:
>bibl=os.listdir("c:\\klientdata\\")
>except:
>wx.MessageBox("Kunde inte läsa käll ...
>
> So far i get how to use it but i would like to be able to execute 
> the try block again after it jumped to the exception.

Yes, thats a common desire, unfortunately it isn't possible,
at least not directly.

One way round this is to put the try inside a function then
call the function inside an outer try, like this:

def mylistdir(d):
 try:   bibl = os.listdir(d)
 except: raise

try:
mylistdir("C:\\")
except:
print 'oops!'
mylistdir(default)

But even here you only get wo bites at the pie.

If you need more you need to write a loop:

success = False
while not success
  try:
mylistdir(d)
success = True
  except: print 'oops!'


But I agree a retry option would be nice. But I've never found a
language yet that supports it. (There are some good reasons why
this is the case BTW, to do with the uncertain state of the code
block that you exit.)

HTH,

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

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


Re: [Tutor] Unusual behavior in readline

2006-08-08 Thread wesley chun
summarizing what folks have already said plus a few more tweaks such
as moving the close() to finally (2.5+), following the style guideline
of variable non-titlecasing, removing unused variables, etc.:

#!/usr/bin/env python2.5

def processFile(inputfile):
try:
fh = open(inputfile, "r")
for entry in fh:
print "Entry = %s" % entry.strip()
except IOError, e:
print "\nError occurred opening %s for input\n" % inputfile
finally:
fh.close()

if __name__ == '__main__':
processFile('phone')

we get this output:

$ tony.py
Entry = Alias,Phone
Entry = JANE SMITH,12131234567

the try-except-finally statement was unified (again) coming up in 2.5.
 i say again because it was actually there before but removed in
version 0.9.6.  :-)

how about some 2.6 fun and using the with statement to get rid of
finally and closing the file, as a 2.5 preview?

#!/usr/bin/env python2.5

from __future__ import with_statement

def processFile(inputfile):
try:
with open(inputfile, "r") as fh:
for entry in fh:
print "Entry = %s" % entry.strip()
except IOError, e:
print "\nError occurred opening %s for input\n" % inputfile

the context management of the with statement will automagically close
the file regardless of exceptions so you do not need to worry about
it.  in 2.6, both 'with' and 'as' become keywords -- you will be
warned in 2.5.

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
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] searching for a string in a dictionary

2006-08-08 Thread anil maran
all_types:.there is such a listhow do i search for a particular string say teststring in this listi triedif teststring in all_types:if teststring in all_types.type: it doesnt workplease help me out hereshould i use lambda 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Exercise in writing a python function.

2006-08-08 Thread Kermit Rose
 Hello all.
 
 
I feel more familar with Python now, and when I recently went back to
reading
the tutorial,  I could actually read it without being overwhelmed by too
much new detail.
 
 
I've been staring at the specs for a python function for a while.
 
I wrote one version of it and it worked.
 
Then I changed the specs, and now need to reconstruct my original work.
 
I'm sure I can do it fairly easily.
 
I'm not asking anyone to write the function for me.
 
It did occur to me that it could be a classroom exercise for other students.
 
The current specifications for the function are:
 
 
def incr(mult,z,zlim,mpylist):
# mult is a vector of exponents for the multipliers in mpylist.
# z is a positive odd  integer.
# zlim is the upper bound  critical value for the sum of  ( mpylist[k][0] *
mpylist[k][1] ) 
# where kth multiplier is mpylist [k][0]
# and kth  multiplier index is mpylist [k][1]
 
# function incr returns the next value of vector mult.
# mult may be thought as a number written in a variable base.
# mult[0] is the least significant and matches multiplier mpylist[0][0]
# adding one to mult would mean adding 1 to mult[0]
# unless doing so would make sum of multiplier * index exceed zlim.
# in that case mult[0] is set to zero, and 1 is added to mult[1]
# unless doing so would make sum of multilier * index exceed zlim
# in that case, mult[0] and mult[1] is set to zero,
# and 1 is added to mult[2]
# unless . . .
 

# mult[0] is set to -1 to indicate that the largest possible value of mult
has been exceeded.
# mpylist[0][0] = 2 and all other multipliers  in mpylist are odd.
# mult[0], the index on multiplier 2, must not equal 1.  It may equal zero,
or any integer > 1, 
# provided the zlim constraint is met.
 
 
 
 
 
 

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


Re: [Tutor] Exercise in writing a python function.

2006-08-08 Thread John Fouhy
On 09/08/06, Kermit Rose <[EMAIL PROTECTED]> wrote:
> def incr(mult,z,zlim,mpylist):
> # mult is a vector of exponents for the multipliers in mpylist.
> # z is a positive odd  integer.
> # zlim is the upper bound  critical value for the sum of  ( mpylist[k][0] *
> mpylist[k][1] )
> # where kth multiplier is mpylist [k][0]
> # and kth  multiplier index is mpylist [k][1]
>
> # function incr returns the next value of vector mult.
> # mult may be thought as a number written in a variable base.
> # mult[0] is the least significant and matches multiplier mpylist[0][0]
> # adding one to mult would mean adding 1 to mult[0]
> # unless doing so would make sum of multiplier * index exceed zlim.
> # in that case mult[0] is set to zero, and 1 is added to mult[1]
> # unless doing so would make sum of multilier * index exceed zlim
> # in that case, mult[0] and mult[1] is set to zero,
> # and 1 is added to mult[2]
> # unless . . .
>
>
> # mult[0] is set to -1 to indicate that the largest possible value of mult
> has been exceeded.
> # mpylist[0][0] = 2 and all other multipliers  in mpylist are odd.
> # mult[0], the index on multiplier 2, must not equal 1.  It may equal zero,
> or any integer > 1,
> # provided the zlim constraint is met.

Hi Kermit,

Is there anything particular that you're stuck on?

I think I understand your function, although I'm not sure what role z
plays.  Are you looking for help on how to translate the description
you've given into logic suitable for programming?

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


Re: [Tutor] Exercise in writing a python function.

2006-08-08 Thread John Fouhy
On 09/08/06, Kermit Rose <[EMAIL PROTECTED]> wrote:
> Hello John.
>
> Thanks for replying.
>
> In my previous version,  I used z as the critical value,.
>
> Since I created zlim,  a function of z, to be passed in as a parameter, I no
> longer need z
>
> in the parameter list.
>
> In another part of the program, z is multiplied by
>
> product of mpylist[ k][0] ** mult[k] for k  in range(len(mpylist)).
>
>
> I'm feeling something akin to writer's block when I sit down and attempt to
> start the code.
>
> I know that if I can just get started then the rest of the code will begin
> to flow in my thoughts.
>
> I did not really expect anyone to help me, but if you wish to  indicate the
> first few lines of
>
> either python or psuedo code
> for this routine, it probably will help me get started.
>
>
> Kermit   <  [EMAIL PROTECTED]  >

Hi Kermit,

Your basic data structure is a list (actually, several related lists),
which you work your way through.  So I would start off with a for
loop:

for k in range(len(mult)):

Then, in the body of the loop, your basic logic is:

Add 1 to mult[k].
If mult[k] is not too big, exit.
Otherwise, ...

Hmm, actually, I'm not sure I do understand.  Does mpylist ever
change?  How is mult related to zlim?

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