473,473 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Python - C# interoperability

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?

Jan 9 '07 #1
6 4247
mc schrieb:
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
Jan 9 '07 #2
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 ?
Jan 9 '07 #3

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

Jan 10 '07 #4
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.

Jan 10 '07 #5

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

Jan 10 '07 #6
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?
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
Jan 11 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian Lloyd | last post by:
For those interested, I've made a preview-2 release of Python for .NET. Python for .NET is a near-seamless integration of the CPython runtime with the .NET Common Language Runtime (CLR). It...
5
by: Max Ischenko | last post by:
Hi, I've started to develop under Microsoft ASP framework, which allows different lang. used in a ActiveX page. I wonder about possible strategies to use Python modules from VBScript <%%>...
7
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional...
29
by: Maurice LING | last post by:
Hi, I remembered reading a MSc thesis about compiling Perl to Java bytecodes (as in java class files). At least, it seems that someone had compiled scheme to java class files quite successfully....
53
by: john67 | last post by:
The company I work for is about to embark on developing a commercial application that will cost us tens-of-millions to develop. When all is said and done it will have thousands of business...
53
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I...
1
by: Mark Harrison | last post by:
Right now I'm using Boost Python to wrap some C++ code so that applications from both languages can use it. This is great, but I'm rapidly coming to the conclusion that a lot of this work is...
17
by: Johann C. Rocholl | last post by:
Just in case anybody has the same problem, here's my first attempt at implementing a subset of the PNG spec in pure Python. I license it to you under the terms of the GNU GPL. ...
21
by: Raj | last post by:
Hi, We just executed a project with Python using TG. The feedback was to use more python like programming rather than C style code executed in Python. The feedback is from a Python purist and...
0
by: Luke Kenneth Casson Leighton | last post by:
On Sep 3, 10:02 pm, bearophileH...@lycos.com wrote: 1200 lines of code for the compiler, and about... 800 for a basic suite of builtin types (Dict, List, set, string). ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.