[파이썬] `sys.implementation`: Python 구현 정보 반환
To access the information provided by sys.implementation
, you first need to import the sys
module.
import sys
Once imported, you can access different attributes of sys.implementation
to retrieve specific information. Some of the most commonly used attributes include:
name
: Returns the name of the Python implementation, such as “CPython” or “IronPython”.version
: Returns the version of the Python implementation.cache_tag
: Returns the cache tag for compiled bytecode files.hexversion
: Returns the Python version number in hexadecimal format.
Here is an example that demonstrates how to use sys.implementation
to retrieve and display these attributes:
import sys
# Retrieving Python implementation name
implementation_name = sys.implementation.name
print(f"Python implementation: {implementation_name}")
# Retrieving Python implementation version
implementation_version = sys.implementation.version
print(f"Python version: {implementation_version}")
# Retrieving cache tag
cache_tag = sys.implementation.cache_tag
print(f"Cache tag: {cache_tag}")
# Retrieving Python version number in hexadecimal format
hex_version = sys.implementation.hexversion
print(f"Python version (hex): {hex_version}")
Executing the above code will give you output similar to the following:
Python implementation: CPython
Python version: sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
Cache tag: cpython-38
Python version (hex): 0x30805f0
By utilizing sys.implementation
, you can access valuable information about the Python implementation you are working with and use it to make decisions or troubleshoot compatibility issues in your code.