1. Chardet Module
Python is dealing with string problems and often encounters string encoding problems. Chardet is a very good code recognition module.
The formats that can be identified are:
Installing Chardet
Under Mac python has been integrated into the system, OS X Yosemite 10.10 version of the system Python version is Python2.7. The installation directory for Python is in /usr/bin/python
, the Library directory is in /Library/Python/2.7/site-packages/
.
Unzip the downloaded chardet-2.3.0.tar.gz and copy it to the Python library directory.
# sudo cp -rf chardet /Library/Python/2.7/site-packages/
You need to use sudo plus permissions under your Mac.
Test code
import chardet import urllib #可根据需要,选择不同的数据 TestData = urllib.urlopen(‘http://www.baidu.com/‘).read() print
The result indicates that there is a 99% probability that this code is UTF-8 encoded.
MAC OS Python installation Chardet module