Python 或 IronPython
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/590007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python or IronPython
提问by johnc
How does IronPython stack up to the default Windows implementation of Python from python.org? If I am learning Python, will I be learning a subtley different language with IronPython, and what libraries would I be doing without?
IronPython 如何叠加到 python.org 中 Python 的默认 Windows 实现?如果我正在学习 Python,我是否会使用 IronPython 学习一种微妙的不同语言,没有哪些库我会做什么?
Are there, alternatively, any pros to IronPython (not including .NET IL compiled classes) that would make it more attractive an option?
或者,IronPython 是否有任何优点(不包括 .NET IL 编译类)可以使其成为更具吸引力的选择?
采纳答案by zweiterlinde
There are a number of important differences:
有许多重要的区别:
- Interoperability with other .NET languages. You can use other .NET libraries from an IronPython application, or use IronPython from a C# application, for example. This interoperability is increasing, with a movement toward greater support for dynamic types in .NET 4.0. For a lot of detail on this, see thesetwopresentations at PDC 2008.
- Better concurrency/multi-core support, due to lack of a GIL. (Note that the GIL doesn't inhibit threading on a single-core machine---it only limits performance on multi-core machines.)
- Limited ability to consume Python C extensions. The Ironcladproject is making significant strides toward improving this---they've nearly gotten Numpyworking!
- Less cross-platform support; basically, you've got the CLR and Mono. Mono is impressive, though, and runs on many platforms---and they've got an implementation of Silverlight, called Moonlight.
- Reports of improved performance, although I have not looked into this carefully.
- Feature lag: since CPython is the reference Python implementation, it has the "latest and greatest" Python features, whereas IronPython necessarily lags behind. Many people do not find this to be a problem.
- 与其他 .NET 语言的互操作性。例如,您可以使用 IronPython 应用程序中的其他 .NET 库,或使用 C# 应用程序中的 IronPython。随着 .NET 4.0 中对动态类型的更大支持,这种互操作性正在增加。有关此很多的细节,看到这2个演讲在2008年PDC。
- 由于缺乏 GIL,更好的并发/多核支持。(请注意,GIL 不会禁止单核机器上的线程——它只会限制多核机器上的性能。)
- 使用 Python C 扩展的能力有限。在铁甲工程对改善该---他们已经得到了几乎使显著进步NumPy的工作!
- 较少的跨平台支持;基本上,你已经有了 CLR 和Mono。不过,Mono 令人印象深刻,并且可以在许多平台上运行——而且他们已经实现了 Silverlight,称为Moonlight。
- 性能改进的报告,尽管我没有仔细研究过。
- 功能滞后:由于 CPython 是参考 Python 实现,因此它具有“最新和最好的”Python 功能,而 IronPython 必然落后。许多人不认为这是一个问题。
回答by Epcylon
There are some subtle differences in how you write your code, but the biggest difference is in the libraries you have available.
您编写代码的方式存在一些细微的差异,但最大的差异在于您可用的库。
With IronPython, you have all the .Net libraries available, but at the expense of some of the "normal" python libraries that haven't been ported to the .Net VM I think.
使用 IronPython,您可以使用所有 .Net 库,但代价是一些我认为尚未移植到 .Net VM 的“普通”python 库。
Basically, you should expect the syntax and the idioms to be the same, but a script written for IronPython wont run if you try giving it to the "regular" Python interpreter. The other way around is probably more likely, but there too you will find differences I think.
基本上,您应该期望语法和习惯用法相同,但是如果您尝试将其提供给“常规”Python 解释器,则为 IronPython 编写的脚本将无法运行。另一种方式可能更有可能,但我认为你也会发现差异。
回答by TraumaPony
Well, it's generally faster.
嗯,它通常更快。
Can't use modules, and only has a subset of the library.
不能使用模块,并且只有库的一个子集。
回答by John D. Cook
See the blog post IronPython is a one-way gate. It summarizes some things I've learned about IronPython from asking questions on StackOverflow.
请参阅博客文章IronPython 是单向门。它总结了我从 StackOverflow 上提问中学到的一些关于 IronPython 的知识。
回答by Andy Dent
Pro: You can run IronPython in a browserif SilverLight is installed.
优点:如果安装了 SilverLight,您可以在浏览器中运行IronPython。
回答by Christian Witts
Python is Python, the only difference is that IronPython was designed to run on the CLR (.NET Framework), and as such, can inter-operate and consume .NET assemblies written in other .NET languages. So if your platform is Windows and you also use .NET or your company does then should consider IronPython.
Python 就是 Python,唯一的区别是 IronPython 被设计为在 CLR(.NET 框架)上运行,因此,可以互操作和使用用其他 .NET 语言编写的 .NET 程序集。因此,如果您的平台是 Windows 并且您也使用 .NET 或您的公司使用,那么应该考虑 IronPython。
回答by Rafa? Dowgird
One of the pros of IronPython is that, unlike CPython, IronPython doesn't use the Global Interpreter Lock, thus making threading more effective.
IronPython 的优点之一是,与 CPython 不同,IronPython 不使用全局解释器锁,从而使线程更有效。
In the standard Python implementation, threads grab the GIL on each object access. This limits parallel execution, which matters especially if you expect to fully utilize multiple CPUs.
在标准 Python 实现中,线程在每次访问对象时都会获取 GIL。这限制了并行执行,这在您希望充分利用多个 CPU 时尤其重要。
回答by Christopher Mahan
It also depends on whether you want your code to work on Linux. Dunno if IronPython will work on anything beside windows platforms.
它还取决于您是否希望您的代码在 Linux 上运行。不知道 IronPython 是否可以在 Windows 平台之外的任何东西上工作。