views:

217

answers:

2

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.

+4  A: 

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.

technomalogical
+3  A: 

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

jle