Embedding IronPython in C#

See embedding on the Voidspace site. An example there, The IronPython Calculator and the Evaluator works over a simple python expression evaluator called from a C# program. public string calculate(string input) { try { ScriptSource source = engine.CreateScriptSourceFromString(input, SourceCodeKind.Expression); object result = source.Execute(scope); return result.ToString(); } catch (Exception ex) { return “Error”; } }

How to use a C# dll in IronPython

import clr clr.AddReferenceToFileAndPath(r”C:\Folder\Subfolder\file.dll”) is the simplest way as proposed by Jeff in the comments. This also works: import clr import sys sys.path.append(r”C:\Folder\Subfolder”) # path of dll clr.AddReference (“Ipytest.dll”) # the dll import TestNamspace # import namespace from Ipytest.dll

IDE for ironpython on windows [closed]

SharpDevelop with IronPython 2.0 Beta Integration is worth a look – especially given that it’s free. Also, check out this Iron Python 2 – what IDE do YOU use? discussion. Seems to confirm your belief that “IronPython Studio doesn’t support IronPython 2”.

Ironpython 2.6 .py -> .exe [closed]

You can use pyc.py, the Python Command-Line Compiler, which is included in IronPython since version 2.6 to compile a Python script to an executable. You find it at %IRONPYTONINSTALLDIR%\Tools\Scripts\pyc.py on your hard disk. Example Let’s assume you have a simple script test.py that just prints out something to console. You can turn this into an … Read more

Instantiating a python class in C#

IronPython classes are not .NET classes. They are instances of IronPython.Runtime.Types.PythonType which is the Python metaclass. This is because Python classes are dynamic and support addition and removal of methods at runtime, things you cannot do with .NET classes. To use Python classes in C# you will need to use the ObjectOperations class. This class … Read more

Calling a C# library from python

It is actually pretty easy. Just use NuGet to add the “UnmanagedExports” package to your .Net project. See https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports for details. You can then export directly, without having to do a COM layer. Here is the sample C# code: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using RGiesecke.DllExport; class Test … Read more