我一直遇到错误,似乎我应该已经从在线阅读的内容中调试了它。我试图将行从一个CSV追加到另一个。
这是错误:
for row in reader:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
下面是我的代码。我已经尝试了一些细微的变化,例如“ rt”而不是“ r”。
import csv
#tried this first
with open('input.csv') as myfile:
reader = csv.reader(myfile)
writer = csv.writer(open('output.csv', 'a'))
for row in reader:
if "EMAIL" or "EMAIL ADDRESS" or "Email" in row:
writer.writerow(row)
第二次尝试
reader = csv.reader(open('input.csv', 'r', encoding="utf-8"))
writer = csv.writer(open('output.csv', 'a'))
for row in reader:
if "EMAIL" or "EMAIL ADDRESS" or "Email" in row:
writer.writerow(row)
最后一次尝试
reader = csv.reader(open('input.csv', 'r', encoding="ascii"))
writer = csv.writer(open('output.csv', 'a'))
for row in reader:
if "EMAIL" or "EMAIL ADDRESS" or "Email" in row:
writer.writerow(row)
我们将不胜感激!