Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Also see <a href="http://www.python.org/dev/peps/pep-0263/" rel="noreferrer">PEP 263</a> if you are using a non-ascii characterset</p> <blockquote> <h2>Abstract</h2> <p>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.</p> <h2>Problem</h2> <p>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.</p> <h2>Proposed Solution</h2> <p>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.</p> <p>To make Python aware of this encoding declaration a number of concept changes are necessary with respect to the handling of Python source code data.</p> <h2>Defining the Encoding</h2> <p>Python will default to ASCII as standard encoding if no other encoding hints are given.</p> <p>To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:</p> <pre><code> # coding=&lt;encoding name&gt; </code></pre> <p>or (using formats recognized by popular editors)</p> <pre><code> #!/usr/bin/python # -*- coding: &lt;encoding name&gt; -*- </code></pre> <p>or</p> <pre><code> #!/usr/bin/python # vim: set fileencoding=&lt;encoding name&gt; : </code></pre> <p>...</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload