【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'}
posted @ 2017-02-16 20:28  赵康  阅读(369)  评论(0编辑  收藏  举报