[Tutor] Done at Last!
alan.gauld@bt.com
alan.gauld@bt.com
Tue, 27 Mar 2001 10:33:14 +0100
> def getDayOfWeek():
> #Thanks to Alan Gauld and his book for this
You're welcome :-)
> #This block seeks that the file with today's date fits one in the
> #validDays list.
> for item in theFiles:
> splitItem = string.split(item)
> for z in range(len(splitItem)):
> if z == 8:
This seems inefficient. You don't do anything with z unless its 8 so why not
rewrite the test as:
if len(slitItem) >= 8:
> if splitItem[8] in validDays:
> allTheFiles.append(splitItem[8])
That saves several unnecessary iterations...
>
> #This routine extracts the dir listing with today's date on it
> for x in theFiles:
> ....
> for z in range(len(y)):
> if z == 8:
>
Same again here
> if string.lower(y[8]) == todaysFile:
> correctFileName = y[8]
> rv = checkSize(correctFileName, theFiles)
> return rv
>
> def makeChoice():
> choices = ['atl/', 'austin/', 'boston/', 'chicago/',
> 'dallas/', 'dc/',
> 'galveston/', 'houston/', 'la/', 'miami/', 'nola/', 'ny/',
> 'phl/', 'portland/', 'sd/', 'seattle/', 'sf/',
> 'slc/', 'Vail/']
>
> print """
> Which cities would you like to check?
> 1) Atlanta
> 2) Boston
> 3) Chicago
> etc...
Hmm, why not dynamically build the list from the list of cities?
It would help with maintenance. Create a dictionary of city
and folders:
choices = { 'Atlanta':['atl/'],
'Boston' :['boston/'],
etc...
'other' :['austin/', 'dallas/', 'galveston/', 'houston/']
}
Then generate the menu using choices.keys().sort()
(and maybe an exclusion test to catch 'other' and tag
it at the end)
To add a new city add an entry to choices and the menu and
folder list gets updated automatically...
> File "c:\python20\lib\socket.py", line 221, in readline
> new = self._sock.recv(self._rbufsize)
> error: (10054, 'Connection reset by peer')
Could just be a timeout? I get that regularly using
commandline ftp programs.
Alan G.