From 5ab7cf4454ff54781e8ebd94eb2e2b54c58f4261 Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Wed, 1 Feb 2017 20:21:22 -0800 Subject: Issue #29381: Clarify ordering of UNIX shebang line as source encoding line --- Doc/tutorial/interpreter.rst | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index faf57a344c..bf7ce77641 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -10,13 +10,13 @@ Using the Python Interpreter Invoking the Interpreter ======================== -The Python interpreter is usually installed as :file:`/usr/local/bin/python3.6` +The Python interpreter is usually installed as :file:`/usr/local/bin/python3.7` on those machines where it is available; putting :file:`/usr/local/bin` in your Unix shell's search path makes it possible to start it by typing the command: .. code-block:: text - python3.6 + python3.7 to the shell. [#]_ Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local @@ -98,8 +98,8 @@ before printing the first prompt: .. code-block:: shell-session - $ python3.6 - Python 3.6 (default, Sep 16 2015, 09:25:04) + $ python3.7 + Python 3.7 (default, Sep 16 2015, 09:25:04) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> @@ -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 `. 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 -- cgit v1.2.1 From ba6c9c88bf4e08a0099c7c89eb73c6d9f8ee2d6b Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Wed, 1 Feb 2017 20:38:55 -0800 Subject: Backed out changeset 3d712292f2fa --- Doc/tutorial/interpreter.rst | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index bf7ce77641..faf57a344c 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -10,13 +10,13 @@ Using the Python Interpreter Invoking the Interpreter ======================== -The Python interpreter is usually installed as :file:`/usr/local/bin/python3.7` +The Python interpreter is usually installed as :file:`/usr/local/bin/python3.6` on those machines where it is available; putting :file:`/usr/local/bin` in your Unix shell's search path makes it possible to start it by typing the command: .. code-block:: text - python3.7 + python3.6 to the shell. [#]_ Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local @@ -98,8 +98,8 @@ before printing the first prompt: .. code-block:: shell-session - $ python3.7 - Python 3.7 (default, Sep 16 2015, 09:25:04) + $ python3.6 + Python 3.6 (default, Sep 16 2015, 09:25:04) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> @@ -138,24 +138,25 @@ 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. -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:: +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:: # -*- coding: encoding -*- -where *encoding* is one of the valid :mod:`codecs` supported by Python. +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`. -For example, to declare that Windows-1252 encoding is to be used, the first -line of your source code file should be:: +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:: # -*- coding: cp-1252 -*- -One exception to the *first line* rule is when the source code starts with a -:ref:`UNIX "shebang" line `. In this case, the encoding -declaration should be added as the second line of the file. For example:: +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. - #!/usr/bin/env python3 - # -*- coding: cp-1252 -*- .. rubric:: Footnotes -- cgit v1.2.1 From 11b22721760007e51ce4539855feea2c4ccf66a0 Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Wed, 1 Feb 2017 20:55:47 -0800 Subject: Issue #29381: Clarify ordering of UNIX shebang line as source encoding line --- Doc/tutorial/interpreter.rst | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index faf57a344c..3bd100d46a 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 `. 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 -- cgit v1.2.1