Once a Python program is compiled with Jython, it is all Java: the program is translated to Java bytecode, it uses Java classes to do its work, and there is no Python left except for the original source code. Because the compiler tool itself is also written in Java, Jython is sometimes called "100 percent pure Java." That label may be more profound to marketers than programmers, though, because Jython scripts are still written using standard Python syntax, use Python datatypes, and import many of Python's standard library modules. For instance, Example 18-5 is a legal Jython program, derived from an example originally written by Guido van Rossum.
Python程序用Jython编译后,它就是Java的了:它已经转化为Java字节码,虽然源码是Python的,但它运行的是Java类,与Python已经无关了。因为编译器本身是用Java编写的,Jython有时被称为“百分之百的纯Java”。当然这一称法只是对市场人员有意义,对于程序员来说,Jython脚本仍是按标准的Python语法编写的,使用Python数据类型,并且导入了许多Python标准库模块。例如,例18-5改编自Guido van Rossum的原作,它是一个合法的Jython程序。
Example 18-5. PP3E\Internet\Other\Jython\jycalc.py
#########################################################################
# implement a simple calculator in Jython; evaluation runs a full
# expression all at once using the Python eval( ) built-in--Jython's
# source-code compiler is present at runtime, as in standard Python
#########################################################################
from java import awt # get access to Java class libraries
from pawt import swing # they look like Python modules here
labels = ['0', '1', '2', '+', # labels for calculator buttons
'3', '4', '5', '-', # will be used for a 4x4 grid
'6', '7', '8', '*',
'9', '.', '='

