Iron Python : what are good uses for Iron Python [

2019-04-03 11:29发布

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?

12条回答
疯言疯语
2楼-- · 2019-04-03 12:06

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...)

查看更多
欢心
3楼-- · 2019-04-03 12:06

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...).

查看更多
We Are One
4楼-- · 2019-04-03 12:06

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.

查看更多
再贱就再见
5楼-- · 2019-04-03 12:11

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楼-- · 2019-04-03 12:13

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.

查看更多
别忘想泡老子
7楼-- · 2019-04-03 12:18

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.

alt text

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.

查看更多
登录 后发表回答