python3-csv写入中文乱码
2018-03-21 11:25 菜鸟Alex 阅读(17355) 评论(0) 编辑 收藏 举报- 代码如下
import csv
data = [['American','美国人'],
['Chinese','中国人']]
with open('results.csv','w',newline='',) as f:
w = csv.writer(f)
w.writerows(data)
-
结果如下
-
正确打开方式应该加上
encoding='utf-8-sig'
-
代码
import csv
data = [['American','美国人'],
['Chinese','中国人']]
with open('results.csv','w',newline='',encoding='utf-8-sig') as f:
w = csv.writer(f)
w.writerows(data)
- 结果