IronPython 与原始 Python 的比较。我可以从第一个中期待什么?
我希望学习 Python,但我作为一名 C# 开发人员整天在 .Net 中工作,因此我决定下载并安装 IronPython 和集成的 IronPython studio。它与原始 Python 有何不同或相似?作为一名 .Net 开发人员,我是否可以期望在 .Net 环境中毫无问题地运行传统的 Python 脚本,或者这只是同一个旧的迁移乌托邦?我可以期待什么?
提前致谢。
编辑:迪克。 2009 - IronPython 最近已升级至 2.6。如果可能,请升级您的答案。
I wish to learn Python but I'm working all day in .Net as a C# developer, so I decided to download and install IronPython and integrated IronPython studio. How different or similar from the original Python it is? As a .Net developer can I expect to run conventional Python script in .Net environment with no problem or this is just the same old migration utopia? What can I expect about?
Thanks in advance.
EDIT: Dic. 2009 - IronPython has been upgraded to 2.6 recently. Please upgrade your answers if is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的情况,学习 IronPython 是完全合理的(特别是这本书可以很好地帮助您那!)。您将可以访问几乎所有 Python 2.5 功能(不确定 IronPython 何时升级到 Python 2.6 版本,但 2.5 已经相当可用),以及您所使用的所有 .Net 库和程序集。了解并喜爱 Visual Studio 加载项等工具。
CPython 和 IronPython(以及 Jython,就这一点而言,它将与 IronPython 相同的概念应用于 JVM —— Jim Hugunin 早在他搬到 Microsoft 之前就是 Jython 的创始人,在那里他创立了 IronPython,这两个项目现在都蓬勃发展)主要在垃圾收集和线程方面:IronPython 和 Jython 依赖于它们的底层平台(因此,您可以获得标记和清除垃圾收集和自由线程),CPython 推出自己的(因此,它主要是引用计数 GC,具有标记和清除功能) -偶尔扫描一次以解决引用循环和全局解释器锁阻碍的线程)。
编码良好的 Python 脚本不依赖于所讨论的实现细节(它从不假设 GC 立即发生,从不假设操作在线程下是原子的,除了少数几个,如 Queue.Queue 的方法,它们被明确记录为),但是当然还有很多草率的脚本。例如:
这会使文件对象保持打开状态,直到它被垃圾回收为止;在引用计数环境中,收集会立即发生(因此文件会尽快关闭),而在标记和清除环境中则并非如此(因此使用此类构造的进程通常会错误地保留一些文件,可能是许多文件,无用地打开时间远远超过其需要的时间,浪费系统资源&c)。
因此,正确的 Python 编码是这样的:
它确实保证在每个实现中立即关闭文件(
with
语句非常非常方便) ;-)。这并不影响你学习Python,也不妨碍重用正确编码的Python代码,但是如果你想重用编码不规范的Python代码(特别是在长时间运行的服务器、服务、守护进程等中) ;c) 您将来可能需要对其进行一些收紧。因此,顺便说一句,那些想要使用更新更好的 CPython 版本(例如 Unladen Swallow &c)的人,一旦这些版本实现了更好的垃圾收集机制,就会摆脱 GIL 和其他增强功能吗?希望这已经改变了 Python 社区的“文化”,转向更正确、更少马虎的编码,但当然,周围有无数行旧的马虎代码,所以需要小心;-)。
In your situation it's perfectly reasonable to study IronPython (especially as this book does a great job helping you do that!). You'll have access to essentially all of Python 2.5 functionality (not sure when IronPython will upgrade to a 2.6 version of Python, but 2.5 is already quite usable), plus all the .Net libraries and assemblies you know and love, and tools such as Visual Studio add-ins.
The differences between CPython and IronPython (and Jython, for that matter, which applies the same concept as IronPython to the JVM -- Jim Hugunin was the originator of Jython long before he moved to Microsoft where he originated IronPython, both projects now thrive) are chiefly in garbage collection and threading: IronPython and Jython rely on their underlying platforms (so, you get mark-and-sweep garbage collection and free threading), CPython rolls its own (so, it's mostly reference-count GC, with mark-and-sweep once in a while to resolve reference loops, and threading hampered by a global interpreter lock).
A well-coded Python script does not rely on the implementation details in question (it never assumes that GC happens immediately, never assumes that an operation is atomic under threading except for the few, like Queue.Queue's methods, that are explicitly documented to be), but of course there's plenty of scripts out in the wild that are sloppy. For example:
this leaves the file object open until it's garbage collected; in a reference-count environment the collection happens immediately (so the file gets closed ASAP), in a mark-and-sweep environment that is not the case (so the process using such constructs often would erroneously keep some files, maybe many files, uselessly open for far longer than they need to be, wasting system resources &c).
So, proper Python coding is instead:
which does guarantee immediate closure of the file in every implementation (the
with
statement is very very handy that way;-).This doesn't affect your learning of Python, nor does it impede reuse of properly-coded Python code, but if and when you want to reuse sloppily-coded Python code (especially in a long-running server, service, daemon process, &c) you may in the future need to do some tightening up thereof. So, btw, will people who want to use newer and better CPython versions, such as Unladen Swallow &c, once those versions implement better garbage collection mechanisms, get rid of the GIL, and other enhancements; hopefully this is already changing the "culture" of the Python community towards more correct, less sloppy coding, but of course there's bazillions of lines of old sloppy code around, so some care is needed;-).
大多数 Python 脚本在 IronPython 中都能完美运行。
这是一个 最新版本中 IronPython 中未包含的软件包和模块列表。
只要您的脚本不依赖于这些,它很可能无需更改即可工作。然而,通过将脚本迁移到使用 .NET 框架类而不是 python 标准库,IronPython 的大部分“功能”才真正发挥作用。
Most python scripts work perfectly well in IronPython.
Here is a list of packages and modules not included in IronPython in the latest release.
As long as your script doesn't rely on these, it will most likely work without changes. However, much of the "power" of IronPython really comes into play by migrating your scripts to use .NET framework classes instead of the python standard library.