Python 利用chardet模块检测字符类型

特别是Python2的情况下,我想知道现在的字符串是什么类型。这时候就可以使用chardet模块了。

#pip install chardet
#python
>>> import chardet
>>> chardet.detect('abc')
{'confidence': 1.0, 'encoding': 'ascii'}

pip install chardet #安装chardet模块

chardet.dect(‘字符串’) #检测字符串类型。

{‘confidence’: 1.0, ‘encoding’: ‘ascii’} #输出结果

You May Also Like

About the Author: 萌新

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注