假如你不知道你要处理的文件是什么编码课怎么办呢?
chardet 模块具有自动检测编码功能(需要安装第三方工具包) #pip3 instatll chardet
import chardet
f = open('log', mode='rb')
data = f.read()
f.close()
result = chardet.detect(data)
print(result)
data.decode('gb2312')
假如你不知道你要处理的文件是什么编码课怎么办呢?
chardet 模块具有自动检测编码功能(需要安装第三方工具包) #pip3 instatll chardet
import chardet
f = open('log', mode='rb')
data = f.read()
f.close()
result = chardet.detect(data)
print(result)
data.decode('gb2312')