IronPython

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

IronPython is written entirely in C # and is provided under the Apache License 2.0. IronPython is in the language range compatible with CPython 2.7, but without the Python standard library ( see Related links ) delivered. It can, however, all the modules of CPython installation charge, as long as they do not require compiled libraries. Access to. NET assemblies unrestricted access.

Programs written in IronPython can be interpreted both as well as just- in-time executables translate. As usual in. NET, you can IronPython access to libraries written in other. NET languages ​​, as well as those with restrictions on access in IronPython written libraries.

The IronPython environment can be used as a scripting language to automate a. NET application. The runtime environment is included in the. NET application. It can be passed to the script any object, which is useful for example for games extensions or plug-in development.

Examples

An output without NET library. :

Print " Hello world!" Using the same example, this time with an "internal " library NET. :

From System import Console        Console.WriteLine ( "Hello World !") And even with the help of an "external " NET library with the MyLib.dll in any other NET language can be written ( for example, C #, Visual Basic NET or C / CLI. ). .:

Import clr      clr.AddReferenceToFile ( " MyLib.dll " )      from import MyLib Out        Out.print ("Hello World !") IronPython in C # embed (eg 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 ) );          }      } Suppose the C # program is compiled as eval.exe before and the IronPython runtime libraries IronPython.dll and IronMath.dll (eg in the same directory ) are present, any Python expressions can be evaluated:

C: \> eval.exe 2 2   4     C: \> eval.exe 2 ** 3   8     C: \> eval.exe 5% 3   2 In a tutorial that comes with the Iron Python package, is an example to see how IronPython can be used as a scripting language for C #.

417360
de