第2模块第1章05文件处理——智能检测编码的工具
2019-03-09 本文已影响0人
飞鸟在笼
如果不知道一个文件的是以什么编码的,
我们知道中文utf-8连个字节,3个字符,gbk2个字符,可以由此规律出发,进行推测。
问:假如你不知道你要处理的文件式什么编码可怎么办?
import chardet
f = open('log',mode='rb')
data = f.read()
f.close()
result = chardet.detect(open('log',mode='rb').read())
print(result)
chardet属于第三方库
输出结果