首页后端开发Pythonpython怎么把ASNIGB2312转换成UTF

python怎么把ASNIGB2312转换成UTF

时间2023-06-05 08:28:01发布访客分类Python浏览492
导读: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
python如何以两个字符一行方式输出 语言跟python哪个好

游客 回复需填写必要信息