python 字符编码判断 chardet评测

之前一直想找到一个模块,针对字符判断是什么字符集编码的库

网上有chardet的blog,发现自己的环境有这个库,于是就做了测试

>>> import chardet
>>> a = "也有".decode('gbk')
>>> a
u'\u6d94\u71b8\u6e41'
>>> a = "也有".decode('gbk').encode('gbk')
>>> a
'\xe4\xb9\x9f\xe6\x9c\x89'
>>> chardet.detect(a)
{'confidence': 0.7525, 'language': '', 'encoding': 'utf-8'}
>>> print(a)
也有>>> a = "也有".decode('gbk').encode('gbk')
>>> a = u"也有".encode('gbk')
>>> a
'\xd2\xb2\xd3\xd0'
>>> chardet.detect(a)
{'confidence': 0.7679697235616183, 'language': 'Russian', 'encoding': 'KOI8-R'}

总结发现不是很准,放弃使用

猜你喜欢

转载自www.cnblogs.com/renfanzi/p/10768306.html