python2 str 编码检测
代码语言:javascript复制import chardet
s = 'sdffdfd'
print type(s)
print chardet.detect(s)
s2 = '反反复复'
print type(s2)
print chardet.detect(s2)
s3 = u'反反复复'.encode('utf-8')
print type(s3)
print chardet.detect(s3)
# <type 'str'>
# {'confidence': 1.0, 'encoding': 'ascii'}
# <type 'str'>
# {'confidence': 0.938125, 'encoding': 'utf-8'}
# <type 'str'>
# {'confidence': 0.938125, 'encoding': 'utf-8'}