From 5723263a3a39a05b6a2f567e0e7771792e6e2f5b Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Fri, 15 Feb 2019 00:35:25 +0100 Subject: [PATCH] bpo-30410: Documentation of sys.stdin/out/err update to reflect change in 3.6 (GH-10264) Documentation of sys.stdin/out/err update to reflect change in 3.6 on Windows to use UTF-8. Wording by Eryk Sun and Paul Moore. https://bugs.python.org/issue30410 --- Doc/library/sys.rst | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 9002f94545..018f0c9f10 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1368,13 +1368,30 @@ always available. returned by the :func:`open` function. Their parameters are chosen as follows: - * The character encoding is platform-dependent. Under Windows, if the stream - is interactive (that is, if its :meth:`isatty` method returns ``True``), the - console codepage is used, otherwise the ANSI code page. Under other - platforms, the locale encoding is used (see :meth:`locale.getpreferredencoding`). - - Under all platforms though, you can override this value by setting the - :envvar:`PYTHONIOENCODING` environment variable before starting Python. + * The character encoding is platform-dependent. Non-Windows + platforms use the locale encoding (see + :meth:`locale.getpreferredencoding()`). + + On Windows, UTF-8 is used for the console device. Non-character + devices such as disk files and pipes use the system locale + encoding (i.e. the ANSI codepage). Non-console character + devices such as NUL (i.e. where isatty() returns True) use the + value of the console input and output codepages at startup, + respectively for stdin and stdout/stderr. This defaults to the + system locale encoding if the process is not initially attached + to a console. + + The special behaviour of the console can be overridden + by setting the environment variable PYTHONLEGACYWINDOWSSTDIO + before starting Python. In that case, the console codepages are + used as for any other character device. + + Under all platforms, you can override the character encoding by + setting the :envvar:`PYTHONIOENCODING` environment variable before + starting Python or by using the new :option:`-X` ``utf8`` command + line option and :envvar:`PYTHONUTF8` environment variable. However, + for the Windows console, this only applies when + :envvar:`PYTHONLEGACYWINDOWSSTDIO` is also set. * When interactive, ``stdout`` and ``stderr`` streams are line-buffered. Otherwise, they are block-buffered like regular text files. You can -- 2.40.0