MAC OS Python installation Chardet module

Source: Internet
Author: User

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:

    • ASCII, UTF-8, UTF-16 (2 variants), UTF-32 (4 variants)
    • Big5, GB2312, EUC-TW, hz-gb-2312, ISO-2022-CN (traditional and Simplified Chinese)
    • EUC-JP, Shift_JIS, CP932, ISO-2022-JP (Japanese)
    • EUC-KR, Iso-2022-kr (Korean)
    • Koi8-r, Maccyrillic, IBM855, IBM866, Iso-8859-5, windows-1251 (Cyrillic)
    • Iso-8859-2, windows-1250 (Hungarian)
    • Iso-8859-5, windows-1251 (Bulgarian)
    • windows-1252 (中文版)
    • Iso-8859-7, windows-1253 (Greek)
    • Iso-8859-8, windows-1255 (Visual and Logical Hebrew)
    • TIS-620 (Thai)

      Chardet is a third-party library of Python that needs to be downloaded and installed.
      Official website: Https://pypi.python.org/pypi/chardet

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.