gpt4 book ai didi

python - 检测 IronPython 的最佳方法

转载 作者:太空狗 更新时间:2023-10-29 17:03:05 24 4
gpt4 key购买 nike

我需要编写一个模块,用于 CPython 和 IronPython。检测 IronPython 的最佳方法是什么,因为在这种情况下我需要稍微不同的行为?

我注意到 sys.platform 在 CPython 上是“win32”,但在 IronPython 上是“cli”。

是否有另一种首选/标准检测方法?

最佳答案

Python 2.6 中的新功能是 platform.python_implementation :

Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’.

这可能是最简洁的方法,而且它是最标准的。但是,我相信 Jython 仍在运行 2.5,所以我不确定您是否可以依靠它来检测 Jython(但这不是您问题的一部分)。

关于python - 检测 IronPython 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2795240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com