[Python IO Learning article] complements files that open Chinese paths

Source: Internet
Author: User
Tags sublime editor

http://blog.csdn.net/mottolinux/article/details/52560062
1 basic knowledge of Python coding in Python "plaintext" is Unicode type and str, "ciphertext" is another encoding format such as GBK UTF-8latin-1 Wait code: "Clear Text"-"ciphertext". Encode ([target encoding format]) object must be decoded for Unicode type: "Ciphertext"-"Clear Text". Decode ([source code format]) object is of type STR There are three main classes of encoding for Chinese characters in Chinese characters "Li" as an example of a. Unicode class machine code \x67\x4e Unicode (python representation) \u674ehtml Entity&#x674EUTF- -(BE)0x674eUTF- +(BE)0x0000674eB. UTF-Class 8 machine code \xe6\x9d\x8e UTF-8(python represents) \xe6\x9d\x8eurl Escape Code%e6%9d%8EOctal Escape Sequence \346\235\216c. GB Class machine code \xc0\xee gb2312 GBK gb18030 \xc0\xee
2set the Chinese encoding format on the. py file (1the contents of the Py file appear on the string in Chinese (2includes a string preceded by U (converted to Unicode format), and the first is to read the string literal and convert it to Unicode based on the file encoding format set.3) If you add a #coding=utf-8, the Chinese press utf-8 turn into Unicode (4) If you do not add #coding=utf-8, the system's default encoding format (5) system's default encoding, get code: sys.getdefaultencoding ()3How to set the encoding format for. py Files: (1) #coding =<encoding>        (2) <encoding>depending on the editor different sublime editor defaults to UTF-8Win7 Bring your own operating system: ASCIII/gbk--To read Chinese, to GBK can be saved as: UTF-84the Win7 file name is Chinese or the folder is in Chinese (1) are GBK encoded (2When reading and writing files, you must open (.... Encode ('GBK'),'R')5the content on the Win7 file contains Chinese (1) is not the same as 4 (2the contents of the file are based on the encoded format (Notepad may be saved as) (3) is recommended to encode into utf-8, sublime Open does not require conversion6Storage of crawler results (1Now the web is basically utf-8 Encoding (HTML5 default encoding) (2the HTML element content type after BeautifulSoup processing is navigablestring (3) Direct print can be inferred from the 3rd navigablestring the underlying type is Unicode (4) can be converted to Unicode type after the. Replace () method7does not advocate (1) Do not use sys.setdefaultencoding (' utf-8') solve the coding problem8Other (1The String intermediate processing process is all translated into Unicode processing only at the entry and exit of the data. Decode () and. Encode () processing

[Python IO Learning article] complements files that open Chinese paths

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.