python3-csv写入中文乱码

正确打开方式应该加上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)
posted @ 2021-11-07 15:12  晨光曦微  阅读(264)  评论(0编辑  收藏  举报