![python批量修改txt文件,csv文件 编码格式](https://i-blog.csdnimg.cn/blog_migrate/65dad03b52b8ee8e0da4a985e26db8b0.png)
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编码