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 你理解代碼后自己整合吧