[Tutor] Request for code critique
Matt Hehman
druidmatt at yahoo.com
Wed Oct 22 17:11:19 EDT 2003
Sorry if this shows up twice, it got bounced once.
Okay, lots of good feedback to digest. Lloyd Kvam
sent me a complete revised program. The highlights
were as follows:
#retrieve list of known primes
def main_shelve():
try:
d=shelve.open('primesfile')
try:
primes=d['primesfile']
except KeyError:
primes = [2,3,5]
d['primesfile'] = primes
main(primes)
finally:
d['primesfile'] = primes
d.close()
#defines function for finding common factors
def Euclid(a,b):
<snip>
def main(primes):
<snip a neatened up version of the rest of my program>
if __name__ = '__main__':
main_shelve()
The use of "try:" and "finally:" is new to me (docs?)
The last two lines are a total mystery, as is the fact
that the program actually runs (and quite nicely) when
all I can make out is that functions have been
defined. Why does it execute?
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
More information about the Tutor
mailing list