Python - C# interoperability

Luis M. González luismgz at gmail.com
Tue Jan 9 22:50:57 EST 2007


mc wrote:
> Is there an easy way to compile a Python class (or set of classes) into
> a .DLL that a C# program can call?  Or otherwise to use an existing
> library of Python classes from a C# program as seamlessly as possible?

I'm affraid this is not possible.
Ironpython (the .NET python implementation) can consume assemblies
written in other statically typed languages, such as c#, but not the
other way around.
This is because Ironpython is still a dynamic language, and the lack of
type information makes it impossible to be compiled as c#.

For the time being, if you really need to write reusable assemblies
that could be consumed from other .NET languages, you shouldn't use
Ironpython.
You should use c#, vb.net or any other static language implementation
for .NET.

If you want a more "pythonic" alternative, you could use Boo (
http://boo.codehaus.org ).
It's a static language with a python-like syntax, and it's very easy to
pick up if you already know python.

For consuming Boo assemblies from Ironpython, you should compile them
as .DLL, and place them into a "DLLs" folder in your Ironpython root
directory (where ipy.exe is located).
Then you simply import them as you would with any other python module.
Make sure to add also the boo assembly. If you are using c# instead,
you don't have to add anything else.

Hope this helps,
Luis




More information about the Python-list mailing list