我尝试运行此代码:
txt_file = r"Fun.txt"
in_txt = csv.reader(open(txt_file, "rb"), delimiter = '\t')
csv_file = r"NewProcessedDoc.csv"
with open(csv_file, 'w', newline ='') as csvfile:
swriter = csv.writer(csvfile, delimiter = ' ')
swriter.writerow(in_txt)
print('done! Check NewProcessedDoc.csv file')
但有错误:
swriter.writerow(in_txt)
Error: iterator should return strings, not bytes (did you open the file in text mode?)
有人可以帮忙吗? 谢谢!
答案 0 :(得分:0)
...open(txt_file, "rb")
.writerows()
方法而不是.writerow()
:swriter.writerows(in_txt)