直譯器的初始化與終結化

關於如何在初始化之前設定直譯器的細節,請參見 Python 初始化設定

Python 初始化之前

In an application embedding Python, the Py_Initialize() function must be called before using any other Python/C API functions; with the exception of a few functions and the global configuration variables.

The following functions can be safely called before Python is initialized:

備註

Despite their apparent similarity to some of the functions listed above, the following functions should not be called before the interpreter has been initialized: Py_EncodeLocale(), PyEval_InitThreads(), and Py_RunMain().

Global configuration variables

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

This API is kept for backward compatibility: setting PyConfig.bytes_warning should be used instead, see Python Initialization Configuration.

Issue a warning when comparing bytes or bytearray with str or bytes with int. Issue an error if greater or equal to 2.

-b 選項設定。

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_DebugFlag

This API is kept for backward compatibility: setting PyConfig.parser_debug should be used instead, see Python Initialization Configuration.

Turn on parser debugging output (for expert only, depending on compilation options).

-d 選項與 PYTHONDEBUG 環境變數設定。

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_DontWriteBytecodeFlag

This API is kept for backward compatibility: setting PyConfig.write_bytecode should be used instead, see Python Initialization Configuration.

If set to non-zero, Python won't try to write .pyc files on the import of source modules.

-B 選項與 PYTHONDONTWRITEBYTECODE 環境變數設定。

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_FrozenFlag

This API is kept for backward compatibility: setting PyConfig.pathconfig_warnings should be used instead, see Python Initialization Configuration.

Private flag used by _freeze_module and frozenmain programs.

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_HashRandomizationFlag

This API is kept for backward compatibility: setting PyConfig.hash_seed and PyConfig.use_hash_seed should be used instead, see Python Initialization Configuration.

如果環境變數 PYTHONHASHSEED 被設定為一個非空字串則設為 1

If the flag is non-zero, read the PYTHONHASHSEED environment variable to initialize the secret hash seed.

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_IgnoreEnvironmentFlag

This API is kept for backward compatibility: setting PyConfig.use_environment should be used instead, see Python Initialization Configuration.

忽略所有可能被設定的 PYTHON* 環境變數,例如 PYTHONPATHPYTHONHOME

-E-I 選項設定。

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_InspectFlag

This API is kept for backward compatibility: setting PyConfig.inspect should be used instead, see Python Initialization Configuration.

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.

-i 選項與 PYTHONINSPECT 環境變數設定。

自從版本 3.12 後不推薦使用,將會自版本 3.15 中移除。.

int Py_InteractiveFlag

This API is kept for backward compatibility: setting