diff options
author | Mariatta Wijaya <mariatta.wijaya@gmail.com> | 2017-02-02 05:03:48 (GMT) |
---|---|---|
committer | Mariatta Wijaya <mariatta.wijaya@gmail.com> | 2017-02-02 05:03:48 (GMT) |
commit | bb19bf275b465b8a17da51b6365f9d2800921a05 (patch) | |
tree | 8ff810e00d564f69826e322aa8f6bd05a7bd3c10 /Doc/tutorial | |
parent | 495e8808d7df806a258a37c90827e58c28ff72f0 (diff) | |
parent | 23dcccb75bf5484399feeb5d03bf21a4e4c1c4c2 (diff) | |
download | cpython-bb19bf275b465b8a17da51b6365f9d2800921a05.zip cpython-bb19bf275b465b8a17da51b6365f9d2800921a05.tar.gz cpython-bb19bf275b465b8a17da51b6365f9d2800921a05.tar.bz2 |
Issue #29381: merge with 3.6
Diffstat (limited to 'Doc/tutorial')
-rw-r--r-- | Doc/tutorial/interpreter.rst | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index c97f5d8..bf7ce77 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -138,25 +138,24 @@ should follow. To display all these characters properly, your editor must recognize that the file is UTF-8, and it must use a font that supports all the characters in the file. -It is also possible to specify a different encoding for source files. In order -to do this, put one more special comment line right after the ``#!`` line to -define the source file encoding:: +To declare an encoding other than the default one, a special comment line +should be added as the *first* line of the file. The syntax is as follows:: # -*- coding: encoding -*- -With that declaration, everything in the source file will be treated as having -the encoding *encoding* instead of UTF-8. The list of possible encodings can be -found in the Python Library Reference, in the section on :mod:`codecs`. +where *encoding* is one of the valid :mod:`codecs` supported by Python. -For example, if your editor of choice does not support UTF-8 encoded files and -insists on using some other encoding, say Windows-1252, you can write:: +For example, to declare that Windows-1252 encoding is to be used, the first +line of your source code file should be:: # -*- coding: cp-1252 -*- -and still use all characters in the Windows-1252 character set in the source -files. The special encoding comment must be in the *first or second* line -within the file. +One exception to the *first line* rule is when the source code starts with a +:ref:`UNIX "shebang" line <tut-scripts>`. In this case, the encoding +declaration should be added as the second line of the file. For example:: + #!/usr/bin/env python3 + # -*- coding: cp-1252 -*- .. rubric:: Footnotes |