I need to write a module which will be used from both CPython and IronPython. What's the best way to detect IronPython, since I need a slightly different behaviour in that case?
I noticed that sys.platform is "win32" on CPython, but "cli" on IronPython.
Is there another preferred/standard way of detecting it?
New in Python 2.6 is platform.python_implementation
:
Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’.
That's probably the cleanest way to do it, and that's about as standard as it gets. However, I believe Jython is still running 2.5, so I'm not sure you can rely on this to detect Jython just yet (but that wasn't part of your question anyway).