Iron Python : what are good uses for Iron Python [

2019-04-03 12:01发布

问题:

I have an affinity for python, but I work in a .NET environment, so I was looking into Iron Python, and wondering what it would be used for.

Could you write an app in it? or is it for adding a scripting language to your app?

How do you guys use it?

回答1:

Either or both :)

I wouldn't claim to know a specific "purpose" for IronPython but it certainly can be used to write applications, and it can be used for scripting within a larger .NET application.

Aside from anything else, it's a handy way of gently easing Python developers into the world of .NET. (Why not learn C# at the same time? Come on in, the water's lovely...)



回答2:

The biggest benefit of IronPython is that it brings the worlds of Python and .NET very close together.

If you have libraries (assemblies) written in C# you can import those directly into IronPython and use them, like this:

import clr
clr.AddReferenceToFileAndPath('MyAssembly.dll')

import MyNamespace

c = MyNamespace.MyClass()

c.MyFunction()

This is very nice for reusing exisiting .NET code when scripting or even interactive use with the IronPython interpreter.

Ordinary CPython requires Python .NET to do the same or similar things. In my experience, Python .NET works most of the time, but not always and IronPython provides a much more polished experience in accessing .NET from Python.

IronPython will probably always lag the reference implementation of CPython in terms of standard library support etc., but in general the development is not that far behind, that it would hard to work with coming from a CPython background.

Lastly, there are a few substantial differences between CPython and IronPython, to which, one should pay attention. Example - garbage collection (bit me the other day...).



回答3:

  • IronPython is just Yet Another Python Implementation. You can use it anywhere you would use any other Python implementation. (Modulo platform constraints, of course – obviously you can't use IronPython on a Java-only device.)
  • IronPython is just Yet Another .NET Compiler. You can use it anywhere you would use any other .NET language.
  • IronPython is More Than Just Yet Another Python Implementation. It's a Python implementation that gives you full access to any .NET library.
  • IronPython is More Than Just Yet Another .NET Compiler. It's a .NET compiler that gives you full access to any Python library.
  • IronPython is an embeddable scripting engine for any .NET app, library and framework.


回答4:

IronPython with WPF is the most productive way to design a GUI that I'm aware of. Almost all of the app pictured below is written in IronPython. Only very small parts are done in C# or C++/CLI for performance reasons.

Sure, you do miss some WPF/C# integration, but you gain much more on the productiveness side.

IronPython is also much easier to extend than CPython. You take your C++ code and just add a small C++/CLI wrapper on top of it. CPython has nothing which is as easy as this. That's the reason that I've started using IronPython, because I got tired of writing wrappers for my C++ code in CPython. Boost.Python, SWIG, and the like didn't work for me.



回答5:

I think the Iron family of languages is primarily for adding more flavours to the platform, allowing you to get into .NET using a language that you are familiar with. It lowers the bar a lot for getting new people with different backgrounds into .NET

Even though the syntax is Python, the implementation is still built on top of the CLR and the end product will not differ a lot if you decide to go for an IronPython project instead of say C#.

I've had some experience with IronPython and find it nice to work with (it helps of course that I really like the language). IronPython is now considered a first class citizen by Microsoft, and that is also the impression you get when using it. One downside to using it though is that it isn't as widely adopted as the two main languages, causing some issues when it comes to collaboration and maintaining a code base over time.

I found it particularly useful when doing a .NET port of a search algorithm that was first implemented in Python.

Regarding adding scripting abilities to your app, that is probably not the original intention with IronPython, but it has been done. The Umbraco CMS has (or at least had) the ability to create widgets using Python as a dynamic scripting language within their platform. A pretty neat feature to have.

You should go ahead and try it out.. It's always good to have more tools in the belt :)



回答6:

We use it as an embedded language inside of our software. I had an article on my blog, but recently switched to a new system. You can find an archived version (with broken image links) here:

Our field engineers now use the embedded language to test things on the fly, our quality assurance people use it to create small scripts to test all features of the hardware, etc....

Hope this helps.



回答7:

You use it to write Python code that runs on the .NET platform. It's good for anything that Python is good for.

The Python language is the Python language, no matter what. IronPython is an implementation of the runtime for that language - the support code that compiles your source, creates a virtual machine to execute the bytecode in the resulting .pyc file, communicates with the OS in order to put command line arguments into sys.argv, and all that other fun stuff. (Well, OK, the .NET platform itself does a lot of the work, too. :) )



回答8:

My experience of IronPython is usage it as part of engine that can be changed after installation of base .Net application. With help of Python we have described really large set of business rules, that can be changed from two system installation. Partially IronPython was used as plugin language.

The difference from script language - that after compilation IronPython executed as CLR code.



回答9:

First: IronPython is really more of a compiler than an interpreter in the strictest sense - it will be used to generate .NET Assemblies from your python source files. So yes, you can write apps and most anything the .NET Framework can do.

One of the largest benefits of IronPython is that it has (effectively) no GIL - meaning that if you are both writing Python code and it is multi-threaded - you can often get performance that is better than CPython without having to spawn multiple process and pickle objects across the boundaries. It doesn't solve the problem of concurrency, but .NET provides much more robust constructs for dealing with it. I think this is pretty niche honestly, but it is certainly there.

The python.org wiki page for IronPython lists a bunch of key differentiators as well:



回答10:

You can write an app in it, you can use it as a scripting language in your app.

It's used for accessing existing Python libraries and, if needed, writing parts of your code in Python if a .NET languages doesn't seem well enough suited for that job.



回答11:

I think Resolver Systems built their products with IronPython. So there is definitely some real-world use of IronPython.

Enthought also anounced that they will port NumPy to IronPython and .Net. This will certainly broaden the appeal of IronPython.



回答12:

You can use it for cool things like having an embedded web server within your application which can be developed with one of the available Python web frameworks. It is much easier and smoother to develop for than hosting an ASP.NET web server within your application. CherryPy for example comes with a builtin web server as well that should work fine with IronPython with a few small modifications.