【Python】python2 str 编码检测

python2 str 编码检测

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'}
原文地址:https://www.cnblogs.com/forzhaokang/p/6407478.html