# coding=utf-8
import chardet
a='潜'
b='水'
c='潜水'
print [a]
print chardet.detect(a)
print [b]
print chardet.detect(b)
print [c]
print chardet.detect(c)
运行的结果:
['\xe6\xbd\x9c']
{'confidence': 0.505, 'encoding': 'utf-8'}
['\xe6\xb0\xb4']
{'confidence': 0.505, 'encoding': 'utf-8'}
['\xe6\xbd\x9c\xe6\xb0\xb4']
{'confidence': 0.99, 'encoding': 'GB2312'}
utf-8编码的两个字放在一起就被当成了gb2312格式。
我找了很久python编码的问题,但是还是找不到解决方案。
希望有朋友能解答。
补充,我是在ubuntu中测试的。
在mac下测试是正常的。
用的是 python2.7.6
locale:
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
MMMHUHU
LEATH
梵蒂冈之花
相关分类