[파이썬] `sys.api_version`: C API 버전 확인

In Python, you can use the sys module to access various system-specific parameters and functions. One of the useful parameters provided by the sys module is api_version, which allows you to check the version of the C API being used by Python.

The C API provides a way to interact with Python from C or other languages that are compatible with C. By checking the C API version, you can ensure compatibility with the specific version of Python you are using.

To check the C API version in Python, you can use the sys.api_version attribute.

import sys

c_api_version = sys.api_version

print(f"The C API version is: {c_api_version}")

When you run this code, it will output the current C API version being used by Python.

The C API version is: 1013

The C API version is represented as a single integer, where the major, minor, and micro versions are combined into a single value. For example, a version like 3.7.1 would be represented as 1007 (3 * 1000 + 7 * 10 + 1).

By checking the C API version, you can ensure compatibility with specific features or functionality that might be available in different versions of the C API. This can be useful when developing extensions or modules that interact with the underlying C-level implementation of Python.

Keep in mind that the sys.api_version attribute is available in Python 3.x. It may not be available in older versions of Python.

In summary, the sys.api_version attribute in Python allows you to check the version of the C API being used by Python. This can be helpful to ensure compatibility and make informed decisions when interacting with the C-level implementation of Python.