Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import python functions into a .NET language?

I am a C# .NET programmer and am learning Python. I have downloaded IronPython, and know that it can call into .NET libraries.

I'm wondering whether there is a way to do the reverse, that is to call into some existing "classic" Python libraries in my C# code, maybe using .NET Interop.

I'd like to be able to access functions in libraries such as pygame.

like image 757
Buggieboy Avatar asked Feb 18 '09 15:02

Buggieboy


2 Answers

Ironpython 2.0 is CPython 2.5 compatible, so pure Python that uses <=2.5 APIs should work fine under Ironpython. I believe Ironpython code can then be compiled into a DLL.

For C-extensions like Pygame, you might want to take a look at Ironclad. It's a project to allow for C-extensions to be used within Ironpython. This may also give you the native code bridge you're looking for.

like image 97
technomalogical Avatar answered Nov 06 '22 15:11

technomalogical


You can use Python for .Net, which allows you to 'use CLR services and continue to use existing Python code and C-based extensions while maintaining native execution speeds for Python code.'

Further, 'A key goal for this project has been that Python for .NET should "work just the way you'd expect in Python", except for cases that are .NET specific (in which case the goal is to work "just the way you'd expect in C#"). In addition, with the IronPython project gaining traction, it is my goal that code written for IronPython run without modification under Python for .NET.'

Hope this helps

like image 26
jle Avatar answered Nov 06 '22 14:11

jle