473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 4243
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.