解决Python3读取中文CSV报错
发布时间
阅读量:
阅读量
解决Python3读取csv文件中文报错问题
问题
今日在使用csv库进行操作时,遇到了错误提示,经排查发现原因为csv文件中包含中文字符,在读取过程中因编码格式不匹配导致异常发生。
测试脚本与功能实现
import csv
with open ('test.csv','r') as file:
csv_file = csv.reader(file)
for row in csv_file:
print(row)
报错
Traceback (most recent call last):
File "test.py", line 5, in <module>
for row in csvFile:
File "/usr/lib/python3.5/csv.py", line 109, in __next__
self.fieldnames
File "/usr/lib/python3.5/csv.py", line 96, in fieldnames
self._fieldnames = nex
全部评论 (0)
还没有任何评论哟~
