- 直接代码
# 批量处理编码问题
from os import listdir
from chardet import detect
fns = (fn for fn in listdir('./dataset/photo/') if fn.endswith('.csv'))
for fn in fns:
print(fn)
with open( './dataset/photo/' + fn, 'rb+') as fp:
content = fp.read()
encoding = detect(content)['encoding']
content = content.decode(encoding).encode('utf8')
fp.seek(0)
fp.write(content)
好用的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)