python设置文件编码 Defining Python Source Code Encodings

PEP 263提议在Python源文件中引入语法来声明文件的编码,以便解析器根据给定的编码解释文件。这使程序员可以使用例如UTF-8直接在Unicode编辑器中编写Unicode字面量。
摘要由CSDN通过智能技术生成

PEP 263 – Defining Python Source Code Encodings
PEP: 263
Title: Defining Python Source Code Encodings
Author: mal at lemburg.com (Marc-André Lemburg), martin at v.loewis.de (Martin von Löwis)
Status: Final
Type: Standards Track
Created: 06-Jun-2001
Python-Version: 2.3
Post-History:
Contents

Abstract
Problem
Proposed Solution
Defining the Encoding
Examples
Concepts
Implementation
Phases
Scope
References
History
Copyright
Abstract
This PEP proposes to introduce a syntax to declare the encoding of a Python source file. The encoding information is then used by the Python parser to interpret the file using the given encoding. Most notably this enhances the interpretation of Unicode literals in the source code and makes it possible to write Unicode literals using e.g. UTF-8 directly in an Unicode aware editor.

Problem
In Python 2.1, Unicode literals can only be written using the Latin-1 based encoding “unicode-escape”. This makes the programming environment rather unfriendly to Python users who live and work in non-Latin-1 locales such as many of the Asian countries. Programmers can write their 8-bit strings using the favorite encoding, but are bound to the “unicode-escape” encoding for Unicode literals.

Proposed Solution
I propose to make the Python source code encoding both visible and changeable on a per-source file basis by using a special comment at the top of the file to declare the encoding.

To make Python aware of this encoding declaration a number of concept changes are necessary with respect t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值