Tintenfiisch
Tintenfiisch

Reputation: 360

C# .NET interoperabillity with managed Python (CPython) -> any problems?

I am working on a design of an application. The Core should be written in C# but i also want to use some already finished CPython modules (un-managed).

So I am interested in the interoperability (Call CPython method from C# and Call C# from CPython). And if there are problems, because C# runs within the .NET runtime (managed) and CPython directly un-managed.

I already investigated this issue with Google and came out to these solutions:

What do you think, which way would be better ? or do you have another solution ?

And the last but maybe most important question, did I understand the above mentioned points right, or do I mess up ?

Many thanks in advance !!

Upvotes: 3

Views: 1269

Answers (2)

Joe43634732436
Joe43634732436

Reputation: 11

Expose your Python code via COM and call that from C#. Used this avenue (both ways) many times.

Upvotes: 1

Katriel
Katriel

Reputation: 123632

I think you misunderstand Python. It's an interpreted1 language. You just provide the text source files and the interpreter will execute them.

There is a difference between the language Python and the implementations CPython, IronPython, Jython, PyPy, what have you. Each of them attempts to implement the language Python as accurately as possible, while also adding implementation-specific functionality. This is just like how, say, the C# compiler was written in C++.

For example, any (pure) Python file can be executed by the IronPython interpreter. But if you know that you're going to use IronPython, you can use the special IronPython features that let you into the .NET library.

Now, most Python doesn't use any of the implementation-specific functionality, so it doesn't matter what you use to run it. Some Python does, though.

1Well, it's compiled into .pyc files... but then "compile" isn't really a well-defined term anyway.


Why does this matter to you? Well, you have a bunch of Python source code that you want to use with the .NET framework. If that code doesn't use any of the CPython-specific features -- such as using C extension modules -- then you can just run it in IronPython.

Upvotes: 2

Related Questions