Khalid Al-Ghamdi wrote:
Hi everybody,
I'm running python 2.6.1 on vista and I'm trying to use the csv module to
write to a csv file and get the average of some numbers, but I keep getting
the following error:
Traceback (most recent call last):
File "C:\Python31\MyCSVProjectFinal.py", line 83, in <module>
writer.writerow(headings)
IOError: [Errno 9] Bad file descriptor
line 83 refers to the following code, specifically to the one in capital (in
the actual code it's not in capital by the way):
headings = linesInCSV[0] # e.g. ['Measured1', 'Measured2']
csvOutFileName = easygui.filesavebox(title = "Choose output file for
averages", )
if csvOutFileName is not None:
print "Saving using: "+csvOutFileName
csvOut = file(csvOutFileName, 'rb')
If this is an output file, why would you use 'rb' as the file mode?
Don't you mean 'wb' ?
writer = csv.writer(csvOut)
* WRITER.WRITEROW(HEADINGS)*
for index in range(len(measured1)):
writer.writerow([measured1[index], measured2[index]])
writer.writerow([averaged1, averaged2])
else:
print "No filename for saving"
so, my problem is I don't know why it keeps giving me this error. I've
checked on the internet, but I haven't found anything to help resolve this
error.
<snip>
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor