python - 检测 IronPython 的最佳方法

标签 python ironpython version detection

我需要编写一个模块,用于 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/

相关文章:

perl - CPAN 模块需要什么 perl 版本?

spring-boot - 如何知道 spring-boot 项目中使用了哪些版本的 hibernate/spring 数据?

python - 如何正确使用 strip() 类型?

c# - 科学数据可视化和 .NET 框架

c# - 在托管应用程序中调用具有命名参数的函数

c# - 如何在二进制文件上将 AssemblyVersion 标记为 FileVersion

python - 使用 python 对文件进行排序

python - 在 Python 中使用 Dropbox API v2 覆盖文件

python - Pygame,改变我整个游戏的分辨率

c# - 使用 PTVS 进行 IronPython 远程调试