Detailed description of ascii and Unicode usage in python3

Source: Internet
Author: User
This article mainly describes the ascii and Unicode information in python3. if you need it, you can refer to the following article for details about the ascii and Unicode information in python3, for more information, see

# Auther: Aaron Fan ''' ASCII: Chinese characters are not supported. one English character occupies 1 byte Unicode (Wanguo code, supports text display in all countries): Chinese characters are supported, but each English and Chinese occupies 2 byte UTF-8 (is a variable-length character encoding for Unicode, also known as Wanguo code .) : English still occupies 1 byte in ASCII format, and all Chinese characters are unified into three bytes. Unicode supports encoding conversion in various countries, for example, if garbled characters occur in Chinese gbk-format software opened in Japan, gbk must be converted to Unicode encoding for normal display. GBK: Full name: Chinese character Internal Code extension Specification (GBK is the first letter of "national standard" and "extension" Chinese pinyin, English name: Chinese Internal Code Specification) ''''' 1. convert it to Unicode2 and then gbk. In general, encode it first and then decode it. ''' # Example: '''gbk _ file is a gbk-encoded file requirement: convert gbk_file into a new utf8-encoded file. the new file name is: gbk_to_utf8_file ''' # python3 command line method # Convert gbk files to utf8 files, source file gbk_file, target file utf8file: open ('utf8file', 'W + ', encoding = 'utf-8 '). write (open ('gbk _ file', 'R', encoding = 'gbk '). read () # Convert the utf8 file into a gbk file, the source file utf8file, and the target file gbk_file: open ('gbk _ file', 'W + ', encoding = 'gbk '). write (open ('utf8file', 'R', encoding = 'utf-8 '). read () # implementation method on python2: # Convert the gbk file to the utf8 file, the source file newfile, and the target file utf8file: pen ('utf8file', 'W + '). write (open ('newfile', 'r '). read (). decode ('gbk '). encode ('utf-8 '))

The preceding sections describe how to use ascii and Unicode in python3. For more information, see other related articles in the first PHP community!

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.