Eryk Sun <[email protected]> added the comment:
Python 3.7+ doesn't need to explicitly enable UTF-8 mode in this case on POSIX
systems. If the locale encoding is the "POSIX" or "C" locale, and "C" locale
coercion is not disabled via LC_ALL or PYTHONCOERCECLOCALE=0, the interpreter
tries to coerce the LC_CTYPE locale to "C.UTF-8", "C.utf8", or "UTF-8". If
these attempts fail, or if coercion is disabled, the interpreter will
automatically enable UTF-8 mode, unless that's also explicitly disabled. For
example:
$ unset LANG
$ unset LC_ALL
$ unset PYTHONCOERCECLOCALE
$ unset PYTHONUTF8
$ python -c 'import locale; print(locale.getpreferredencoding())'
UTF-8
$ PYTHONCOERCECLOCALE=0 python -c 'import locale;
print(locale.getpreferredencoding())'
UTF-8
$ PYTHONUTF8=0 python -c 'import locale;
print(locale.getpreferredencoding())'
UTF-8
$ PYTHONCOERCECLOCALE=0 PYTHONUTF8=0 python -c 'import locale;
print(locale.getpreferredencoding())'
ANSI_X3.4-1968
----------
nosy: +eryksun
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45232>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com