Jython不如C Python健壮
Jython is generally considered to be buggier than the standard C implementation of the language. This is certainly due to its younger age and smaller user base, and it varies from JVM to JVM, but you are more likely to hit snags in Jython. In contrast, C Python has been amazingly bug-free since its introduction in 1990.
一般认为,Jython比标准的C Python实现具有更多的错误。当然是因为它出现时间不长,用户群小,以及随不同JVM而不同,但是使用Jython更有可能碰钉子。另一方面,C Python自从1990年出现以来,早已令人惊异地鲜有错误。
Jython may be less portable than C Python
Jython移植性可能不如C Pytnon
It's also worth noting that the core Python language is far more portable than Java (despite marketing statements to the contrary). Because of that, deploying standard Python code with the Java-based Jython implementation may actually lessen its portability. Naturally, this depends on the set of extensions you use, but standard Python runs today on everything from handheld PDAs, iPods, and cell phones to PCs, Cray supercomputers, and IBM mainframes.
同时值得注意的是,Python语言的核心远比Java移植性强(尽管市场报告是相反的)。因此,使用基于Java的Jython实现来部署标准的 Python代码,可能会降低它的移植性。自然的,这取决于你所使用的扩展库,但是标准的Python目前可运行于以下所有设备,从手持PDA, iPod,手机,到PC,Cray超级计算机,和IBM大型机。
Some incompatibilities between Jython and standard Python can be very subtle. For instance, Jython inherits all of the Java runtime engine's behavior, including Java security constraints and garbage collection. Java garbage collection is not based on standard Python's reference count scheme, and therefore can automatically collect cyclic objects.[*] It also means that some common Python programming idioms won't work. For example, it's typical in Python to code file-processing loops in this form:
Jython与标准Python之间的一些不兼容可能是非常细微的。例如,Jythone继承了所有Java运行时引擎的行为,包括Java安全性约束和垃圾回收。Java垃圾回收并非建立于标准Python的引用计数机制,因此可以自动回收循环对象。[*] 这也意味着一些通用的Python编程惯用法不能用了。例如,这是一个典型的Python代码,循环处理文件:
[*] But as of Python 2.0, its garbage collector can now collect cyclic objects too. See the 2.0 release notes and the gc standard library module in Python's library manual.
[*]但是从Python 2.0起,它的垃圾回收现在也能回收循环对象了。见Python库手册中的2.0发布说明及标准库模块gc。
text = open(filename).read( )
dostuffwith(text)
That works because files are automatically closed when garbage collected in standard Python, and we can be sure that the file object returned by the open call will be immediately garbage collected (it's temporary, so there are no more references as soon as we call read). This won't work in Jython, though, because we can't be sure when the temporary file object will be reclaimed. To avoid running out of file descriptors, we usually need to code this differently for Jython:
能那样做是因为在标准Python中垃圾回收时,文件会自动关闭,我们可以确信,open调用返回的文件对象会立即被垃圾回收(它是临时对象,一旦调用read,它就再也没有被引用了)。然而这不能用于Jython,因为我们不能确信何时临时文件对象才能收回。为了避免用光文件描述符,Jython通常需要这样编码:
file = open(filename)
text = file.read( )
dostuffwith(text)
file.close( )
You may face a similar implementation mismatch if you assume that output files are immediately closed: open(name,'w').write(bytes) collects and closes the temporary file object and hence flushes the bytes out to the file under the standard C implementation of Python only, and Jython instead collects the file object at some arbitrary time in the future.
如果你假定输出文件会被立即关闭,你可能面临类似的实现上的差异:仅在Python标准的C实现中,open(name,'w').write(bytes)会回收和关闭临时文件对象,因此清空缓冲区数据保存到文件,而Jython是在未来不确定的时刻回收文件对象。
18.4.7. Picking Your Python
18.4.7. 选择你的Python
Because of concerns such as those just mentioned, the Jython implementation of the Python language is probably best used only in contexts where Java integration or web-browser interoperability is an important design goal. You should always be the judge, of course, but the standard C implementation seems better suited to most other Python applications. Still, that leaves a very substantial domain to Jythonalmost all Java systems and programmers can benefit from adding Jython to their tool sets.
因为上述原因,Python语言的Jython实现最好仅用于特定环境,即当Java集成或浏览器互用性是一个重要的设计目标时。但是标准C实现看起来能更好地适用于大多数其它Python应用。当然,你才是决定者。Jython仍然具有很大的应用领域,几乎所有Java系统和程序员都可以受益于Jython。
Jython allows programmers to write programs that use Java class libraries in a fraction of the code and complexity required by Java-coded equivalents. Hence, Jython excels as an extension language for Java-based systems, especially those that will run in the context of web browsers. Because Java is a standard component of most web browsers, Jython scripts will often run automatically without extra install steps on client machines. Furthermore, even Java-coded applications that have nothing to do with the Web can benefit from Jython's ease of use; its seamless integration with Java class libraries makes Jython arguably the best Java scripting and testing tool available today.

