IronPython

from Wikipedia, the free encyclopedia
IronPython
Ironpython-logo.png
Basic data
Publishing year: 2006
Designer: Jim Hugunin
Developer: Jim Hugunin, Microsoft
Current  version : 2.7.10   (April 27, 2020)
Operating system : Platform independent
License : Apache license 2.0
ironpython.net

IronPython is an implementation of the Python programming language for the Common Language Infrastructure (CLI) or compatible runtime environments such as B. Mono .

IronPython is written entirely in C # and is provided under the Apache 2.0 license . IronPython is language-compatible with CPython 2.7, but is delivered without the Python standard library. However, all modules of a CPython installation can be loaded as long as they do not require any compiled libraries. Access to .NET assemblies is possible without restriction.

Programs created in IronPython can be interpreted and just-in-time translated into executable files. As is usual in .NET, you can use IronPython to access libraries that were written in other .NET languages, just as they can, with restrictions, access libraries written in IronPython.

The IronPython environment can be used as a scripting language to automate a .NET application. The runtime environment is integrated into the .NET application. Any objects can be passed to the script. B. makes sense for game extensions or plug-in developments.

Examples

Output without .NET library:

print "Hallo Welt!"

The same example, this time with an "internal" .NET library:

from System import Console

Console.WriteLine("Hallo Welt!")

And once with the help of an "external" .NET library, whereby the MyLib.dll can be written in any other .NET language (e.g. C # , Visual Basic .NET or C ++ / CLI ):

import clr
clr.AddReferenceToFile("MyLib.dll")
from MyLib import Out

Out.Print("Hallo Welt!")

Embed IronPython in C # (e.g. as a calculator):

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

public class Eval
{
    public static void Main(string[] args)
    {
        ScriptEngine se = Python.CreateEngine();
        Console.WriteLine(se.Execute(args[0]));
    }
}

Assuming the C # program is compiled as eval.exe and the IronPython runtime libraries IronPython.dll and IronMath.dll (e.g. in the same directory) are available, any Python expressions can be evaluated:

 C:\> eval.exe 2+2
 4

 C:\> eval.exe 2**3
 8

 C:\> eval.exe 5%3
 2

A tutorial that is included with the IronPython package shows an example of how IronPython can be used as a scripting language for C #.

See also

  • Python , the Python programming language
  • Jython , Java implementation of the Python programming language
  • PyPy , implementation of the Python programming language in Python itself
  • Boo , implementation of the Python-like programming language Boo for .NET

Individual evidence

  1. IronPython 2.7.10 release

Web links