API 和 ABI 版本控制 ¶
CPython exposes its version number in the following macros. Note that these correspond to the version code is built with, not necessarily the version used at run time .
见 C API 稳定性 for a discussion of API and ABI stability across versions.
-
PY_MAJOR_VERSION
¶
-
The
3in3.4.1a2.
-
PY_MINOR_VERSION
¶
-
The
4in3.4.1a2.
-
PY_MICRO_VERSION
¶
-
The
1in3.4.1a2.
-
PY_RELEASE_LEVEL
¶
-
The
ain3.4.1a2. This can be0xA对于 Alpha,0xB对于 Beta,0xCfor release candidate or0xFfor final.
-
PY_RELEASE_SERIAL
¶
-
The
2in3.4.1a2. Zero for final releases.
-
PY_VERSION_HEX
¶
-
The Python version number encoded in a single integer.
The underlying version information can be found by treating it as a 32 bit number in the following manner:
字节
位数 (大端在前次序)
含义
Value for
3.4.1a21
1-8
PY_MAJOR_VERSION0x032
9-16
PY_MINOR_VERSION0x043
17-24
PY_MICRO_VERSION0x014
25-28
PY_RELEASE_LEVEL0xA29-32
PY_RELEASE_SERIAL0x2因此
3.4.1a2是十六进制0x030401a2and3.10.0是十六进制0x030a00f0.Use this for numeric comparisons, e.g.
#if PY_VERSION_HEX >= ....This version is also available via the symbol
Py_Version.
-
const
unsigned
long
Py_Version
¶
-
属于
稳定 ABI (应用程序二进制接口)
since version 3.11.
The Python runtime version number encoded in a single constant integer, with the same format as the
PY_VERSION_HEXmacro. This contains the Python version used at run time.Added in version 3.11.