如下代码就是通过chardet包获得文件的编码格式的,其中chardet需要单独安装
import chardet
byte=min(32,os.path.getsize(filename))
raw=open(filename,'rb').read(byte)
result=chardet.detect(raw)
encoding=result['encoding']
如下代码就是通过chardet包获得文件的编码格式的,其中chardet需要单独安装
import chardet
byte=min(32,os.path.getsize(filename))
raw=open(filename,'rb').read(byte)
result=chardet.detect(raw)
encoding=result['encoding']