Python File Encoding Description coding

Source: Internet
Author: User

Authoritative Source: http://www.python.org/dev/peps/pep-0263/
The header declaration of the Python source file (declared on the first or second line of the file)

# Coding=utf-8

# Coding:utf-8

#-*-Coding:utf-8-*-

To conform to the regular specification "coding[:=]\s* ([-\w.] +) "NOTE: or = no spaces before and after

Defining the Encoding
    Python would default to ASCII as standard encoding if no other    encoding hints is given.    To define a source code encoding, a magic comment must is placed into the    source files either as first or second    l Ine in the file, such as:          # coding=<encoding name>    or (using formats recognized by popular editors)          #!/u Sr/bin/python          #-*-Coding: <encoding name>-*-    or          #!/usr/bin/python          # vim:set fileencoding= <encoding name>: More    precisely, the first or second line must match the regular    expression "coding[:=]\s * ([-\w.] +)". The first group of this    expression was then interpreted as encoding name. If the encoding    is unknown to Python, an error is raised during compilation. There must not being any Python statement on the line that    contains the    encoding declaration.

The full name of the PEP is the Python enhancement proposals, "Python enhancement Advice", which is a specification of each of the various enhancements and extensions that define Python.

Each pep has a number and is unique, and this number will not change once it is fixed, for example, Pep 3000 is used to define the relevant specifications for Python 3.0, and Pep 333 is the Python Web application Interface WSGI (Web Serve R Gateway Interface 1.0) Specifications

The relative specification of THE PEP itself is the definition in Pep 1, and all pep lists are here

Read More:http://www.arthurtoday.com/2009/11/python-pep.html#ixzz46oh9obzv

Learning: http://blog.csdn.net/orangleliu/article/details/8755461

Python File Encoding Description coding

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.