python怎么把ASNIGB2312转换成UTF
导读:python怎么把ASNIGB2312转换成UTF?#!/usr/bin/env python3from chardet import detectfn = 'a.txt'with open(fn, 'rb' as f: s = f...
python怎么把ASNIGB2312转换成UTF?
#!/usr/bin/env python3from chardet import detectfn = 'a.txt'with open(fn, 'rb') as f: s = f.read()coding = detect(s)['encoding']print('coding: { } '.format(coding))print('content: { } '.format(s.decode(coding).rstrip()))newf = 'b.txt'with open(newf, 'wb') as f: f.write(s.decode(coding).encode('utf8'))print('done!convert coding to utf-8 and wirte content in `{ } `'.format(newf))
如果报ImportError那就
pip install chardet
def 你理解代码后自己整合吧
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: python怎么把ASNIGB2312转换成UTF
本文地址: https://pptw.com/jishu/62283.html
