Using Python 3 with C#

Hello!

Is it possible to integrate python 3 and C#?

There is an application in c# in which you want to add scripting functionality in the form of python 3 scripts. It would be especially nice if python compiled in MSIL and could use CLR builds, but as I understand it, IronPython only supports 2.7.

If this is not possible, are there any other scripting languages that integrate well with the CLR (not just at the Interop level)?

Author: Kyubey, 2015-05-29

5 answers

IronPython wanted to add support for Python 3, but Microsoft stopped supporting development, and the main developer went to another company. Since the team is no longer there, there is no one to actively develop IronPython. IronPython and IronRuby were developed at the expense of Microsoft, then they ran out of interest in DLR, and they threw the code into open source. The last time I looked, the branch for the third python was sluggishly developing. This is so, a historical reference.

And now to the point. What's wrong with Python 2.7? If unicode, then in IronPython all strings are already unicode.

If you want a close connection with .NET, then this is one of the best options. Relationship with .NET is full-fledged and very detailed.

Generally, for .NET implements many languages, including Ruby, JavaScript, and others. But to choose them due to the fact that Python is not the version you need will be, at least, strange. In the near future, the 2.x branch will still live. And alternative implementations for .NET still won't keep up with the latest language updates, no matter what language you choose.

I can understand if you already have a layer of Python 3 code or an urgent need for new features of the third version of the language. But in conditions when you just need to add scripts to the application, you should focus on several other parameters: how common the language is, how clear it is, how well the interoperability is implemented.

 5
Author: Kyubey, 2015-05-29 11:03:19

About other languages.

  1. Powershell. A scripting language that natively runs in the CLR. Hence-transparent work with any objects.

  2. C#itself. The command-line mode is not supported, of course - but the script in the file can be compiled on the fly and executed.

 2
Author: Pavel Mayorov, 2015-05-29 11:20:46

Found IronPython for the third python. The last commit was 3 months ago.

You can also use the 3to2 converter (to convert Python 3 code to Python 2 code) and use the stable official version: $ pip install 3to2 $ 3to2 manifest_parser.py -w ...вывод опущен... $ python2 Python 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. ... import manifest_parser And no exceptions

 0
Author: Cyber Tailor, 2015-05-29 11:35:32

Another option:

Use a separate C# application and a separate python process, and communicate via SOAP or XML-RPC. Requests and responses can be sent via stdin/stdout, HTTP, or MQ...

The advantage of this method is the a priori ability to use the version of the language that seems most beautiful.

 0
Author: Pavel Mayorov, 2015-05-29 11:47:09

And another communication option. You can make the main application in python, and load the part in C# as a library. The CPython module can be easily written in C++/CLI.

 0
Author: Pavel Mayorov, 2015-05-29 11:50:44