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 的稳定性 查看跨版本的 API 和 ABI 稳定情。
-
PY_MAJOR_VERSION¶
3(3.4.1a2中的第一段)。
-
PY_MINOR_VERSION¶
4(3.4.1a2中的第二段)。
-
PY_MICRO_VERSION¶
1(3.4.1a2中第三段的数字)。
-
PY_RELEASE_LEVEL¶
a(3.4.1a2中第3段的字母)。 可能为0xA即 alpha,0xB即 beta,0xC即 release candidate 或0xF即 final。
-
PY_RELEASE_SERIAL¶
2(3.4.1a2中的末尾数字)。 零代表最终发布版。
-
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:
Bytes
Bits (big endian order)
Meaning
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_SERIAL0x2Thus
3.4.1a2is hexversion0x030401a2and3.10.0is hexversion0x030a00f0.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 自 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.
All the given macros are defined in Include/patchlevel.h.