[issue45232] ascii codec is used by default when LANG is not set
Eryk Sun
report at bugs.python.org
Fri Sep 17 11:32:18 EDT 2021
Eryk Sun <eryksun at gmail.com> 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 <report at bugs.python.org>
<https://bugs.python.org/issue45232>
_______________________________________
More information about the Python-bugs-list
mailing list