Python - C# interoperability

M

mc

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?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

mc said:
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?

You should take a look at IronPython, which supports that kind of thing.

Regards,
Martin
 
B

Bruno Desthuilliers

mc a écrit :
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 can't tell if that'll do, but have you looked at IronPython ?
 
?

=?iso-8859-1?q?Luis_M._Gonz=E1lez?=

mc said:
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
 
M

mc

Thanks to all who responded. It appears that there may be a solution
as follows:

use jythonc to turn Python program into Java bytecode

use Microsoft's jbimp to turn Java bytecode into .NET DLL

It sounds roundabout, but I am investigating.
 
S

sturlamolden

mc said:
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?

One way is to use IronPython if you don't need modules written for
CPython.

Another option is to use a COM wrapper, e.g. using win32com in Python.

A third option is to embed a Python interpreter in your C# app.
 
L

Larry Bates

mc said:
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?

You can write COM objects that can be called from C# (or basically ANY
other language that can call COM objects) quite easily and compile them
with py2exe for distribution without python itself.

-Larry Bates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top