Skip to content

Commit

Permalink
bpo-39287: Doc: Add UTF-8 mode section in using/windows. (GH-17935)
Browse files Browse the repository at this point in the history
Co-Authored-By: Kyle Stanley <aeros167@gmail.com>
  • Loading branch information
methane and aeros committed Jan 28, 2020
1 parent 13c1c35 commit 148610d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,6 @@ conflict.

Also available as the :option:`-X` ``utf8`` option.

.. availability:: \*nix.

.. versionadded:: 3.7
See :pep:`540` for more details.

Expand Down
44 changes: 44 additions & 0 deletions Doc/using/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,50 @@ existed)::

C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.9

.. _win-utf8-mode:

UTF-8 mode
==========

.. versionadded:: 3.7

Windows still uses legacy encodings for the system encoding (the ANSI Code
Page). Python uses it for the default encoding of text files (e.g.
:func:`locale.getpreferredencoding`).

This may cause issues because UTF-8 is widely used on the internet
and most Unix systems, including WSL (Windows Subsystem for Linux).

You can use UTF-8 mode to change the default text encoding to UTF-8.
You can enable UTF-8 mode via the ``-X utf8`` command line option, or
the ``PYTHONUTF8=1`` environment variable. See :envvar:`PYTHONUTF8` for
enabling UTF-8 mode, and :ref:`setting-envvars` for how to modify
environment variables.

When UTF-8 mode is enabled:

* :func:`locale.getpreferredencoding` returns ``'UTF-8'`` instead of
the system encoding. This function is used for the default text
encoding in many places, including :func:`open`, :class:`Popen`,
:meth:`Path.read_text`, etc.
* :data:`sys.stdin`, :data:`sys.stdout`, and :data:`sys.stderr`
all use UTF-8 as their text encoding.
* You can still use the system encoding via the "mbcs" codec.

Note that adding ``PYTHONUTF8=1`` to the default environment variables
will affect all Python 3.7+ applications on your system.
If you have any Python 3.7+ applications which rely on the legacy
system encoding, it is recommended to set the environment variable
temporarily or use the ``-X utf8`` command line option.

.. note::
Even when UTF-8 mode is disabled, Python uses UTF-8 by default
on Windows for:

* Console I/O including standard I/O (see :pep:`528` for details).
* The filesystem encoding (see :pep:`529` for details).


.. _launcher:

Python Launcher for Windows
Expand Down

0 comments on commit 148610d

Please sign in to comment.