With what command inside code can I understand that IronPython or Python is running?
2 Answers
Check the value of platform.python_implementation()
.
platform.python_implementation()
Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.
Check the value of sys.implementation.name
.
name is the implementation’s identifier, e.g.
'cpython'
. The actual string is defined by the Python implementation, but it is guaranteed to be lower case.
For IronPython sys.implementation.name
is 'ironpython'
, for Python it is 'cpython'
.
Example:
import sys
if sys.implementation.name == 'cpython':
print("I am Python")
elif sys.implementation.name == 'ironpython':
print("I am IronPython")
else:
print("I am something else")