why huge speed difference btwn 1.52 and 2.1?
Robin Senior
rsenior at hotmail.com
Mon Jun 4 14:22:00 EDT 2001
On 3 Jun 2001 08:07:56 -0700, aahz at panix.com (Aahz Maruch) wrote:
>In article <9f8fgs$ooo$1 at knot.queensu.ca>,
>robin senior <rsenior at hotmail.com> wrote:
>>
>>I have a pretty simple script for processing a flat file db, running on
>>Python 2.1; I tried running it under 1.52 for kicks, and to my surprise it
>>ran almost 10 times as fast! Could someone let me know why 2.1 would be so
>>much slower?
>
>This script is so poorly formatted that I can't read it.
Sorry, I was at work and using IE to post; this should be better:
import re
import string
states = {
'ALABAMA':'AL',
'ALASKA':'AK',
'ARIZONA':'AZ',
'WISCONSIN':'WI',
'WYOMING':'WY'}
for year in range(1994, 1998):
f = open('states/USA'+str(year)+'.TXT')
counter = 1
while(1):
print str(year), counter
counter = counter + 1
#convert city name to allcaps (db outputs in allcaps)
line = string.upper(f.readline().strip())
#check for EOF
if not line:
break
for state in states.keys():
#(STATENAME) OR (STATE ABBREVIATION)
if ( (re.search(' '+state+'( |,)', line, re.IGNORECASE)) or (re.search(' '+states[state]+'( |,)', line, re.IGNORECASE)) ):
filename = string.replace(state, ' ', '_')
g = open('states/'+filename+'/'+str(year)+'.TXT', "a")
g.write(line)
g.write("\n")
g.close()
f.close()
More information about the Python-list
mailing list