文件处理-智能检测编码的工具

假如你不知道你要处理的文件是什么编码课怎么办呢?

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')

posted on 2019-05-17 10:10  kingforn  阅读(797)  评论(0编辑  收藏  举报