[英]Python: Can not write to CSV file
I have this snippet of Python code: 我有以下这段Python代码:
import csv
def analyse(csvFileToRead, csvFileToWrite):
# open file to read
openedCsvFileToRead = open(csvFileToRead)
reader = csv.reader(openedCsvFileToRead)
# open file to write
openedCsvFileToWrite = open(csvFileToWrite)
writer = csv.writer(openedCsvFileToWrite)
for row in reader:
date = row[8]
if date[0] == "5":
writer.writerow(row)
# close file
openedCsvFileToRead.close()
openedCsvFileToWrite.close()
if __name__ == "__main__":
analyse("mydata.csv", "mynewdata.csv")
when run using Python 3.4 I get the following error message: 使用Python 3.4运行时,出现以下错误消息:
Traceback (most recent call last):
File "main.py", line 40, in <module>
analyse("mydata.csv", "mynewdata.csv")
File "main.py", line 25, in analyse
writer.writerow(row)
io.UnsupportedOperation: not writable
What Am I doing wrong? 我究竟做错了什么? I'm on Windows 7 64bit.
我在Windows 7 64位上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.