3

There are some great libraries for Python that have cousins in the .NET world, but some are unmatched.

Realizing that Python is a dynamic language, which makes it difficult to mix with a (largely) statically typed language like C# (though this is seemingly getting easier with .NET 4.0), there are options like IronPython which can help match up the two languages.

I've never come across any other options for dovetailing Python libraries with .NET. Are there any other ways to do this that are tried and true? I have far less experience with Python, so it's entirely possible that I'm overlooking something.

5 Answers 5

3

Providing your use case isn't dependent on speed you can use things like .net remoting and XML services to allow different platforms/languages/environments to talk to each other (this is the approach used by the Robot Framework RemoteLibrary for example).

Another option is to have some common data store behind both languages (typically a database).

1
  • The remoting is one I definitely hadn't thought of.
    – jonsca
    Commented Oct 24, 2011 at 14:12
5

I'm not saying I recommend this approach, but in the spirit of completeness, you could use COM to invoke Python from .NET or visa versa. I have never used COM with Python but apparently it is possible.

4

IronPython tries the total integration approach. There is a package called Python.NET that is a hybrid of the CLR and the standard C based Python runtime. It seems less developed than IronPython and I'm not sure it would be ".NET" enough. However, it would give direct access to Python libraries.

1
  • I have added a longeer post about Python.Net Commented Nov 2, 2016 at 8:02
3

Our application shells out to run python. We had to do that instead of using IronPython because a number of the base libraries are compiled from C. A simple test for determining what you'll have to do is to parse a CSV file.

2

We are using Python.Net to call CLR Code from Python and vice vera. It works rather well, but has some drawbacks, mainly that writing CLR code in Python is ...weird (this also applies to the other way).

So we are mostly using it as an interface: Have high level methods which can be called and which return defined data structures - we try to avoid to create a complete python program in C#-code. This has also adavantages in regard to testabillity.

Note that Python.Net is only slowly updated, which can be a problem if you want to use the newest and hottest python release. On ther other hand: you can use ALL of python, not just the IronPython subset.

A last word of warning: If you are calling CLR Code from Python try to avoid to pass CLR objects deeper into you python program - while Python.Net is good ad abstracting away some differences, other differences will come around to bite you, like trying to pickle/unpickle an CLR object. We found thst writing some conversion code really helps to mitigate such problems. Warning 2: There are some .Net exceptions which can bring your python process down. If you observe myterious shutdowns, take a look at the global .Net exception handler. This isn't the fault of either python or clr - just that both have somewhat different ideas of how some thinks should be handled.

Last but not least: In terms of data science, F# is really good and has some interesting libraries like http://bluemountaincapital.github.io/Deedle/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.