初始化、定稿和线程

Python 初始化配置 for details on how to configure the interpreter prior to initialization.

在 Python 初始化之前

在嵌入 Python 的应用程序中, Py_Initialize() 函数必须被调用,在使用任何其它 Python/C API 函数之前;除了一些函数和 全局配置变量 .

可以安全地调用下列函数,在初始化 Python 之前:

注意

Despite their apparent similarity to some of the functions listed above, the following functions 不应被调用 before the interpreter has been initialized: Py_EncodeLocale() , Py_GetPath() , Py_GetPrefix() , Py_GetExecPrefix() , Py_GetProgramFullPath() , Py_GetPythonHome() , Py_GetProgramName() , PyEval_InitThreads() ,和 Py_RunMain() .

全局配置变量

Python has variables for the global configuration to control different features and options. By default, these flags are controlled by 命令行选项 .

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 初始化配置 .

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

设置通过 -b 选项。

Deprecated since version 3.12, will be removed in version 3.14.