我正在尝试编写一个程序,该程序查看.CSV文件(input.csv)并仅重写以某个元素(corrected.csv)开头的行,如文本文件(output.txt)中所列。
这是我的程序现在的样子:
import csv
lines = []
with open('output.txt','r') as f:
for line in f.readlines():
lines.append(line[:-1])
with open('corrected.csv','w') as correct:
writer = csv.writer(correct, dialect = 'excel')
with open('input.csv', 'r') as mycsv:
reader = csv.reader(mycsv)
for row in reader:
if row[0] not in lines:
writer.writerow(row)
不幸的是,我一直收到此错误,而且我不知道它是什么。
Traceback (most recent call last):
File "C:\Python32\Sample Program\csvParser.py", line 12, in <module>
for row in reader:
_csv.Error: line contains NULL byte
感谢这里的所有人,甚至使我明白这一点。