[IronPython] determine if running under IP

Dan Eloff dan.eloff at gmail.com
Wed May 21 21:26:51 CEST 2008


> Easy=)  Check the value of sys.platform which will be "cli" under IronPython.
Except if you're running IronPython under silverlight, in which case
it will be 'silverlight'

You could do:

try:
    import clr
    IronPython = True
except ImportError:
    IronPython = False

Except if you're running CPython with Python .NET, in which case it
will falsely identify as IronPython (is that wrong? Python .NET aims
to be as compatible as possible with IronPython)

There's really a million ways to discover this, some of them
outlandishly hackish, e.g.

IronPython = 'Microsoft' in sys.copyright

It depends I guess on what you're particular needs are, and and how
elegant you want your solution to be. I hope this gives you some
ideas, be creative.

-Dan



More information about the Ironpython-users mailing list