脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python判断字符串编码的简单实现方法(使用chardet)

python判断字符串编码的简单实现方法(使用chardet)

2020-08-31 11:16小呆 Python

这篇文章主要介绍了python判断字符串编码的简单实现方法,涉及chardet模块的安装与简单使用方法,需要的朋友可以参考下

本文实例讲述了python判断字符串编码的方法。分享给大家供大家参考,具体如下:

安装chardet模块

chardet文件夹放在/usr/lib/python2.4/site-packages目录下

?
1
2
3
4
[root@sha-sso-data01 chardet]# python
Python 2.4.3 (#1, Sep 21 2011, 19:55:41)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
?
1
2
3
4
>>> import chardet
>>> chardet.detect("我")
{'confidence': 0.505, 'encoding': 'utf-8'}
>>>

希望本文所述对大家Python程序设计有所帮助。

延伸 · 阅读

精彩推荐