We've been using IronPython for a number of years as a scripting tool within some of our .Net desktop applications. Customers have been asking when we will support Python 3, but it looks like IronPython3 is still a long way off (https://github.com/IronLanguages/ironpython3). I've just found a library called Python.Net, and was wondering how similar this is to IronPython, and whether it is something we could move over to?
Most of the Python.Net examples show how to use .Net types from within Python code, and I can't find any good examples of how you actually run Python code from within C#. There's a section headed "Embedding Python" near the end of the page (http://pythonnet.github.io/), but it doesn't go into much detail.
I'm interested to know how to run a script from either a file or a string, whether scripts can be "compiled" (like IronPython), presumably "variables" can be passed back and forth like the IronPython scope? Are there any restrictions or known issues? Does Python.Net allows running of scripts that reference libraries such as numpy? (We were unable get this working with IronPython, which I believe was due to it containing compiled (.pyc) code, which IP doesn't support).
Does anyone have experience of both, and able to offer some insight on how they compare?
A short summary: originally Python.NET was designed to be a drop-in replacement for IronPython, so most of what you want is possible with the major caveat: you need to also have a regular Python interpreter.
Now to more details:
PythonEngine
class has Exec
and Eval
functions.PythonEngine
(which is just a representation of Python interpreter).PyScope
class, which lets you control a group of Python variables.The issues Python.NET has compared to IronPython:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With