2

With what command inside code can I understand that IronPython or Python is running?

2 Answers 2

1

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’.

1

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")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.