使用unicodecsv时出现Unicode编码错误。
- 论坛
- 使用unicodecsv时出现Unicode编码错误。
15 浏览
使用unicodecsv时出现Unicode编码错误。
我使用unicodecsv模块将列表写入csv文件,并使用"utf-8"进行编码,但是当我尝试使用unicodecsv.reader读取时,仍然出现错误:UnicodeDecodeError: 'utf8' codec can't decode byte...
。我可以使用csv.reader读取它。我是否漏掉了什么?
我的代码如下:
with open(datapath + filename, 'wb') as csvfile: writer_to_csv = unicodecsv.writer(csvfile, encoding = "utf-8") writer_to_csv.writerows(data)
当我尝试读取它时:
with open(datapath + filename, 'rb') as csvfile: file_to_list = unicodecsv.reader(csvfile, encoding = "utf-8")
我收到了错误消息。