Home  >  Article  >  Backend Development  >  Simple way to determine string encoding in python (using chardet)

Simple way to determine string encoding in python (using chardet)

高洛峰
高洛峰Original
2017-03-01 13:19:341185browse

The example in this article describes how Python determines the encoding of a string. Share it with everyone for your reference, the details are as follows:

Install the chardet module

The chardet folder is placed in /usr/lib/python2.4/site- Under the packages directory

[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.

>>> import chardet
>>> chardet.detect("我")
{'confidence': 0.505, 'encoding': 'utf-8'}
>>>

For more articles related to Python’s simple method of determining string encoding (using chardet), please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn