[Tutor] Stumped Again
Terry Green
tmantjg at yahoo.com
Sun Oct 31 01:12:11 CEST 2010
Am running this Script and cannot figure out how to close my files,
Keep getting msg: Attribute Error: '_csv.writer' object has no attribute
'close'
Why?
import csv
testOutput =
csv.writer(open('c:/users/terry/downloads/tup1012k/tup1012.csv', 'w'),
delimiter=',',
quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
csvreader =
csv.reader(open("c:/users/terry/downloads/tup1012k/tup1012x.drf","r"),delimi
ter=',')
for row in csvreader:
test=('test4')
track=row[0]
rdate=row[1]
race=row[2]
postPos=row[3]
entry=row[4]
distance=row[5]
surface=row[6]
Reserved=row[7]
raceType=row[8]
ageSex=row[9]
todaysRaceClassification=row[10]
purse=row[11]
claimingPrice=row[12]
jockey=row[32]
jockeySts = int(row[34])
jockeyWins = int(row[35])
horseName=row[44]
daysSinceLR=row[223]
try:
jockeyPct=round((jockeyWins/jockeySts)*100)
except ZeroDivisionError:
print
(track,race,postPos,horseName,jockey,jockeyWins,jockeySts,0)
else:
print
(track,race,postPos,horseName,jockey,jockeyWins,jockeySts,jockeyPct)
testOutput.writerow((track,race,postPos,horseName,jockey,jockeyWins,jockeySt
s,jockeyPct,'\n'))
testOutput.close()
csvreader.close()
Please Help!!!!!
Terry Green
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101030/2370fe76/attachment.html>
More information about the Tutor
mailing list