首页 > 编程语言 > 详细

python批量修改txt文件,csv文件 编码格式

时间:2018-06-15 10:33:48      阅读:618      评论:0      收藏:0      [点我收藏+]
技术分享图片



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)

批量改为utf-8编码

python批量修改txt文件,csv文件 编码格式

原文:http://blog.51cto.com/13000661/2129573

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!