全局配置变量
Python has variables for the global configuration to control different features and options. By default, these flags are controlled by command line options.
When a flag is set by an option, the value of the flag is the number of times that the option was set. For example, -b
sets Py_BytesWarningFlag
to 1 and -bb
sets Py_BytesWarningFlag
to 2.
int Py_BytesWarningFlag
Issue a warning when comparing bytes
or bytearray
with str
or bytes
with int
. Issue an error if greater or equal to 2
.
由 -b
选项设置。
int Py_DebugFlag
Turn on parser debugging output (for expert only, depending on compilation options).
Set by the -d
option and the PYTHONDEBUG
environment variable.
int Py_DontWriteBytecodeFlag
If set to non-zero, Python won’t try to write .pyc
files on the import of source modules.
Set by the -B
option and the PYTHONDONTWRITEBYTECODE
environment variable.
int Py_FrozenFlag
Suppress error messages when calculating the module search path in Py_GetPath()
.
Private flag used by _freeze_importlib
and frozenmain
programs.
int Py_HashRandomizationFlag
Set to 1
if the PYTHONHASHSEED
environment variable is set to a non-empty string.
If the flag is non-zero, read the PYTHONHASHSEED
environment variable to initialize the secret hash seed.
int Py_IgnoreEnvironmentFlag
忽略所有 PYTHON*
环境变量,例如可能已设置的 PYTHONPATH
和 PYTHONHOME
。
int Py_InspectFlag
When a script is passed as first argument or the -c
option is used, enter interactive mode after executing the script or the command, even when sys.stdin
does not appear to be a terminal.
Set by the -i
option and the PYTHONINSPECT
environment variable.
int Py_InteractiveFlag
由 -i
选项设置。
int Py_IsolatedFlag
Run Python in isolated mode. In isolated mode sys.path
contains neither the script’s directory nor the user’s site-packages directory.
由 -I
选项设置。
3.4 新版功能.
int Py_LegacyWindowsFSEncodingFlag
If the flag is non-zero, use the mbcs
encoding instead of the UTF-8 encoding for the filesystem encoding.
Set to 1
if the PYTHONLEGACYWINDOWSFSENCODING
environment variable is set to a non-empty string.
有关更多详细信息,请参阅 PEP 529。
可用性: Windows。
int Py_LegacyWindowsStdioFlag
If the flag is non-zero, use io.FileIO
instead of WindowsConsoleIO
for sys
standard streams.
Set to 1
if the PYTHONLEGACYWINDOWSSTDIO
environment variable is set to a non-empty string.
有关更多详细信息,请参阅 PEP 528。
可用性: Windows。
int Py_NoSiteFlag
禁用 site
的导入及其所附带的基于站点对 sys.path
的操作。 如果 site
会在稍后被显式地导入也会禁用这些操作 (如果你希望触发它们则应调用 site.main()
)。
由 -S
选项设置。
int Py_NoUserSiteDirectory
不要将 用户 site-packages 目录
添加到 sys.path
。
Set by the -s
and -I
options, and the PYTHONNOUSERSITE
environment variable.
int Py_OptimizeFlag
Set by the -O
option and the PYTHONOPTIMIZE
environment variable.
int Py_QuietFlag
即使在交互模式下也不显示版权和版本信息。
由 -q
选项设置。
3.2 新版功能.
int Py_UnbufferedStdioFlag
Force the stdout and stderr streams to be unbuffered.
Set by the -u
option and the PYTHONUNBUFFERED
environment variable.
int Py_VerboseFlag
Print a message each time a module is initialized, showing the place (filename or built-in module) from which it is loaded. If greater or equal to 2
, print a message for each file that is checked for when searching for a module. Also provides information on module cleanup at exit.
Set by the -v
option and the PYTHONVERBOSE
environment variable.