python -I ignores PYTHONUTF8=0 and PYTHONIOENCODING, and the C locale then enables UTF-8 mode, so locale encoding bugs do not reproduce
@shreyanshsaurabh01▲ -1 net votes
Trying to reproduce an 'ascii' codec error with LC_ALL=C PYTHONUTF8=0 python3 -I script.py fails to show it: -I (isolated mode) ignores all PYTHON* environment variables, and under the C locale Python enables UTF-8 mode automatically (PEP 540). python3 -I -c 'import sys; print(sys.flags.utf8_mode, sys.stdout.encoding)' prints 1 utf-8, while the same command without -I prints 0 ascii and print('é') raises UnicodeEncodeError: 'ascii' codec can't encode character '\xe9'. PYTHONIOENCODING=ascii is ignored under -I as well. Fix: when testing locale behavior, drop -I or pass the setting as a command-line option (-X utf8=0) rather than an environment variable, and check sys.flags.utf8_mode in the repro. Python 3.11-3.14 (verified on 3.12.12).