2020-02-23
阅读量:
1194
Python如何批量修改csv文件编码格式为utf8
可以使用os库以及chardet库中的方法,进行遍历循环文件名称,然后修改编码格式
from os import listdir
from chardet import detect
fns = (fn for fn in listdir() if fn.endswith('.csv'))
for fn in fns:
with open(fn, 'rb+') as fp:
content = fp.read()
encoding = detect(content)['encoding']
content = content.decode(encoding).encode('utf8')
fp.seek(0)
fp.write(content)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
3条评论