示例工程 01-orientation
01-orientation/01-hello-runtime/hello_runtime.py
"""演示 CPython 运行时的基本信息与 sys.path 结构。"""
from __future__ import annotations
import platform
import sys
def runtime_info() -> dict[str, object]:
"""返回解释器与导入路径的可断言快照。"""
return {
"implementation": platform.python_implementation(),
"version": platform.python_version(),
"executable": sys.executable,
"path0": sys.path[0] if sys.path else None,
"cache_tag": sys.implementation.cache_tag,
}
def main() -> None:
for key, value in runtime_info().items():
print(f"{key}: {value}")
if __name__ == "__main__":
main()