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!