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

高洛峰
Release: 2017-03-01 13:19:34
Original
1234 people have browsed it

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.
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!