Commits

Bruce Eckel  committed 162d6c8

Another rewrite of Jython.rst, which is now in decent enough shape for the conference.

  • Participants
  • Parent commits 4b769ef

Comments (0)

Files changed (10)

File Python3PatternsIdioms.pdf

Binary file modified.

File code/Jython/Walk_comprehension.py

 # Jython/Walk_comprehension.py
 import os
 restFiles = [os.path.join(d[0], f) for d in os.walk(".")
-             for f in d[2] if f.endswith(".java")]
+             for f in d[2] if f.endswith(".java") and 
+             "PythonInterpreter" in open(os.path.join(d[0], f)).read()]
 for r in restFiles:
     print(r)

File html/Jython.html

 that the material can be used to introduce Java programmers to
 Jython.</p>
 </div>
-<p>This chapter looks at the value of crossing language boundaries. It is often
-advantageous to solve a problem using more than one programming language, rather
-than being arbitrarily stuck using a single language. As you&#8217;ll see in this
-chapter, a problem that is very difficult or tedious to solve in one language
-can often be solved quickly and easily in another. If you can combine the use of
-languages, you can create your product much more quickly and cheaply.</p>
-<p>The most straightforward use of this idea is the <em>Interpreter</em> design
-pattern, which adds an interpreted language to your program to allow
-the end user to easily customize a solution. If the application user
-needs greater run time flexibility, for example to create scripts
-describing the desired behavior of the system, you can use
-<em>Interpreter</em> by creating and embedding a language interpreter into
-your program.</p>
+<p>Sometimes it&#8217;s easier and faster to temporarily step into another
+language to solve a particular aspect of your problem.</p>
+<p>This chapter looks at the value of crossing language boundaries. It is
+often advantageous to solve a problem using more than one programming
+language; as you&#8217;ll see, a problem that is very difficult or tedious
+to solve in one language can often be solved quickly and easily in
+another. By combining languages, you can create your product much more
+quickly and cheaply.</p>
+<p>One use of this idea is the <em>Interpreter</em> design pattern, which adds
+an interpreted language to your program to allow the end user to
+easily customize a solution. If the application user needs greater run
+time flexibility, for example to create scripts describing the desired
+behavior of the system, you can use <em>Interpreter</em> by creating and
+embedding a language interpreter into your program.</p>
 <p>In Java, the easiest and most powerful way to do this is with <em>Jython</em>
 <a class="footnote-reference" href="#id3" id="id1">[1]</a>, an implementation of Python in pure Java byte codes. As you will
 see, this brings together the benefits of both worlds.</p>
-<p><em>Interpreter</em> solves a particular problem &#8211; that of creating a
-scripting language for the user. But sometimes it&#8217;s just easier and
-faster to temporarily step into another language to solve a particular
-aspect of your problem. You&#8217;re not creating an interpreter, you&#8217;re
-just writing some code in another language.</p>
-<div class="section" id="interpreter-motivation">
-<h2>Interpreter Motivation<a class="headerlink" href="#interpreter-motivation" title="Permalink to this headline">¶</a></h2>
-<p>Remember that each design pattern allows one or more factors to change, so it&#8217;s
-important to first be aware of which factor is changing. Sometimes the end users
-of your application (rather than the programmers of that application) need
-complete flexibility in the way that they configure some aspect of the program.
-That is, they need to do some kind of simple programming. The interpreter
-pattern provides this flexibility by adding a language interpreter.</p>
-<p>The problem is that developing your own language and building an interpreter is
-a time-consuming distraction from the process of developing your application.
-You must ask whether you want to finish writing your application or create a new
-language.  The best solution is to reuse code: embed an interpreter that&#8217;s
-already been built and debugged for you. The Python language can be freely
-embedded into your for-profit application without signing any license agreement,
-paying royalties, or dealing with strings of any kind. There are basically no
-restrictions at all when you&#8217;re using Python.</p>
-<p>For solving Java problems, we will look at a special version of Python called
-Jython. This is generated entirely in Java byte codes, so incorporating it into
-your application is quite simple,  and it&#8217;s as portable as Java is. It has an
-extremely clean interface with Java: Java can call Python classes, and Python
-can call Java classes.</p>
+<p>Jython is generated entirely in Java byte codes, so incorporating it
+into your application is quite simple, and it&#8217;s as portable as Java
+is. It has an extremely clean interface with Java: Java can call
+Python classes, and Python can call Java classes.</p>
 <p>Because Jython is just Java classes, it can often be &#8220;stealthed&#8221; into
 companies that have rigid processes for using new languges and
 tools. If Java has been accepted, such companies often accept anything
 that runs on the JVM without question.</p>
-<p>Python is designed with classes from the ground up and is a truly pure object
-oriented language (both C++ and Java violate purity in various ways). Python
-scales up so that you can create very big programs without losing control of the
-code. Java projects have been quickly created using Jython, then later optimized by
-rewriting sections of the Jython code that have profiled as bottlenecks into Java.</p>
-</div>
+<p>The Python/Jython language can be freely embedded into your for-profit
+application without signing any license agreement, paying royalties,
+or dealing with strings of any kind. There are basically no
+restrictions when you&#8217;re using Python/Jython.</p>
+<p>Python is designed with classes from the ground up and provides pure
+support for object-oriented programming (both C++ and Java violate
+purity in various ways). Python scales up so that you can create large
+programs without losing control of the code. Java projects have been
+quickly created using Jython, then later optimized by rewriting into
+Java sections of the Jython code that have profiled as bottlenecks.</p>
 <div class="section" id="installation">
 <h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
 <p>To install Jython, go to <a class="reference external" href="http://jython.sourceforge.net">http://jython.sourceforge.net</a>.</p>
 </div>
 <div class="section" id="scripting">
 <h2>Scripting<a class="headerlink" href="#scripting" title="Permalink to this headline">¶</a></h2>
-<p>One very compelling benefit of using a dynamic language on the JVM is
+<p>One compelling benefit of using a dynamic language on the JVM is
 scripting.  You can rapidly create and test code, and solve problems
 more quickly.</p>
 <p>Here&#8217;s an example that shows a little of what you can do in a Jython
 benefits of the JVM. The total runtime of the cpython version is
 faster because of its rapid startup time; the JVM always has a delay
 for startup.</p>
-<p>Note that things that require much more code (and often research) in
-Java are very quick to write in Jython. Here&#8217;s an example that uses
-a Python <em>list comprehension</em> with the <strong>os.walk()</strong> function to visit
-all the directories in a directory tree, and find all the files with names
-that end in <strong>.java</strong> (of course you can easily do more sophisticated things
-like opening the file and looking for information within it):</p>
+<p>Note that things that are very quick to write in Jython require much
+more code (and often research) in Java. Here&#8217;s an example that uses a
+Python <em>list comprehension</em> with the <strong>os.walk()</strong> function to visit
+all the directories in a directory tree, and find all the files with
+names that end in <strong>.java</strong> and contain the word <strong>PythonInterpreter</strong>:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="c"># Jython/Walk_comprehension.py</span>
 <span class="k">import</span> <span class="nn">os</span>
 
 <span class="n">restFiles</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s">&quot;.&quot;</span><span class="p">)</span>
-             <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="mf">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&quot;.java&quot;</span><span class="p">)]</span>
+             <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="mf">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&quot;.java&quot;</span><span class="p">)</span> <span class="ow">and</span>
+             <span class="s">&quot;PythonInterpreter&quot;</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="n">f</span><span class="p">))</span><span class="o">.</span><span class="n">read</span><span class="p">()]</span>
 
 <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">restFiles</span><span class="p">:</span>
     <span class="k">print</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
 The fact that you can quickly try things out allows you to test
 concepts, and then create more refined code as needed.</p>
 </div>
+<div class="section" id="interpreter-motivation">
+<h2>Interpreter Motivation<a class="headerlink" href="#interpreter-motivation" title="Permalink to this headline">¶</a></h2>
+<p>Remember that each design pattern allows one or more factors to
+change, so it&#8217;s important to first be aware of which factor is
+changing. Sometimes the end users of your application (rather than the
+programmers of that application) need complete flexibility in the way
+that they configure some aspect of the program.  That is, they need to
+do some kind of simple programming. The <em>Interpreter</em> pattern provides
+this flexibility by adding a language interpreter.</p>
+<p>The problem is that creating your own language and building an
+interpreter is a time-consuming distraction from the process of
+developing your application.  You must ask whether you want to finish
+writing your application or make a new language.  The best solution is
+to reuse code: embed an interpreter that&#8217;s already been built and
+debugged for you.</p>
 <div class="section" id="creating-a-language">
-<h2>Creating a Language<a class="headerlink" href="#creating-a-language" title="Permalink to this headline">¶</a></h2>
+<h3>Creating a Language<a class="headerlink" href="#creating-a-language" title="Permalink to this headline">¶</a></h3>
 <p>It turns out to be remarkably simple to use Jython to create an
 interpreted language inside your application. Consider the greenhouse
 controller example from <em>Thinking in Java</em>. This is a situation where
 you want the end user &#8211; the person managing the greenhouse &#8211; to have
 configuration control over the system, and so a simple scripting
-language is the ideal solution.  This is often called a
-<em>domain-specific language</em> (DSL) because it solves a particular
-domain problem.</p>
+language is an ideal solution.  This is often called a
+<em>domain-specific language</em> (DSL) because it solves a particular domain
+problem.</p>
 <p>To create the language, we&#8217;ll simply write a set of Python classes,
 and the constructor of each will add itself to a (static) master
 list. The common data and behavior will be factored into the base
 <p class="last">To run this program say <tt class="docutils literal"><span class="pre">python</span> <span class="pre">GreenHouseLanguage.py</span></tt> or
 <tt class="docutils literal"><span class="pre">jython</span> <span class="pre">GreenHouseLanguage.py</span></tt>.</p>
 </div>
-<p>The constructor of each derived class calls the base-class constructor, which
-adds the new object to the list. The <strong>run()</strong> function sorts the list, which
-automatically uses the <strong>__cmp__()</strong> method defined in <strong>Event</strong> to
-base comparisons on time only. In this example, it only prints out the list, but
-in the real system it would wait for the time of each event to come up and then
-run the event.</p>
+<p>The constructor of each derived class calls the base-class
+constructor, which adds the new object to the list. The <strong>run()</strong>
+function sorts the list, which automatically uses the <strong>__cmp__()</strong>
+method defined in <strong>Event</strong> to base comparisons on time only. In this
+example, it only prints out the list, but in the real system it would
+wait for the time of each event to come up and then run the event.</p>
 <p>The <strong>__main__</strong> section performs a simple test on the classes.</p>
 <p>The above file &#8211; which is an ordinary Python program &#8211; is now a
-module that can be included in another Python program.
-But instead of using it in an ordinary Python program,
-let&#8217;s use Jython, inside of Java. This turns out to be remarkably
-simple: you import some Jython classes, create a <strong>PythonInterpreter</strong>
-object, and cause the Python files to be loaded:</p>
+module that can be included in another Python program.  But instead of
+using it in an ordinary Python program, let&#8217;s use Jython, inside of
+Java. This turns out to be remarkably simple: you import some Jython
+classes, create a <strong>PythonInterpreter</strong> object, and cause the Python
+files to be loaded:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/GreenHouseController.java</span>
 <span class="k">import</span> <span class="nn">org.python.core.*</span><span class="o">;</span>
 <span class="k">import</span> <span class="nn">org.python.util.PythonInterpreter</span><span class="o">;</span>
 <span class="o">}</span>
 </pre></div>
 </div>
-<p>The <strong>PythonInterpreter</strong> object is a complete Python interpreter that accepts
-commands from the Java program. One of these commands is <strong>execfile()</strong>, which
-tells it to execute all the statements it finds in a particular file. By
-executing <strong>GreenHouseLanguage.py</strong>, all the classes from that file are loaded
-into our <strong>PythonInterpreter</strong> object, and so it now &#8220;holds&#8221; the greenhouse
-controller language. The <strong>Schedule.ghs</strong> file is the one created by the end
-user to control the greenhouse. Here&#8217;s an example:</p>
+<p>The <strong>PythonInterpreter</strong> object is a complete Python interpreter that
+accepts commands from the Java program. One of these commands is
+<strong>execfile()</strong>, which tells it to execute all the statements it finds
+in a particular file. By executing <strong>GreenHouseLanguage.py</strong>, all the
+classes from that file are loaded into our <strong>PythonInterpreter</strong>
+object, and so it now &#8220;holds&#8221; the greenhouse controller language. The
+<strong>Schedule.ghs</strong> file is the one created by the end user to control
+the greenhouse. Here&#8217;s an example:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="c"># Jython/Schedule.ghs</span>
 <span class="n">Bell</span><span class="p">(</span><span class="mf">7.00</span><span class="p">)</span>
 <span class="n">ThermostatDay</span><span class="p">(</span><span class="mf">6.00</span><span class="p">)</span>
 <span class="n">WaterOff</span><span class="p">(</span><span class="mf">4.45</span><span class="p">)</span>
 </pre></div>
 </div>
-<p>This is the goal of the interpreter design pattern: to make the configuration of
-your program as simple as possible for the end user. With Jython you can achieve
-this with almost no effort at all.</p>
+<p>This is the goal of the interpreter design pattern: to make the
+configuration of your program as simple as possible for the end
+user. With Jython you can achieve this with almost no effort at all.</p>
 <p>One of the other methods available to the <strong>PythonInterpreter</strong> is
 <strong>exec()</strong>, which allows you to send a command to the interpreter. In
 the above program, the <strong>run()</strong> function is called using <strong>exec()</strong>.</p>
 </div>
+</div>
 <div class="section" id="using-java-libraries">
 <h2>Using Java libraries<a class="headerlink" href="#using-java-libraries" title="Permalink to this headline">¶</a></h2>
-<p>Jython wraps the Java libraries so that any of them can be used directly or via
-inheritance. In addition, Python shorthand simplifies coding.</p>
-<p>As an example, consider the <strong>HTMLButton.java</strong> example from
-<em>Thinking in Java</em>. Here is its conversion to Jython:</p>
+<p>Jython wraps Java libraries so that any of them can be used directly
+or via inheritance. In addition, Python shorthand simplifies coding.</p>
+<p>As an example, consider the <strong>HTMLButton.java</strong> example from <em>Thinking
+in Java</em>. Here is its conversion to Jython:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="c"># Jython/PythonSwing.py</span>
 <span class="c"># The HTMLButton.java example from &quot;Thinking in Java&quot;</span>
 <span class="c"># converted into Jython.</span>
 </pre></div>
 </div>
 <p>If you compare the Java version of the program to the above Jython
-implementation, you&#8217;ll see that Jython is shorter and generally easier to
-understand. For example, to set up the frame in the Java version you had to make
-several calls: the constructor for <strong>JFrame()</strong>, the <strong>setVisible()</strong> method
-and the <strong>setDefaultCloseOperation()</strong> method, whereas in the above code all
-three of these operations are performed with a single constructor call.</p>
-<p>Also notice that the <strong>JButton</strong> is configured with an <strong>actionListener()</strong>
-method inside the constructor, with the assignment to <strong>kapow</strong>. In addition,
-Jython&#8217;s JavaBean awareness means that a call to any method with a name that
-begins with &#8220;<strong>set</strong>&#8221; can be replaced with an assignment, as you see above.</p>
-<p>The only method that did not come over from Java is the <strong>pack()</strong> method,
-which seems to be essential in order to force the layout to happen properly.
-It&#8217;s also important that the call to <strong>pack()</strong> appear <em>before</em> the <strong>size</strong>
-setting.</p>
+implementation, you&#8217;ll see that Jython is shorter and generally easier
+to understand. For example, to set up the frame in the Java version
+you had to make several calls: the constructor for <strong>JFrame()</strong>, the
+<strong>setVisible()</strong> method and the <strong>setDefaultCloseOperation()</strong> method,
+whereas in the above code all three of these operations are performed
+with a single constructor call.</p>
+<p>Also notice that the <strong>JButton</strong> is configured with an
+<strong>actionListener()</strong> method inside the constructor, with the
+assignment to <strong>kapow</strong>. In addition, Jython&#8217;s JavaBean awareness
+means that a call to any method with a name that begins with &#8220;<strong>set</strong>&#8221;
+can be replaced with an assignment, as you see above.</p>
+<p>The only method that did not come over from Java is the <strong>pack()</strong>
+method, which seems to be essential in order to force the layout to
+happen properly.  It&#8217;s also important that the call to <strong>pack()</strong>
+appear <em>before</em> the <strong>size</strong> setting.</p>
 <div class="section" id="inheriting-from-java-library-classes">
 <h3>Inheriting from Java library Classes<a class="headerlink" href="#inheriting-from-java-library-classes" title="Permalink to this headline">¶</a></h3>
 <p>You can easily inherit from standard Java library classes in
 <span class="n">frame</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
 </pre></div>
 </div>
-<p><strong>MyDialog</strong> is inherited from <strong>JDialog</strong>, and you can see named arguments
-being used in the call to the base-class constructor.</p>
-<p>In the creation of the &#8220;OK&#8221; <strong>JButton</strong>, note that the <strong>actionPerformed</strong>
-method is set right inside the constructor, and that the function is created
-using the Python <strong>lambda</strong> keyword. This creates a nameless function with the
-arguments appearing before the colon and the expression that generates the
-returned value after the colon. As you should know, the Java prototype for the
-<strong>actionPerformed()</strong> method only contains a single argument, but the lambda
-expression indicates two. However, the second argument is provided with a
-default value, so the function <em>can</em> be called with only one argument. The
-reason for the second argument is seen in the default value, because this is a
-way to pass <strong>self</strong> into the lambda expression, so that it can be used to
-dispose of the dialog.</p>
-<p>Compare this code with the version that&#8217;s published in <em>Thinking in Java</em>.
-You&#8217;ll find that Python language features allow a much more succinct and direct
-implementation.</p>
+<p><strong>MyDialog</strong> is inherited from <strong>JDialog</strong>, and you can see named
+arguments being used in the call to the base-class constructor.</p>
+<p>In the creation of the &#8220;OK&#8221; <strong>JButton</strong>, note that the
+<strong>actionPerformed</strong> method is set right inside the constructor, and
+that the function is created using the Python <strong>lambda</strong> keyword. This
+creates a nameless function with the arguments appearing before the
+colon and the expression that generates the returned value after the
+colon. As you should know, the Java prototype for the
+<strong>actionPerformed()</strong> method only contains a single argument, but the
+lambda expression indicates two. However, the second argument is
+provided with a default value, so the function <em>can</em> be called with
+only one argument. The reason for the second argument is seen in the
+default value, because this is a way to pass <strong>self</strong> into the lambda
+expression, so that it can be used to dispose of the dialog.</p>
+<p>Compare this code with the version that&#8217;s published in <em>Thinking in
+Java</em>.  You&#8217;ll find that Python language features allow a much more
+succinct and direct implementation.</p>
 </div>
 </div>
 <div class="section" id="controlling-java-from-jython">
 <span class="k">print</span><span class="p">(</span><span class="n">jc</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
 </pre></div>
 </div>
-<div class="admonition-todo admonition " id="todo-20">
+<div class="admonition-todo admonition " id="todo-25">
 <p class="first admonition-title">Todo</p>
 <p class="last">rewrite to distinguish python generator from above description, or
 choose different name.</p>
 </div>
-<p>Note that the <strong>import</strong> statements map to the Java package structure exactly as
-you would expect. In the first example, a <strong>Date()</strong> object is created as if it
-were a native Python class, and printing this object just calls <strong>toString()</strong>.</p>
-<p><strong>ValGen</strong> implements the concept of a &#8220;generator&#8221; which is used a great deal in
-the C++ STL (<em>Standard Template Library</em>, part of the Standard C++ Library). A
-generator is an object that produces a new object every time its &#8220;generation
-method&#8221; is called, and it is quite convenient for filling containers. Here, I
-wanted to use it in a <strong>for</strong> iteration, and so I needed the generation method
-to be the one that is called by the iteration process. This is a special method
-called <strong>__getitem__()</strong>, which is actually the overloaded operator for
-indexing, &#8216;<strong>[ ]</strong>&#8216;. A <strong>for</strong> loop calls this method every time it wants to
-move the iteration forward, and when the elements run out, <strong>__getitem__()</strong>
-throws an out-of-bounds exception and that signals the end of the <strong>for</strong> loop
-(in other languages, you would never use an exception for ordinary control flow,
-but in Python it seems to work quite well). This exception happens automatically
-when <strong>self.val[i]</strong> runs out of elements, so the <strong>__getitem__()</strong> code turns
-out to be simple. The only complexity is that <strong>__getitem__()</strong> appears to
-return <em>two</em> objects instead of just one. What Python does is automatically
-package multiple return values into a tuple, so you still only end up returning
-a single object (in C++ or Java you would have to create your own data structure
-to accomplish this). In addition, in the <strong>for</strong> loop where <strong>ValGen</strong> is used,
-Python automatically &#8220;unpacks&#8221; the tuple so that you can have multiple iterators
-in the <strong>for</strong>. These are the kinds of syntax simplifications that make Python
-so endearing.</p>
-<p>The <strong>jmap</strong> and <strong>jset</strong> objects are instances of Java&#8217;s <strong>HashMap</strong> and
-<strong>HashSet</strong>, again created as if those classes were just native Python
-components. In the <strong>for</strong> loop, the <strong>put()</strong> and <strong>add()</strong> methods work just
-like they do in Java. Also, indexing into a Java <strong>Map</strong> uses the same notation
-as for dictionaries, but note that to iterate through the keys in a <strong>Map</strong> you
-must use the <strong>Map</strong> method <strong>keySet()</strong> rather than the Python dictionary
-method <strong>keys()</strong>.</p>
-<p>The final part of the example shows the use of a Java class that I created from
-scratch, to demonstrate how trivial it is. Notice also that Jython intuitively
-understands JavaBeans properties, since you can either use the <strong>getVal()</strong> and
-<strong>setVal()</strong> methods, or assign to and read from the equivalent <strong>val</strong>
-property. Also, <strong>getChars()</strong> returns a <strong>Character[]</strong> in Java, and this
-automatically becomes an array in Python.</p>
-<p>The easiest way to use Java classes that you create for use inside a Python
-program is to put them inside a package. Although Jython can also import
-unpackaged java classes (<strong>import JavaClass</strong>), all such unpackaged java classes
-will be treated as if they were defined in different packages so they can only
-see each other&#8217;s public methods.</p>
-<p>Java packages translate into Jython modules, and Jython must import a module in
-order to be able to use the Java class. Here is the Java code for <strong>JavaClass</strong>:</p>
+<p>Note that the <strong>import</strong> statements map to the Java package structure
+exactly as you would expect. In the first example, a <strong>Date()</strong> object
+is created as if it were a native Python class, and printing this
+object just calls <strong>toString()</strong>.</p>
+<p><strong>ValGen</strong> implements the concept of a &#8220;generator&#8221; which is used a
+great deal in the C++ STL (<em>Standard Template Library</em>, part of the
+Standard C++ Library). A generator is an object that produces a new
+object every time its &#8220;generation method&#8221; is called, and it is quite
+convenient for filling containers. Here, I wanted to use it in a
+<strong>for</strong> iteration, and so I needed the generation method to be the one
+that is called by the iteration process. This is a special method
+called <strong>__getitem__()</strong>, which is actually the overloaded operator
+for indexing, &#8216;<strong>[ ]</strong>&#8216;. A <strong>for</strong> loop calls this method every time
+it wants to move the iteration forward, and when the elements run out,
+<strong>__getitem__()</strong> throws an out-of-bounds exception and that signals
+the end of the <strong>for</strong> loop (in other languages, you would never use
+an exception for ordinary control flow, but in Python it seems to work
+quite well). This exception happens automatically when <strong>self.val[i]</strong>
+runs out of elements, so the <strong>__getitem__()</strong> code turns out to be
+simple. The only complexity is that <strong>__getitem__()</strong> appears to
+return <em>two</em> objects instead of just one. What Python does is
+automatically package multiple return values into a tuple, so you
+still only end up returning a single object (in C++ or Java you would
+have to create your own data structure to accomplish this). In
+addition, in the <strong>for</strong> loop where <strong>ValGen</strong> is used, Python
+automatically &#8220;unpacks&#8221; the tuple so that you can have multiple
+iterators in the <strong>for</strong>. These are the kinds of syntax
+simplifications that make Python so endearing.</p>
+<p>The <strong>jmap</strong> and <strong>jset</strong> objects are instances of Java&#8217;s <strong>HashMap</strong>
+and <strong>HashSet</strong>, again created as if those classes were just native
+Python components. In the <strong>for</strong> loop, the <strong>put()</strong> and <strong>add()</strong>
+methods work just like they do in Java. Also, indexing into a Java
+<strong>Map</strong> uses the same notation as for dictionaries, but note that to
+iterate through the keys in a <strong>Map</strong> you must use the <strong>Map</strong> method
+<strong>keySet()</strong> rather than the Python dictionary method <strong>keys()</strong>.</p>
+<p>The final part of the example shows the use of a Java class that I
+created from scratch, to demonstrate how trivial it is. Notice also
+that Jython intuitively understands JavaBeans properties, since you
+can either use the <strong>getVal()</strong> and <strong>setVal()</strong> methods, or assign to
+and read from the equivalent <strong>val</strong> property. Also, <strong>getChars()</strong>
+returns a <strong>Character[]</strong> in Java, and this automatically becomes an
+array in Python.</p>
+<p>The easiest way to use Java classes that you create for use inside a
+Python program is to put them inside a package. Although Jython can
+also import unpackaged java classes (<strong>import JavaClass</strong>), all such
+unpackaged java classes will be treated as if they were defined in
+different packages so they can only see each other&#8217;s public methods.</p>
+<p>Java packages translate into Jython modules, and Jython must import a
+module in order to be able to use the Java class. Here is the Java
+code for <strong>JavaClass</strong>:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/javaclass/JavaClass.java</span>
 <span class="k">package</span> <span class="n">Jython</span><span class="o">.</span><span class="na">javaclass</span><span class="o">;</span>
 <span class="k">import</span> <span class="nn">java.util.*</span><span class="o">;</span>
 <span class="o">}</span>
 </pre></div>
 </div>
-<p>You can see that this is just an ordinary Java class, without any awareness that
-it will be used in a Jython program. For this reason, one of the important uses
-of Jython is in testing Java code <a class="footnote-reference" href="#id4" id="id2">[2]</a>. Because Python is such a powerful,
-flexible, dynamic language it is an ideal tool for automated test frameworks,
-without making any changes to the Java code that&#8217;s being tested.</p>
+<p>You can see that this is just an ordinary Java class, without any
+awareness that it will be used in a Jython program. For this reason,
+one of the important uses of Jython is in testing Java code
+<a class="footnote-reference" href="#id4" id="id2">[2]</a>. Because Python is such a powerful, flexible, dynamic language it
+is an ideal tool for automated test frameworks, without making any
+changes to the Java code that&#8217;s being tested.</p>
 <div class="section" id="inner-classes">
 <h3>Inner Classes<a class="headerlink" href="#inner-classes" title="Permalink to this headline">¶</a></h3>
-<p>Inner classes becomes attributes on the class object. Instances of <strong>static</strong>
-inner classes can be created with the usual call:</p>
+<p>Inner classes becomes attributes on the class object. Instances of
+<strong>static</strong> inner classes can be created with the usual call:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="n">com</span><span class="o">.</span><span class="n">foo</span><span class="o">.</span><span class="n">JavaClass</span><span class="o">.</span><span class="n">StaticInnerClass</span><span class="p">()</span>
 </pre></div>
 </div>
-<p>Non-<strong>static</strong> inner classes must have an outer class instance supplied
-explicitly as the first argument:</p>
+<p>Non-<strong>static</strong> inner classes must have an outer class instance
+supplied explicitly as the first argument:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="n">com</span><span class="o">.</span><span class="n">foo</span><span class="o">.</span><span class="n">JavaClass</span><span class="o">.</span><span class="n">InnerClass</span><span class="p">(</span><span class="n">com</span><span class="o">.</span><span class="n">foo</span><span class="o">.</span><span class="n">JavaClass</span><span class="p">())</span>
 </pre></div>
 </div>
 </div>
 <div class="section" id="controlling-the-interpreter">
 <h2>Controlling the Interpreter<a class="headerlink" href="#controlling-the-interpreter" title="Permalink to this headline">¶</a></h2>
-<p>In the rest of this chapter, we shall look at more sophisticated ways to
-interact with Jython. The simplest way to exercise more control over the
-<strong>PythonInterpreter</strong> object from within Java is to send data to the
-interpreter, and pull data back out.</p>
+<p>In the rest of this chapter, we shall look at more sophisticated ways
+to interact with Jython. The simplest way to exercise more control
+over the <strong>PythonInterpreter</strong> object from within Java is to send data
+to the interpreter, and pull data back out.</p>
 <div class="section" id="putting-data-in">
 <h3>Putting Data In<a class="headerlink" href="#putting-data-in" title="Permalink to this headline">¶</a></h3>
-<p>To inject data into your Python program, the <strong>PythonInterpreter</strong> class has a
-deceptively simple method: <strong>set()</strong>. However, <strong>set()</strong> takes many different
-data types and performs conversions upon them.  The following example is a
-reasonably thorough exercise of the various <strong>set()</strong> possibilities, along with
-comments that should give a fairly complete explanation:</p>
+<p>To inject data into your Python program, the <strong>PythonInterpreter</strong>
+class has a deceptively simple method: <strong>set()</strong>. However, <strong>set()</strong>
+takes many different data types and performs conversions upon them.
+The following example is a reasonably thorough exercise of the various
+<strong>set()</strong> possibilities, along with comments that should give a fairly
+complete explanation:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/PythonInterpreterSetting.java</span>
 <span class="c">// Passing data from Java to python when using</span>
 <span class="c">// the PythonInterpreter object.</span>
 <span class="o">}</span>
 </pre></div>
 </div>
-<p>As usual with Java, the distinction between real objects and primitive types
-causes trouble. In general, if you pass a regular object to <strong>set()</strong>, it knows
-what to do with it, but if you want to pass in a primitive you must perform a
-conversion. One way to do this is to create a &#8220;Py&#8221; type, such as <strong>PyInteger</strong>
-or <strong>PyFloat</strong>. but it turns out you can also use Java&#8217;s own object wrappers
-like <strong>Integer</strong> and <strong>Float</strong>, which is probably going to be a lot easier to
-remember.</p>
-<p>Early in the program you&#8217;ll see an <strong>exec()</strong> containing the Python statement:</p>
+<p>As usual with Java, the distinction between real objects and primitive
+types causes trouble. In general, if you pass a regular object to
+<strong>set()</strong>, it knows what to do with it, but if you want to pass in a
+primitive you must perform a conversion. One way to do this is to
+create a &#8220;Py&#8221; type, such as <strong>PyInteger</strong> or <strong>PyFloat</strong>. but it turns
+out you can also use Java&#8217;s own object wrappers like <strong>Integer</strong> and
+<strong>Float</strong>, which is probably going to be a lot easier to remember.</p>
+<p>Early in the program you&#8217;ll see an <strong>exec()</strong> containing the Python
+statement:</p>
 <div class="highlight-python"><div class="highlight"><pre><span class="k">print</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mf">5</span><span class="p">:])</span>
 </pre></div>
 </div>
-<p>The colon inside the indexing statement indicates a Python <em>slice</em>, which
-produces a range of elements from the original array. In this case, it produces
-an array containing the elements from number 5 until the end of the array. You
-could also say &#8216;<strong>a[3:5]</strong>&#8216; to produce elements 3 through 5, or &#8216;<strong>a[:5]</strong>&#8216; to
-produce the elements zero through 5. The reason a slice is used in this
-statement is to make sure that the Java <strong>String</strong> has really been converted to
-a Python string, which can also be treated as an array of characters.</p>
-<p>You can see that it&#8217;s possible, using <strong>exec()</strong>, to create a Python function
-(although it&#8217;s a bit awkward). The <strong>prt()</strong> function prints the whole array,
-and then (to make sure it&#8217;s a real Python array), iterates through each element
-of the array and prints it. Finally, it prints the class of the array, so we can
-see what conversion has taken place (Python not only has run-time type
-information, it also has the equivalent of Java reflection). The <strong>prt()</strong>
-function is used to print arrays that come from each of the Java primitive
-types.</p>
-<p>Although a Java <strong>ArrayList</strong> does pass into the interpreter using <strong>set()</strong>,
-and you can index into it as if it were an array, trying to create a slice
-fails. To completely convert it into an array, one approach is to simply extract
-a Java array using <strong>toArray()</strong>, and pass that in. The <strong>set()</strong> method
-converts it to a <strong>PyArray</strong> &#8211; one of the classes provided with Jython &#8211; which
-can be treated as a Python array (you can also explicitly create a <strong>PyArray</strong>,
-but this seems unnecessary).</p>
-<p>Finally, a <strong>Map</strong> is created and passed directly into the interpreter. While it
-is possible to do simple things like index into the resulting object, it&#8217;s not a
-real Python dictionary so you can&#8217;t (for example) call the <strong>keys()</strong> method.
-There is no straightforward way to convert a Java <strong>Map</strong> into a Python
-dictionary, and so I wrote a utility called <strong>toPyDictionary()</strong> and made it a
-<strong>static</strong> method of <strong>net.mindview.python.PyUtil</strong>. This also includes
-utilities to extract a Python array into a Java <strong>List</strong>, and a Python
-dictionary into a Java <strong>Map</strong>:</p>
+<p>The colon inside the indexing statement indicates a Python <em>slice</em>,
+which produces a range of elements from the original array. In this
+case, it produces an array containing the elements from number 5 until
+the end of the array. You could also say &#8216;<strong>a[3:5]</strong>&#8216; to produce
+elements 3 through 5, or &#8216;<strong>a[:5]</strong>&#8216; to produce the elements zero
+through 5. The reason a slice is used in this statement is to make
+sure that the Java <strong>String</strong> has really been converted to a Python
+string, which can also be treated as an array of characters.</p>
+<p>You can see that it&#8217;s possible, using <strong>exec()</strong>, to create a Python
+function (although it&#8217;s a bit awkward). The <strong>prt()</strong> function prints
+the whole array, and then (to make sure it&#8217;s a real Python array),
+iterates through each element of the array and prints it. Finally, it
+prints the class of the array, so we can see what conversion has taken
+place (Python not only has run-time type information, it also has the
+equivalent of Java reflection). The <strong>prt()</strong> function is used to
+print arrays that come from each of the Java primitive types.</p>
+<p>Although a Java <strong>ArrayList</strong> does pass into the interpreter using
+<strong>set()</strong>, and you can index into it as if it were an array, trying to
+create a slice fails. To completely convert it into an array, one
+approach is to simply extract a Java array using <strong>toArray()</strong>, and
+pass that in. The <strong>set()</strong> method converts it to a <strong>PyArray</strong> &#8211; one
+of the classes provided with Jython &#8211; which can be treated as a
+Python array (you can also explicitly create a <strong>PyArray</strong>, but this
+seems unnecessary).</p>
+<p>Finally, a <strong>Map</strong> is created and passed directly into the
+interpreter. While it is possible to do simple things like index into
+the resulting object, it&#8217;s not a real Python dictionary so you can&#8217;t
+(for example) call the <strong>keys()</strong> method.  There is no straightforward
+way to convert a Java <strong>Map</strong> into a Python dictionary, and so I wrote
+a utility called <strong>toPyDictionary()</strong> and made it a <strong>static</strong> method
+of <strong>net.mindview.python.PyUtil</strong>. This also includes utilities to
+extract a Python array into a Java <strong>List</strong>, and a Python dictionary
+into a Java <strong>Map</strong>:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/PyUtil.java</span>
 <span class="c">// PythonInterpreter utilities</span>
 <span class="k">import</span> <span class="nn">org.python.util.PythonInterpreter</span><span class="o">;</span>
 <div class="section" id="getting-data-out">
 <h3>Getting Data Out<a class="headerlink" href="#getting-data-out" title="Permalink to this headline">¶</a></h3>
 <p>There are a number of different ways to extract data from the
-<strong>PythonInterpreter</strong>. If you simply call the <strong>get()</strong> method, passing it the
-object identifier as a string, it returns a <strong>PyObject</strong> (part of the
-<strong>org.python.core</strong> support classes). It&#8217;s possible to &#8220;cast&#8221; it using the
-<strong>__tojava__()</strong> method, but there are better alternatives:</p>
+<strong>PythonInterpreter</strong>. If you simply call the <strong>get()</strong> method,
+passing it the object identifier as a string, it returns a
+<strong>PyObject</strong> (part of the <strong>org.python.core</strong> support classes). It&#8217;s
+possible to &#8220;cast&#8221; it using the <strong>__tojava__()</strong> method, but there are
+better alternatives:</p>
 <ol class="arabic simple">
-<li>The convenience methods in the <strong>Py</strong> class, such as <strong>py2int()</strong>, take a
-<strong>PyObject</strong> and convert it to a number of different types.</li>
-<li>An overloaded version of <strong>get()</strong> takes the desired Java <strong>Class</strong> object
-as a second argument, and produces an object that has that run-time type (so you
-still need to perform a cast on the result in your Java code).</li>
+<li>The convenience methods in the <strong>Py</strong> class, such as <strong>py2int()</strong>,
+take a <strong>PyObject</strong> and convert it to a number of different types.</li>
+<li>An overloaded version of <strong>get()</strong> takes the desired Java
+<strong>Class</strong> object as a second argument, and produces an object that
+has that run-time type (so you still need to perform a cast on the
+result in your Java code).</li>
 </ol>
-<p>Using the second approach, getting an array from the <strong>PythonInterpreter</strong> is
-quite easy. This is especially useful because Python is exceptionally good at
-manipulating strings and files, and so you will commonly want to extract the
-results as an array of strings. For example, you can do a wildcard expansion of
-file names using Python&#8217;s <strong>glob()</strong>, as shown further down in the following
+<p>Using the second approach, getting an array from the
+<strong>PythonInterpreter</strong> is quite easy. This is especially useful because
+Python is exceptionally good at manipulating strings and files, and so
+you will commonly want to extract the results as an array of
+strings. For example, you can do a wildcard expansion of file names
+using Python&#8217;s <strong>glob()</strong>, as shown further down in the following
 code:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/PythonInterpreterGetting.java</span>
 <span class="c">// Getting data from the PythonInterpreter object.</span>
 <span class="o">}</span>
 </pre></div>
 </div>
-<p>The last two examples show the extraction of Python tuples and lists into Java
-<strong>List</strong>s, and Python dictionaries into Java <strong>Map</strong>s. Both of these cases
-require more processing than is provided in the standard Jython library, so I
-have again created utilities in <strong>net.mindview.pyton.PyUtil</strong>: <strong>toList()</strong> to
-produce a <strong>List</strong> from a Python sequence, and <strong>toMap()</strong> to produce a <strong>Map</strong>
-from a Python dictionary. The <strong>PyUtil</strong> methods make it easier to take
-important data structures back and forth between Java and Python.</p>
+<p>The last two examples show the extraction of Python tuples and lists
+into Java <strong>List</strong>s, and Python dictionaries into Java
+<strong>Map</strong>s. Both of these cases require more processing than is
+provided in the standard Jython library, so I have again created
+utilities in <strong>net.mindview.pyton.PyUtil</strong>: <strong>toList()</strong> to produce a
+<strong>List</strong> from a Python sequence, and <strong>toMap()</strong> to produce a <strong>Map</strong>
+from a Python dictionary. The <strong>PyUtil</strong> methods make it easier to
+take important data structures back and forth between Java and Python.</p>
 </div>
 <div class="section" id="multiple-interpreters">
 <h3>Multiple Interpreters<a class="headerlink" href="#multiple-interpreters" title="Permalink to this headline">¶</a></h3>
-<p>It&#8217;s also worth noting that you can have multiple <strong>PythonInterpreter</strong> objects
-in a program, and each one has its own name space:</p>
+<p>It&#8217;s also worth noting that you can have multiple
+<strong>PythonInterpreter</strong> objects in a program, and each one has its own
+name space:</p>
 <div class="highlight-java"><div class="highlight"><pre><span class="c">// Jython/MultipleJythons.java</span>
 <span class="c">// You can run multiple interpreters, each</span>
 <span class="c">// with its own name space.</span>
 <span class="o">}</span>
 </pre></div>
 </div>
-<p>When you run the program you&#8217;ll see that the value of <strong>a</strong> is distinct within
-each <strong>PythonInterpreter</strong>.</p>
+<p>When you run the program you&#8217;ll see that the value of <strong>a</strong> is
+distinct within each <strong>PythonInterpreter</strong>.</p>
 </div>
 </div>
 <div class="section" id="creating-java-classes-with-jython">
 code. This can produce very useful results, as you are then able to
 treat the results as if they are native Java classes, albeit with
 Python power under the hood.</p>
-<p>To produce Java classes from Python code, Jython comes with a compiler called
-<strong>jythonc</strong>.</p>
+<p>To produce Java classes from Python code, Jython comes with a compiler
+called <strong>jythonc</strong>.</p>
 <p>The process of creating Python classes that will produce Java classes
 is a bit more complex than when calling Java classes from Python,
 because the methods in Java classes are statically typed, while Python
     <span class="s">&quot;@sig public java.lang.String[] returnArray()&quot;</span>
 </pre></div>
 </div>
-<p>The Python definition doesn&#8217;t specify any return type, but the &#64;sig string gives
-the full type information about what is being passed and returned. The
-<strong>jythonc</strong> compiler uses this information to generate the correct Java code.</p>
-<p>There&#8217;s one other set of rules you must follow in order to get a successful
-compilation: you must inherit from a Java class or interface in your Python
-class (you do not need to specify the <strong>&#64;sig</strong> signature for methods defined in
-the superclass/interface). If you do not do this, you won&#8217;t get your desired
-methods &#8211; unfortunately, <strong>jythonc</strong> gives you no warnings or errors in this
-case, but you won&#8217;t get what you want. If you don&#8217;t see what&#8217;s missing, it can
-be very frustrating.</p>
-<p>In addition, you must import the appropriate java class and give the correct
-package specification.  In the example below, <strong>java</strong> is imported so you must
-inherit from <strong>java.lang.Object</strong>, but you could also say <strong>from java.lang
-import Object</strong> and then you&#8217;d just inherit from <strong>Object</strong> without the package
-specification. Unfortunately, you don&#8217;t get any warnings or errors if you get
-this wrong, so you must be patient and keep trying.</p>
-<p>Here is an example of a Python class created to produce a Java class. This also
-introduces the &#8216;<strong>=T</strong>&#8216; directive for the makefile builder tool, which specifies
-a different target than the one that is normally used by the tool. In this case,
-the Python file is used to build a Java <strong>.class</strong> file, so the class file is
-the desired target:</p>
+<p>The Python definition doesn&#8217;t specify any return type, but the &#64;sig
+string gives the full type information about what is being passed and
+returned. The <strong>jythonc</strong> compiler uses this information to generate
+the correct Java code.</p>
+<p>There&#8217;s one other set of rules you must follow in order to get a
+successful compilation: you must inherit from a Java class or
+interface in your Python class (you do not need to specify the
+<strong>&#64;sig</strong> signature for methods defined in the
+superclass/interface). If you do not do this, you won&#8217;t get your
+desired methods &#8211; unfortunately, <strong>jythonc</strong> gives you no warnings or
+errors in this case, but you won&#8217;t get what you want. If you don&#8217;t see
+what&#8217;s missing, it can be very frustrating.</p>
+<p>In addition, you must import the appropriate java class and give the
+correct package specification.  In the example below, <strong>java</strong> is
+imported so you must inherit from <strong>java.lang.Object</strong>, but you could
+also say <strong>from java.lang import Object</strong> and then you&#8217;d just inherit
+from <strong>Object</strong> without the package specification. Unfortunately, you
+don&#8217;t get any warnings or errors if you get this wrong, so you must be
+patient and keep trying.</p>
+<p>Here is an example of a Python class created to produce a Java
+class. In this case, the Python file is used to build a Java
+<strong>.class</strong> file, so the class file is the desired target:</p>
 <div class="highlight-python"><pre># Jython/PythonToJavaClass.py
 # A Python class converted into a Java class
 # Compile with:
         for x in m.keys():
             print(x, m[x])</pre>
 </div>
-<p>First note that <strong>PythonToJavaClass</strong> is inherited from <strong>java.lang.Object</strong>; if
-you don&#8217;t do this you will quietly get a Java class without the right
-signatures. You are not required to inherit from <strong>Object</strong>; any other Java
-class will do.</p>
-<p>This class is designed to demonstrate different  arguments and return values, to
-provide you with enough examples that you&#8217;ll be able to easily create your own
-signature strings. The first three of these are fairly self-explanatory, but
-note the full qualification of the Java name in the signature string.</p>
-<p>In <strong>returnArray()</strong>, a Python array must be returned as a Java array. To do
-this, the Jython <strong>array()</strong> function (from the <strong>jarray</strong> module) must be
-used, along with the type of the class for the resulting array. Any time you
-need to return an array to Java, you must use <strong>array()</strong>, as seen in the
-methods <strong>ints()</strong> and <strong>doubles()</strong>.</p>
-<p>The last methods show how to pass arguments in from Java. Basic types happen
-automatically as long as you specify them in the <strong>&#64;sig</strong> string, but you must
-use objects and you cannot pass in primitives (that is, primitives must be
-ensconced in wrapper objects, such as <strong>Integer</strong>).</p>
-<p>In <strong>argIn3()</strong>, you can see that a Java <strong>List</strong> is transparently converted to
-something that behaves just like a Python array, but is not a true array because
-you cannot take a slice from it. If you want a true Python array, then you must
-create and pass a <strong>PyArray</strong> as in <strong>argIn4()</strong>, where the slice is
-successful. Similarly, a Java <strong>Map</strong> must come in as a <strong>PyDictionary</strong> in
-order to be treated as a Python dictionary.</p>
+<p>First note that <strong>PythonToJavaClass</strong> is inherited from
+<strong>java.lang.Object</strong>; if you don&#8217;t do this you will quietly get a Java
+class without the right signatures. You are not required to inherit
+from <strong>Object</strong>; any other Java class will do.</p>
+<p>This class is designed to demonstrate different arguments and return
+values, to provide you with enough examples that you&#8217;ll be able to
+easily create your own signature strings. The first three of these are
+fairly self-explanatory, but note the full qualification of the Java
+name in the signature string.</p>
+<p>In <strong>returnArray()</strong>, a Python array must be returned as a Java
+array. To do this, the Jython <strong>array()</strong> function (from the
+<strong>jarray</strong> module) must be used, along with the type of the class for
+the resulting array. Any time you need to return an array to Java, you
+must use <strong>array()</strong>, as seen in the methods <strong>ints()</strong> and
+<strong>doubles()</strong>.</p>
+<p>The last methods show how to pass arguments in from Java. Basic types
+happen automatically as long as you specify them in the <strong>&#64;sig</strong>
+string, but you must use objects and you cannot pass in primitives
+(that is, primitives must be ensconced in wrapper objects, such as
+<strong>Integer</strong>).</p>
+<p>In <strong>argIn3()</strong>, you can see that a Java <strong>List</strong> is transparently
+converted to something that behaves just like a Python array, but is
+not a true array because you cannot take a slice from it. If you want
+a true Python array, then you must create and pass a <strong>PyArray</strong> as in
+<strong>argIn4()</strong>, where the slice is successful. Similarly, a Java <strong>Map</strong>
+must come in as a <strong>PyDictionary</strong> in order to be treated as a Python
+dictionary.</p>
 <p>Here is the Java program to exercise the Java classes produced by the
 above Python code. You can&#8217;t compile <strong>TestPythonToJavaClass.java</strong>
 until <strong>PythonToJavaClass.class</strong> is available:</p>
 </div>
 <p>For Python support, you&#8217;ll usually only need to import the classes in
 <strong>org.python.core</strong>. Everything else in the above example is fairly
-straightforward, as <strong>PythonToJavaClass</strong> appears, from the Java side, to be
-just another Java class. <strong>dumpClassInfo()</strong> uses reflection to verify that the
-method signatures specified in <strong>PythonToJavaClass.py</strong> have come through
-properly.</p>
+straightforward, as <strong>PythonToJavaClass</strong> appears, from the Java side,
+to be just another Java class. <strong>dumpClassInfo()</strong> uses reflection to
+verify that the method signatures specified in
+<strong>PythonToJavaClass.py</strong> have come through properly.</p>
 <div class="section" id="building-java-classes-from-python">
 <h3>Building Java Classes from Python<a class="headerlink" href="#building-java-classes-from-python" title="Permalink to this headline">¶</a></h3>
-<p>Part of the trick of creating Java classes from Python code is the &#64;sig
-information in the method documentation strings. But there&#8217;s a second problem
-which stems from the fact that Python has no &#8220;package&#8221; keyword &#8211; the Python
-equivalent of packages (modules) are implicitly created based on the file name.
-However, to bring the resulting class files into the Java program, <strong>jythonc</strong>
-must be given information about how to create the Java package for the Python
-code. This is done on the <strong>jythonc</strong> command line using the <strong>&#8211;package</strong> flag,
-followed by the package name you wish to produce (including the separation dots,
-just as you would give the package name using the <strong>package</strong> keyword in a Java
-program). This will put the resulting <strong>.class</strong> files in the appropriate
-subdirectory off of the current directory. Then you only need to import the
-package in your Java program, as shown above (you&#8217;ll need &#8216;<strong>.</strong>&#8216; in your
-CLASSPATH in order to run it from the code directory).</p>
-<p>Here are the <strong>make</strong> dependency rules that I used to build the above example
-(the backslashes at the ends of the lines are understood by <strong>make</strong> to be line
-continuations):</p>
+<p>Part of the trick of creating Java classes from Python code is the
+&#64;sig information in the method documentation strings. But there&#8217;s a
+second problem which stems from the fact that Python has no &#8220;package&#8221;
+keyword &#8211; the Python equivalent of packages (modules) are implicitly
+created based on the file name.  However, to bring the resulting class
+files into the Java program, <strong>jythonc</strong> must be given information
+about how to create the Java package for the Python code. This is done
+on the <strong>jythonc</strong> command line using the <strong>&#8211;package</strong> flag, followed
+by the package name you wish to produce (including the separation
+dots, just as you would give the package name using the <strong>package</strong>
+keyword in a Java program). This will put the resulting <strong>.class</strong>
+files in the appropriate subdirectory off of the current
+directory. Then you only need to import the package in your Java
+program, as shown above (you&#8217;ll need &#8216;<strong>.</strong>&#8216; in your CLASSPATH in
+order to run it from the code directory).</p>
+<p>Here are the <strong>make</strong> dependency rules that I used to build the above
+example (the backslashes at the ends of the lines are understood by
+<strong>make</strong> to be line continuations):</p>
 <div class="highlight-python"><pre>TestPythonToJavaClass.class: \\
         TestPythonToJavaClass.java \\
         python\java\test\PythonToJavaClass.class
     PythonToJavaClass.py</pre>
 </div>
 <p>The first target, <strong>TestPythonToJavaClass.class</strong>, depends on both
-<strong>TestPythonToJavaClass.java</strong> and the <strong>PythonToJavaClass.class</strong>, which is the
-Python code that&#8217;s converted to a class file. This latter, in turn, depends on
-the Python source code. Note that it&#8217;s important that the directory where the
-target lives be specified, so that the makefile will create the Java program
-with the minimum necessary amount of rebuilding.</p>
+<strong>TestPythonToJavaClass.java</strong> and the <strong>PythonToJavaClass.class</strong>,
+which is the Python code that&#8217;s converted to a class file. This
+latter, in turn, depends on the Python source code. Note that it&#8217;s
+important that the directory where the target lives be specified, so
+that the makefile will create the Java program with the minimum
+necessary amount of rebuilding.</p>
 </div>
 </div>
 <div class="section" id="summary">
 <h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
-<p>This chapter has arguably gone much deeper into Jython than required to use the
-interpreter design pattern. Indeed, once you decide that you need to use
-interpreter and that you&#8217;re not going to get lost inventing your own language,
-the solution of installing Jython is quite simple, and you can at least get
-started by following the <strong>GreenHouseController</strong> example.</p>
-<p>Of course, that example is often too simple and you may need something more
-sophisticated, often requiring more interesting data to be passed back and
-forth. When I encountered the limited documentation, I felt it necessary to come
-up with a more thorough examination of Jython.</p>
+<p>This chapter has arguably gone much deeper into Jython than required
+to use the interpreter design pattern. Indeed, once you decide that
+you need to use interpreter and that you&#8217;re not going to get lost
+inventing your own language, the solution of installing Jython is
+quite simple, and you can at least get started by following the
+<strong>GreenHouseController</strong> example.</p>
+<p>Of course, that example is often too simple and you may need something
+more sophisticated, often requiring more interesting data to be passed
+back and forth. When I encountered the limited documentation, I felt
+it necessary to come up with a more thorough examination of Jython.</p>
 <p>In the process, note that there could be another equally powerful
 design pattern lurking in here, which could perhaps be called
 <em>multiple languages</em> or <em>language hybridizing</em>. This is based on the
 much faster than with either language by itself. CORBA is another way
 to bridge across languages, and at the same time bridging between
 computers and operating systems.</p>
-<p>To me, Python and Java present a very potent combination for program development
-because of Java&#8217;s architecture and tool set, and Python&#8217;s extremely rapid
-development (generally considered to be 5-10 times faster than C++ or Java).
-Python is usually slower, however, but even if you end up re-coding parts of
-your program for speed, the initial fast development will allow you to more
-quickly flesh out the system and uncover and solve the critical sections. And
-often, the execution speed of Python is not a problem &#8211; in those cases it&#8217;s an
-even bigger win. A number of commercial products already use Java and Jython,
-and because of the terrific productivity leverage I expect to see this happen
-more in the future.</p>
+<p>To me, Python and Java present a very potent combination for program
+development because of Java&#8217;s architecture and tool set, and Python&#8217;s
+extremely rapid development (generally considered to be 5-10 times
+faster than C++ or Java).  Python is usually slower, however, but even
+if you end up re-coding parts of your program for speed, the initial
+fast development will allow you to more quickly flesh out the system
+and uncover and solve the critical sections. And often, the execution
+speed of Python is not a problem &#8211; in those cases it&#8217;s an even bigger
+win. A number of commercial products already use Java and Jython, and
+because of the terrific productivity leverage I expect to see this
+happen more in the future.</p>
 </div>
 <div class="section" id="exercises">
 <h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this headline">¶</a></h2>
 <ol class="arabic simple">
-<li>Modify <strong>GreenHouseLanguage.py</strong> so that it checks the times for the events
-and runs those events at the appropriate times.</li>
-<li>Modify <strong>GreenHouseLanguage.py</strong> so that it calls a function for <strong>action</strong>
-instead of just printing a string.</li>
-<li>Create a Swing application with a <strong>JTextField</strong> (where the user will enter
-commands) and a <strong>JTextArea</strong> (where the command results will be displayed).
-Connect to a <strong>PythonInterpreter</strong> object so that the output will be sent to
-the <strong>JTextArea</strong> (which should scroll). You&#8217;ll need to locate the
-<strong>PythonInterpreter</strong> command that redirects the output to a Java stream.</li>
-<li>Modify <strong>GreenHouseLanguage.py</strong> to add a master controller class (instead
-of the static array inside <strong>Event</strong>) and provide a <strong>run()</strong> method for
-each of the subclasses. Each <strong>run()</strong> should create and use an object from
-the standard Java library during its execution. Modify
-<strong>GreenHouseController.java</strong> to use this new class.</li>
-<li>Modify the resulting <strong>GreenHouseLanguage.py</strong> from exercise two to produce
-Java classes (add the &#64;sig documentation strings to produce the correct Java
-signatures, and create a makefile to build the Java <strong>.class</strong> files). Write
-a Java program that uses these classes.</li>
-<li>Modify <strong>GreenHouseLanguage.py</strong> so that the subclasses of <strong>Event</strong> are not
-discrete classes, but are instead <em>generated</em> by a single function which creates
-the class and the associated string dynamically.</li>
+<li>Modify <strong>GreenHouseLanguage.py</strong> so that it checks the times for
+the events and runs those events at the appropriate times.</li>
+<li>Modify <strong>GreenHouseLanguage.py</strong> so that it calls a function for
+<strong>action</strong> instead of just printing a string.</li>
+<li>Create a Swing application with a <strong>JTextField</strong> (where the user
+will enter commands) and a <strong>JTextArea</strong> (where the command
+results will be displayed).  Connect to a <strong>PythonInterpreter</strong>
+object so that the output will be sent to the <strong>JTextArea</strong> (which
+should scroll). You&#8217;ll need to locate the <strong>PythonInterpreter</strong>
+command that redirects the output to a Java stream.</li>
+<li>Modify <strong>GreenHouseLanguage.py</strong> to add a master controller class
+(instead of the static array inside <strong>Event</strong>) and provide a
+<strong>run()</strong> method for each of the subclasses. Each <strong>run()</strong> should
+create and use an object from the standard Java library during its
+execution. Modify <strong>GreenHouseController.java</strong> to use this new
+class.</li>
+<li>Modify the resulting <strong>GreenHouseLanguage.py</strong> from exercise two
+to produce Java classes (add the &#64;sig documentation strings to
+produce the correct Java signatures, and create a makefile to
+build the Java <strong>.class</strong> files). Write a Java program that uses
+these classes.</li>
+<li>Modify <strong>GreenHouseLanguage.py</strong> so that the subclasses of
+<strong>Event</strong> are not discrete classes, but are instead <em>generated</em> by
+a single function which creates the class and the associated
+string dynamically.</li>
 </ol>
 <p class="rubric">Footnotes</p>
 <table class="docutils footnote" frame="void" id="id3" rules="none">
 <colgroup><col class="label" /><col /></colgroup>
 <tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>The original version of this was called <em>JPython</em>, but the project
-changed and the name was changed to emphasize the distinctness of the new
-version.</td></tr>
+<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>The original version of this was called <em>JPython</em>, but the
+project changed and the name was changed to emphasize the
+distinctness of the new version.</td></tr>
 </tbody>
 </table>
 <table class="docutils footnote" frame="void" id="id4" rules="none">
 <colgroup><col class="label" /><col /></colgroup>
 <tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Changing the registry setting <strong>python.security.respectJavaAccessibility
-= true</strong> to <strong>false</strong> makes testing even more powerful because it allows
-the test script to use <em>all</em> methods, even protected and package-
-private.</td></tr>
+<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Changing the registry setting
+<strong>python.security.respectJavaAccessibility = true</strong> to
+<strong>false</strong> makes testing even more powerful because it allows
+the test script to use <em>all</em> methods, even protected and
+package- private.</td></tr>
 </tbody>
 </table>
 </div>
             <h3><a href="index.html">Table Of Contents</a></h3>
             <ul>
 <li><a class="reference external" href="">Jython</a><ul>
-<li><a class="reference external" href="#interpreter-motivation">Interpreter Motivation</a></li>
 <li><a class="reference external" href="#installation">Installation</a><ul>
 <li><a class="reference external" href="#getting-the-trunk">Getting the Trunk</a></li>
 </ul>
 </li>
 <li><a class="reference external" href="#scripting">Scripting</a></li>
+<li><a class="reference external" href="#interpreter-motivation">Interpreter Motivation</a><ul>
 <li><a class="reference external" href="#creating-a-language">Creating a Language</a></li>
+</ul>
+</li>
 <li><a class="reference external" href="#using-java-libraries">Using Java libraries</a><ul>
 <li><a class="reference external" href="#inheriting-from-java-library-classes">Inheriting from Java library Classes</a></li>
 </ul>
     </div>
     <div class="footer">
       &copy; Copyright 2008, Creative Commons Attribution-Share Alike 3.0.
-      Last updated on Dec 30, 2008.
+      Last updated on Dec 31, 2008.
       Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.
     </div>
   </body>

File html/ToDo.html

 <p class="last">rewrite to distinguish python generator from above description, or
 choose different name.</p>
 </div>
-<p>(The original entry is located in Jython.rst, line 492 and can be found <a class="reference external" href="Jython.html#todo-20"><em>here</em></a>.)</p>
+<p>(The original entry is located in Jython.rst, line 496 and can be found <a class="reference external" href="Jython.html#todo-25"><em>here</em></a>.)</p>
 </div>
 
 
     </div>
     <div class="footer">
       &copy; Copyright 2008, Creative Commons Attribution-Share Alike 3.0.
-      Last updated on Dec 30, 2008.
+      Last updated on Dec 31, 2008.
       Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.
     </div>
   </body>

File html/_sources/Jython.txt

    	   that the material can be used to introduce Java programmers to
 	   Jython.
 
-This chapter looks at the value of crossing language boundaries. It is often
-advantageous to solve a problem using more than one programming language, rather
-than being arbitrarily stuck using a single language. As you'll see in this
-chapter, a problem that is very difficult or tedious to solve in one language
-can often be solved quickly and easily in another. If you can combine the use of
-languages, you can create your product much more quickly and cheaply.
+Sometimes it's easier and faster to temporarily step into another
+language to solve a particular aspect of your problem.
 
-The most straightforward use of this idea is the *Interpreter* design
-pattern, which adds an interpreted language to your program to allow
-the end user to easily customize a solution. If the application user
-needs greater run time flexibility, for example to create scripts
-describing the desired behavior of the system, you can use
-*Interpreter* by creating and embedding a language interpreter into
-your program.
+This chapter looks at the value of crossing language boundaries. It is
+often advantageous to solve a problem using more than one programming
+language; as you'll see, a problem that is very difficult or tedious
+to solve in one language can often be solved quickly and easily in
+another. By combining languages, you can create your product much more
+quickly and cheaply.
+
+One use of this idea is the *Interpreter* design pattern, which adds
+an interpreted language to your program to allow the end user to
+easily customize a solution. If the application user needs greater run
+time flexibility, for example to create scripts describing the desired
+behavior of the system, you can use *Interpreter* by creating and
+embedding a language interpreter into your program.
 
 In Java, the easiest and most powerful way to do this is with *Jython*
 [#]_, an implementation of Python in pure Java byte codes. As you will
 see, this brings together the benefits of both worlds.
 
-*Interpreter* solves a particular problem -- that of creating a
-scripting language for the user. But sometimes it's just easier and
-faster to temporarily step into another language to solve a particular
-aspect of your problem. You're not creating an interpreter, you're
-just writing some code in another language.
-
-Interpreter Motivation
-=======================================================================
-
-Remember that each design pattern allows one or more factors to change, so it's
-important to first be aware of which factor is changing. Sometimes the end users
-of your application (rather than the programmers of that application) need
-complete flexibility in the way that they configure some aspect of the program.
-That is, they need to do some kind of simple programming. The interpreter
-pattern provides this flexibility by adding a language interpreter.
-
-The problem is that developing your own language and building an interpreter is
-a time-consuming distraction from the process of developing your application.
-You must ask whether you want to finish writing your application or create a new
-language.  The best solution is to reuse code: embed an interpreter that's
-already been built and debugged for you. The Python language can be freely
-embedded into your for-profit application without signing any license agreement,
-paying royalties, or dealing with strings of any kind. There are basically no
-restrictions at all when you're using Python.
-
-For solving Java problems, we will look at a special version of Python called
-Jython. This is generated entirely in Java byte codes, so incorporating it into
-your application is quite simple,  and it's as portable as Java is. It has an
-extremely clean interface with Java: Java can call Python classes, and Python
-can call Java classes.
+Jython is generated entirely in Java byte codes, so incorporating it
+into your application is quite simple, and it's as portable as Java
+is. It has an extremely clean interface with Java: Java can call
+Python classes, and Python can call Java classes.
 
 Because Jython is just Java classes, it can often be "stealthed" into
 companies that have rigid processes for using new languges and
 tools. If Java has been accepted, such companies often accept anything
 that runs on the JVM without question.
 
-Python is designed with classes from the ground up and is a truly pure object
-oriented language (both C++ and Java violate purity in various ways). Python
-scales up so that you can create very big programs without losing control of the
-code. Java projects have been quickly created using Jython, then later optimized by
-rewriting sections of the Jython code that have profiled as bottlenecks into Java.
+The Python/Jython language can be freely embedded into your for-profit
+application without signing any license agreement, paying royalties,
+or dealing with strings of any kind. There are basically no
+restrictions when you're using Python/Jython.
+
+Python is designed with classes from the ground up and provides pure
+support for object-oriented programming (both C++ and Java violate
+purity in various ways). Python scales up so that you can create large
+programs without losing control of the code. Java projects have been
+quickly created using Jython, then later optimized by rewriting into
+Java sections of the Jython code that have profiled as bottlenecks.
 
 Installation
 =======================================================================
 Scripting
 =======================================================================
 
-One very compelling benefit of using a dynamic language on the JVM is
+One compelling benefit of using a dynamic language on the JVM is
 scripting.  You can rapidly create and test code, and solve problems
 more quickly.
 
 faster because of its rapid startup time; the JVM always has a delay
 for startup.
 
-Note that things that require much more code (and often research) in
-Java are very quick to write in Jython. Here's an example that uses
-a Python *list comprehension* with the **os.walk()** function to visit
-all the directories in a directory tree, and find all the files with names
-that end in **.java** (of course you can easily do more sophisticated things
-like opening the file and looking for information within it)::
+Note that things that are very quick to write in Jython require much
+more code (and often research) in Java. Here's an example that uses a
+Python *list comprehension* with the **os.walk()** function to visit
+all the directories in a directory tree, and find all the files with
+names that end in **.java** and contain the word **PythonInterpreter**::
 
-     # Jython/Walk_comprehension.py
-     import os
+       # Jython/Walk_comprehension.py
+       import os
 
-     restFiles = [os.path.join(d[0], f) for d in os.walk(".")
-                  for f in d[2] if f.endswith(".java")]
+       restFiles = [os.path.join(d[0], f) for d in os.walk(".")
+       		    for f in d[2] if f.endswith(".java") and
+                    "PythonInterpreter" in open(os.path.join(d[0], f)).read()]
 
-     for r in restFiles:
-     	 print(r)
+       for r in restFiles:
+       	   print(r)
 
 You can certainly achieve this in Java. It will just take a lot longer.
 
 The fact that you can quickly try things out allows you to test
 concepts, and then create more refined code as needed.
 
+Interpreter Motivation
+=======================================================================
+
+Remember that each design pattern allows one or more factors to
+change, so it's important to first be aware of which factor is
+changing. Sometimes the end users of your application (rather than the
+programmers of that application) need complete flexibility in the way
+that they configure some aspect of the program.  That is, they need to
+do some kind of simple programming. The *Interpreter* pattern provides
+this flexibility by adding a language interpreter.
+
+The problem is that creating your own language and building an
+interpreter is a time-consuming distraction from the process of
+developing your application.  You must ask whether you want to finish
+writing your application or make a new language.  The best solution is
+to reuse code: embed an interpreter that's already been built and
+debugged for you.
+
 Creating a Language
-=======================================================================
+-------------------------------------------------------------------------
 
 It turns out to be remarkably simple to use Jython to create an
 interpreted language inside your application. Consider the greenhouse
 controller example from *Thinking in Java*. This is a situation where
 you want the end user -- the person managing the greenhouse -- to have
 configuration control over the system, and so a simple scripting
-language is the ideal solution.  This is often called a
-*domain-specific language* (DSL) because it solves a particular
-domain problem.
+language is an ideal solution.  This is often called a
+*domain-specific language* (DSL) because it solves a particular domain
+problem.
 
 To create the language, we'll simply write a set of Python classes,
 and the constructor of each will add itself to a (static) master
 .. note:: To run this program say ``python GreenHouseLanguage.py`` or
    	  ``jython GreenHouseLanguage.py``.
 
-The constructor of each derived class calls the base-class constructor, which
-adds the new object to the list. The **run()** function sorts the list, which
-automatically uses the **__cmp__()** method defined in **Event** to
-base comparisons on time only. In this example, it only prints out the list, but
-in the real system it would wait for the time of each event to come up and then
-run the event.
+The constructor of each derived class calls the base-class
+constructor, which adds the new object to the list. The **run()**
+function sorts the list, which automatically uses the **__cmp__()**
+method defined in **Event** to base comparisons on time only. In this
+example, it only prints out the list, but in the real system it would
+wait for the time of each event to come up and then run the event.
 
 The **__main__** section performs a simple test on the classes.
 
 The above file -- which is an ordinary Python program -- is now a
-module that can be included in another Python program.
-But instead of using it in an ordinary Python program,
-let's use Jython, inside of Java. This turns out to be remarkably
-simple: you import some Jython classes, create a **PythonInterpreter**
-object, and cause the Python files to be loaded:
+module that can be included in another Python program.  But instead of
+using it in an ordinary Python program, let's use Jython, inside of
+Java. This turns out to be remarkably simple: you import some Jython
+classes, create a **PythonInterpreter** object, and cause the Python
+files to be loaded:
 
 ..  code-block:: java
 
       }
     }
 
-The **PythonInterpreter** object is a complete Python interpreter that accepts
-commands from the Java program. One of these commands is **execfile()**, which
-tells it to execute all the statements it finds in a particular file. By
-executing **GreenHouseLanguage.py**, all the classes from that file are loaded
-into our **PythonInterpreter** object, and so it now "holds" the greenhouse
-controller language. The **Schedule.ghs** file is the one created by the end
-user to control the greenhouse. Here's an example::
+The **PythonInterpreter** object is a complete Python interpreter that
+accepts commands from the Java program. One of these commands is
+**execfile()**, which tells it to execute all the statements it finds
+in a particular file. By executing **GreenHouseLanguage.py**, all the
+classes from that file are loaded into our **PythonInterpreter**
+object, and so it now "holds" the greenhouse controller language. The
+**Schedule.ghs** file is the one created by the end user to control
+the greenhouse. Here's an example::
 
     # Jython/Schedule.ghs
     Bell(7.00)
     LightOff(2.00)
     WaterOff(4.45)
 
-This is the goal of the interpreter design pattern: to make the configuration of
-your program as simple as possible for the end user. With Jython you can achieve
-this with almost no effort at all.
+This is the goal of the interpreter design pattern: to make the
+configuration of your program as simple as possible for the end
+user. With Jython you can achieve this with almost no effort at all.
 
 One of the other methods available to the **PythonInterpreter** is
 **exec()**, which allows you to send a command to the interpreter. In
 Using Java libraries
 =======================================================================
 
-Jython wraps the Java libraries so that any of them can be used directly or via
-inheritance. In addition, Python shorthand simplifies coding.
+Jython wraps Java libraries so that any of them can be used directly
+or via inheritance. In addition, Python shorthand simplifies coding.
 
-As an example, consider the **HTMLButton.java** example from
-*Thinking in Java*. Here is its conversion to Jython::
+As an example, consider the **HTMLButton.java** example from *Thinking
+in Java*. Here is its conversion to Jython::
 
     # Jython/PythonSwing.py
     # The HTMLButton.java example from "Thinking in Java"
     frame.size=200, 500
 
 If you compare the Java version of the program to the above Jython
-implementation, you'll see that Jython is shorter and generally easier to
-understand. For example, to set up the frame in the Java version you had to make
-several calls: the constructor for **JFrame()**, the **setVisible()** method
-and the **setDefaultCloseOperation()** method, whereas in the above code all
-three of these operations are performed with a single constructor call.
+implementation, you'll see that Jython is shorter and generally easier
+to understand. For example, to set up the frame in the Java version
+you had to make several calls: the constructor for **JFrame()**, the
+**setVisible()** method and the **setDefaultCloseOperation()** method,
+whereas in the above code all three of these operations are performed
+with a single constructor call.
 
-Also notice that the **JButton** is configured with an **actionListener()**
-method inside the constructor, with the assignment to **kapow**. In addition,
-Jython's JavaBean awareness means that a call to any method with a name that
-begins with "**set**" can be replaced with an assignment, as you see above.
+Also notice that the **JButton** is configured with an
+**actionListener()** method inside the constructor, with the
+assignment to **kapow**. In addition, Jython's JavaBean awareness
+means that a call to any method with a name that begins with "**set**"
+can be replaced with an assignment, as you see above.
 
-The only method that did not come over from Java is the **pack()** method,
-which seems to be essential in order to force the layout to happen properly.
-It's also important that the call to **pack()** appear *before* the **size**
-setting.
+The only method that did not come over from Java is the **pack()**
+method, which seems to be essential in order to force the layout to
+happen properly.  It's also important that the call to **pack()**
+appear *before* the **size** setting.
 
 Inheriting from Java library Classes
 -------------------------------------------------------------------------------
     frame.pack()
 
 
-**MyDialog** is inherited from **JDialog**, and you can see named arguments
-being used in the call to the base-class constructor.
+**MyDialog** is inherited from **JDialog**, and you can see named
+arguments being used in the call to the base-class constructor.
 
-In the creation of the "OK" **JButton**, note that the **actionPerformed**
-method is set right inside the constructor, and that the function is created
-using the Python **lambda** keyword. This creates a nameless function with the
-arguments appearing before the colon and the expression that generates the
-returned value after the colon. As you should know, the Java prototype for the
-**actionPerformed()** method only contains a single argument, but the lambda
-expression indicates two. However, the second argument is provided with a
-default value, so the function *can* be called with only one argument. The
-reason for the second argument is seen in the default value, because this is a
-way to pass **self** into the lambda expression, so that it can be used to
-dispose of the dialog.
+In the creation of the "OK" **JButton**, note that the
+**actionPerformed** method is set right inside the constructor, and
+that the function is created using the Python **lambda** keyword. This
+creates a nameless function with the arguments appearing before the
+colon and the expression that generates the returned value after the
+colon. As you should know, the Java prototype for the
+**actionPerformed()** method only contains a single argument, but the
+lambda expression indicates two. However, the second argument is
+provided with a default value, so the function *can* be called with
+only one argument. The reason for the second argument is seen in the
+default value, because this is a way to pass **self** into the lambda
+expression, so that it can be used to dispose of the dialog.
 
-Compare this code with the version that's published in *Thinking in Java*.
-You'll find that Python language features allow a much more succinct and direct
-implementation.
+Compare this code with the version that's published in *Thinking in
+Java*.  You'll find that Python language features allow a much more
+succinct and direct implementation.
 
 
 Controlling Java from Jython
 ..  todo:: rewrite to distinguish python generator from above description, or
     	   choose different name.
 
-Note that the **import** statements map to the Java package structure exactly as
-you would expect. In the first example, a **Date()** object is created as if it
-were a native Python class, and printing this object just calls **toString()**.
+Note that the **import** statements map to the Java package structure
+exactly as you would expect. In the first example, a **Date()** object
+is created as if it were a native Python class, and printing this
+object just calls **toString()**.
 
-**ValGen** implements the concept of a "generator" which is used a great deal in
-the C++ STL (*Standard Template Library*, part of the Standard C++ Library). A
-generator is an object that produces a new object every time its "generation
-method" is called, and it is quite convenient for filling containers. Here, I
-wanted to use it in a **for** iteration, and so I needed the generation method
-to be the one that is called by the iteration process. This is a special method
-called **__getitem__()**, which is actually the overloaded operator for
-indexing, '**[ ]**'. A **for** loop calls this method every time it wants to
-move the iteration forward, and when the elements run out, **__getitem__()**
-throws an out-of-bounds exception and that signals the end of the **for** loop
-(in other languages, you would never use an exception for ordinary control flow,
-but in Python it seems to work quite well). This exception happens automatically
-when **self.val[i]** runs out of elements, so the **__getitem__()** code turns
-out to be simple. The only complexity is that **__getitem__()** appears to
-return *two* objects instead of just one. What Python does is automatically
-package multiple return values into a tuple, so you still only end up returning
-a single object (in C++ or Java you would have to create your own data structure
-to accomplish this). In addition, in the **for** loop where **ValGen** is used,
-Python automatically "unpacks" the tuple so that you can have multiple iterators
-in the **for**. These are the kinds of syntax simplifications that make Python
-so endearing.
+**ValGen** implements the concept of a "generator" which is used a
+great deal in the C++ STL (*Standard Template Library*, part of the
+Standard C++ Library). A generator is an object that produces a new
+object every time its "generation method" is called, and it is quite
+convenient for filling containers. Here, I wanted to use it in a
+**for** iteration, and so I needed the generation method to be the one
+that is called by the iteration process. This is a special method
+called **__getitem__()**, which is actually the overloaded operator
+for indexing, '**[ ]**'. A **for** loop calls this method every time
+it wants to move the iteration forward, and when the elements run out,
+**__getitem__()** throws an out-of-bounds exception and that signals
+the end of the **for** loop (in other languages, you would never use
+an exception for ordinary control flow, but in Python it seems to work
+quite well). This exception happens automatically when **self.val[i]**
+runs out of elements, so the **__getitem__()** code turns out to be
+simple. The only complexity is that **__getitem__()** appears to
+return *two* objects instead of just one. What Python does is
+automatically package multiple return values into a tuple, so you
+still only end up returning a single object (in C++ or Java you would
+have to create your own data structure to accomplish this). In
+addition, in the **for** loop where **ValGen** is used, Python
+automatically "unpacks" the tuple so that you can have multiple
+iterators in the **for**. These are the kinds of syntax
+simplifications that make Python so endearing.
 
-The **jmap** and **jset** objects are instances of Java's **HashMap** and
-**HashSet**, again created as if those classes were just native Python
-components. In the **for** loop, the **put()** and **add()** methods work just
-like they do in Java. Also, indexing into a Java **Map** uses the same notation
-as for dictionaries, but note that to iterate through the keys in a **Map** you
-must use the **Map** method **keySet()** rather than the Python dictionary
-method **keys()**.
+The **jmap** and **jset** objects are instances of Java's **HashMap**
+and **HashSet**, again created as if those classes were just native
+Python components. In the **for** loop, the **put()** and **add()**
+methods work just like they do in Java. Also, indexing into a Java
+**Map** uses the same notation as for dictionaries, but note that to
+iterate through the keys in a **Map** you must use the **Map** method
+**keySet()** rather than the Python dictionary method **keys()**.
 
-The final part of the example shows the use of a Java class that I created from
-scratch, to demonstrate how trivial it is. Notice also that Jython intuitively
-understands JavaBeans properties, since you can either use the **getVal()** and
-**setVal()** methods, or assign to and read from the equivalent **val**
-property. Also, **getChars()** returns a **Character[]** in Java, and this
-automatically becomes an array in Python.
+The final part of the example shows the use of a Java class that I
+created from scratch, to demonstrate how trivial it is. Notice also
+that Jython intuitively understands JavaBeans properties, since you
+can either use the **getVal()** and **setVal()** methods, or assign to
+and read from the equivalent **val** property. Also, **getChars()**
+returns a **Character[]** in Java, and this automatically becomes an
+array in Python.
 
-The easiest way to use Java classes that you create for use inside a Python
-program is to put them inside a package. Although Jython can also import
-unpackaged java classes (**import JavaClass**), all such unpackaged java classes
-will be treated as if they were defined in different packages so they can only
-see each other's public methods.
+The easiest way to use Java classes that you create for use inside a
+Python program is to put them inside a package. Although Jython can
+also import unpackaged java classes (**import JavaClass**), all such
+unpackaged java classes will be treated as if they were defined in
+different packages so they can only see each other's public methods.
 
-Java packages translate into Jython modules, and Jython must import a module in
-order to be able to use the Java class. Here is the Java code for **JavaClass**:
+Java packages translate into Jython modules, and Jython must import a
+module in order to be able to use the Java class. Here is the Java
+code for **JavaClass**:
 
 ..  code-block:: java
 
       }
     }
 
-You can see that this is just an ordinary Java class, without any awareness that
-it will be used in a Jython program. For this reason, one of the important uses
-of Jython is in testing Java code [#]_. Because Python is such a powerful,
-flexible, dynamic language it is an ideal tool for automated test frameworks,
-without making any changes to the Java code that's being tested.
+You can see that this is just an ordinary Java class, without any
+awareness that it will be used in a Jython program. For this reason,
+one of the important uses of Jython is in testing Java code
+[#]_. Because Python is such a powerful, flexible, dynamic language it
+is an ideal tool for automated test frameworks, without making any
+changes to the Java code that's being tested.
 
 Inner Classes
 ------------------------------------------------------------------------------
 
-Inner classes becomes attributes on the class object. Instances of **static**
-inner classes can be created with the usual call::
+Inner classes becomes attributes on the class object. Instances of
+**static** inner classes can be created with the usual call::
 
     com.foo.JavaClass.StaticInnerClass()
 
-Non-**static** inner classes must have an outer class instance supplied
-explicitly as the first argument::
+Non-**static** inner classes must have an outer class instance
+supplied explicitly as the first argument::
 
     com.foo.JavaClass.InnerClass(com.foo.JavaClass())
 
 Controlling the Interpreter
 =======================================================================
 
-In the rest of this chapter, we shall look at more sophisticated ways to
-interact with Jython. The simplest way to exercise more control over the
-**PythonInterpreter** object from within Java is to send data to the
-interpreter, and pull data back out.
+In the rest of this chapter, we shall look at more sophisticated ways
+to interact with Jython. The simplest way to exercise more control
+over the **PythonInterpreter** object from within Java is to send data
+to the interpreter, and pull data back out.
 
 Putting Data In
 --------------------------------------------------------------------------------
 
-To inject data into your Python program, the **PythonInterpreter** class has a
-deceptively simple method: **set()**. However, **set()** takes many different
-data types and performs conversions upon them.  The following example is a
-reasonably thorough exercise of the various **set()** possibilities, along with
-comments that should give a fairly complete explanation:
+To inject data into your Python program, the **PythonInterpreter**
+class has a deceptively simple method: **set()**. However, **set()**
+takes many different data types and performs conversions upon them.
+The following example is a reasonably thorough exercise of the various
+**set()** possibilities, along with comments that should give a fairly
+complete explanation:
 
 ..  code-block:: java
 
       }
     }
 
-As usual with Java, the distinction between real objects and primitive types
-causes trouble. In general, if you pass a regular object to **set()**, it knows
-what to do with it, but if you want to pass in a primitive you must perform a
-conversion. One way to do this is to create a "Py" type, such as **PyInteger**
-or **PyFloat**. but it turns out you can also use Java's own object wrappers
-like **Integer** and **Float**, which is probably going to be a lot easier to
-remember.
+As usual with Java, the distinction between real objects and primitive
+types causes trouble. In general, if you pass a regular object to
+**set()**, it knows what to do with it, but if you want to pass in a
+primitive you must perform a conversion. One way to do this is to
+create a "Py" type, such as **PyInteger** or **PyFloat**. but it turns
+out you can also use Java's own object wrappers like **Integer** and
+**Float**, which is probably going to be a lot easier to remember.
 
-Early in the program you'll see an **exec()** containing the Python statement::
+Early in the program you'll see an **exec()** containing the Python
+statement::
 
     print(a[5:])
 
-The colon inside the indexing statement indicates a Python *slice*, which
-produces a range of elements from the original array. In this case, it produces
-an array containing the elements from number 5 until the end of the array. You
-could also say '**a[3:5]**' to produce elements 3 through 5, or '**a[:5]**' to
-produce the elements zero through 5. The reason a slice is used in this
-statement is to make sure that the Java **String** has really been converted to
-a Python string, which can also be treated as an array of characters.
+The colon inside the indexing statement indicates a Python *slice*,
+which produces a range of elements from the original array. In this
+case, it produces an array containing the elements from number 5 until
+the end of the array. You could also say '**a[3:5]**' to produce
+elements 3 through 5, or '**a[:5]**' to produce the elements zero
+through 5. The reason a slice is used in this statement is to make
+sure that the Java **String** has really been converted to a Python
+string, which can also be treated as an array of characters.
 
-You can see that it's possible, using **exec()**, to create a Python function
-(although it's a bit awkward). The **prt()** function prints the whole array,
-and then (to make sure it's a real Python array), iterates through each element
-of the array and prints it. Finally, it prints the class of the array, so we can
-see what conversion has taken place (Python not only has run-time type
-information, it also has the equivalent of Java reflection). The **prt()**
-function is used to print arrays that come from each of the Java primitive
-types.
+You can see that it's possible, using **exec()**, to create a Python
+function (although it's a bit awkward). The **prt()** function prints
+the whole array, and then (to make sure it's a real Python array),
+iterates through each element of the array and prints it. Finally, it
+prints the class of the array, so we can see what conversion has taken
+place (Python not only has run-time type information, it also has the
+equivalent of Java reflection). The **prt()** function is used to
+print arrays that come from each of the Java primitive types.
 
-Although a Java **ArrayList** does pass into the interpreter using **set()**,
-and you can index into it as if it were an array, trying to create a slice
-fails. To completely convert it into an array, one approach is to simply extract
-a Java array using **toArray()**, and pass that in. The **set()** method
-converts it to a **PyArray** -- one of the classes provided with Jython -- which
-can be treated as a Python array (you can also explicitly create a **PyArray**,
-but this seems unnecessary).
+Although a Java **ArrayList** does pass into the interpreter using
+**set()**, and you can index into it as if it were an array, trying to
+create a slice fails. To completely convert it into an array, one
+approach is to simply extract a Java array using **toArray()**, and
+pass that in. The **set()** method converts it to a **PyArray** -- one
+of the classes provided with Jython -- which can be treated as a
+Python array (you can also explicitly create a **PyArray**, but this
+seems unnecessary).
 
-Finally, a **Map** is created and passed directly into the interpreter. While it
-is possible to do simple things like index into the resulting object, it's not a
-real Python dictionary so you can't (for example) call the **keys()** method.
-There is no straightforward way to convert a Java **Map** into a Python
-dictionary, and so I wrote a utility called **toPyDictionary()** and made it a
-**static** method of **net.mindview.python.PyUtil**. This also includes
-utilities to extract a Python array into a Java **List**, and a Python
-dictionary into a Java **Map**:
+Finally, a **Map** is created and passed directly into the
+interpreter. While it is possible to do simple things like index into
+the resulting object, it's not a real Python dictionary so you can't
+(for example) call the **keys()** method.  There is no straightforward
+way to convert a Java **Map** into a Python dictionary, and so I wrote
+a utility called **toPyDictionary()** and made it a **static** method
+of **net.mindview.python.PyUtil**. This also includes utilities to
+extract a Python array into a Java **List**, and a Python dictionary
+into a Java **Map**:
 
 ..  code-block:: java
 
       }
     }
 
-
 Here is the unit testing code:
 
 ..  code-block:: java
 --------------------------------------------------------------------------------
 
 There are a number of different ways to extract data from the
-**PythonInterpreter**. If you simply call the **get()** method, passing it the
-object identifier as a string, it returns a **PyObject** (part of the
-**org.python.core** support classes). It's possible to "cast" it using the
-**__tojava__()** method, but there are better alternatives:
+**PythonInterpreter**. If you simply call the **get()** method,
+passing it the object identifier as a string, it returns a
+**PyObject** (part of the **org.python.core** support classes). It's
+possible to "cast" it using the **__tojava__()** method, but there are
+better alternatives:
 
 
-1.  The convenience methods in the **Py** class, such as **py2int()**, take a
-    **PyObject** and convert it to a number of different types.
+1.  The convenience methods in the **Py** class, such as **py2int()**,
+    take a **PyObject** and convert it to a number of different types.
 
-2.  An overloaded version of **get()** takes the desired Java **Class** object
-    as a second argument, and produces an object that has that run-time type (so you
-    still need to perform a cast on the result in your Java code).
+2.  An overloaded version of **get()** takes the desired Java
+    **Class** object as a second argument, and produces an object that
+    has that run-time type (so you still need to perform a cast on the
+    result in your Java code).
 
-Using the second approach, getting an array from the **PythonInterpreter** is
-quite easy. This is especially useful because Python is exceptionally good at
-manipulating strings and files, and so you will commonly want to extract the
-results as an array of strings. For example, you can do a wildcard expansion of
-file names using Python's **glob()**, as shown further down in the following
+Using the second approach, getting an array from the
+**PythonInterpreter** is quite easy. This is especially useful because
+Python is exceptionally good at manipulating strings and files, and so
+you will commonly want to extract the results as an array of
+strings. For example, you can do a wildcard expansion of file names
+using Python's **glob()**, as shown further down in the following
 code:
 
 ..  code-block:: java
       }
     }
 
-The last two examples show the extraction of Python tuples and lists into Java
-**List**\s, and Python dictionaries into Java **Map**\s. Both of these cases
-require more processing than is provided in the standard Jython library, so I
-have again created utilities in **net.mindview.pyton.PyUtil**: **toList()** to
-produce a **List** from a Python sequence, and **toMap()** to produce a **Map**
-from a Python dictionary. The **PyUtil** methods make it easier to take
-important data structures back and forth between Java and Python.
+The last two examples show the extraction of Python tuples and lists
+into Java **List**\s, and Python dictionaries into Java
+**Map**\s. Both of these cases require more processing than is
+provided in the standard Jython library, so I have again created
+utilities in **net.mindview.pyton.PyUtil**: **toList()** to produce a
+**List** from a Python sequence, and **toMap()** to produce a **Map**
+from a Python dictionary. The **PyUtil** methods make it easier to
+take important data structures back and forth between Java and Python.
 
 Multiple Interpreters
 --------------------------------------------------------------------------------
 
-It's also worth noting that you can have multiple **PythonInterpreter** objects
-in a program, and each one has its own name space:
+It's also worth noting that you can have multiple
+**PythonInterpreter** objects in a program, and each one has its own
+name space:
 
 ..  code-block:: java
 
     }
 
 
-When you run the program you'll see that the value of **a** is distinct within
-each **PythonInterpreter**.
+When you run the program you'll see that the value of **a** is
+distinct within each **PythonInterpreter**.
 
 Creating Java classes with Jython
 =======================================================================
 treat the results as if they are native Java classes, albeit with
 Python power under the hood.
 
-To produce Java classes from Python code, Jython comes with a compiler called
-**jythonc**.
+To produce Java classes from Python code, Jython comes with a compiler
+called **jythonc**.
 
 The process of creating Python classes that will produce Java classes
 is a bit more complex than when calling Java classes from Python,
     def returnArray(self):
         "@sig public java.lang.String[] returnArray()"
 
-The Python definition doesn't specify any return type, but the @sig string gives
-the full type information about what is being passed and returned. The
-**jythonc** compiler uses this information to generate the correct Java code.
+The Python definition doesn't specify any return type, but the @sig
+string gives the full type information about what is being passed and
+returned. The **jythonc** compiler uses this information to generate
+the correct Java code.
 
-There's one other set of rules you must follow in order to get a successful
-compilation: you must inherit from a Java class or interface in your Python
-class (you do not need to specify the **@sig** signature for methods defined in
-the superclass/interface). If you do not do this, you won't get your desired
-methods -- unfortunately, **jythonc** gives you no warnings or errors in this
-case, but you won't get what you want. If you don't see what's missing, it can
-be very frustrating.
+There's one other set of rules you must follow in order to get a
+successful compilation: you must inherit from a Java class or
+interface in your Python class (you do not need to specify the
+**@sig** signature for methods defined in the
+superclass/interface). If you do not do this, you won't get your
+desired methods -- unfortunately, **jythonc** gives you no warnings or
+errors in this case, but you won't get what you want. If you don't see
+what's missing, it can be very frustrating.
 
-In addition, you must import the appropriate java class and give the correct
-package specification.  In the example below, **java** is imported so you must
-inherit from **java.lang.Object**, but you could also say **from java.lang
-import Object** and then you'd just inherit from **Object** without the package
-specification. Unfortunately, you don't get any warnings or errors if you get
-this wrong, so you must be patient and keep trying.
+In addition, you must import the appropriate java class and give the
+correct package specification.  In the example below, **java** is
+imported so you must inherit from **java.lang.Object**, but you could
+also say **from java.lang import Object** and then you'd just inherit
+from **Object** without the package specification. Unfortunately, you
+don't get any warnings or errors if you get this wrong, so you must be
+patient and keep trying.
 
-Here is an example of a Python class created to produce a Java class. This also
-introduces the '**=T**' directive for the makefile builder tool, which specifies
-a different target than the one that is normally used by the tool. In this case,
-the Python file is used to build a Java **.class** file, so the class file is
-the desired target::
+Here is an example of a Python class created to produce a Java
+class. In this case, the Python file is used to build a Java
+**.class** file, so the class file is the desired target:
+
+..  code-block:: python
 
     # Jython/PythonToJavaClass.py
     # A Python class converted into a Java class
             for x in m.keys():
                 print(x, m[x])
 
+First note that **PythonToJavaClass** is inherited from
+**java.lang.Object**; if you don't do this you will quietly get a Java
+class without the right signatures. You are not required to inherit
+from **Object**; any other Java class will do.
 
-First note that **PythonToJavaClass** is inherited from **java.lang.Object**; if
-you don't do this you will quietly get a Java class without the right
-signatures. You are not required to inherit from **Object**; any other Java
-class will do.
+This class is designed to demonstrate different arguments and return
+values, to provide you with enough examples that you'll be able to
+easily create your own signature strings. The first three of these are
+fairly self-explanatory, but note the full qualification of the Java
+name in the signature string.
 
-This class is designed to demonstrate different  arguments and return values, to
-provide you with enough examples that you'll be able to easily create your own
-signature strings. The first three of these are fairly self-explanatory, but
-note the full qualification of the Java name in the signature string.
+In **returnArray()**, a Python array must be returned as a Java
+array. To do this, the Jython **array()** function (from the
+**jarray** module) must be used, along with the type of the class for
+the resulting array. Any time you need to return an array to Java, you
+must use **array()**, as seen in the methods **ints()** and
+**doubles()**.
 
-In **returnArray()**, a Python array must be returned as a Java array. To do
-this, the Jython **array()** function (from the **jarray** module) must be
-used, along with the type of the class for the resulting array. Any time you
-need to return an array to Java, you must use **array()**, as seen in the
-methods **ints()** and **doubles()**.
+The last methods show how to pass arguments in from Java. Basic types
+happen automatically as long as you specify them in the **@sig**
+string, but you must use objects and you cannot pass in primitives
+(that is, primitives must be ensconced in wrapper objects, such as
+**Integer**).
 
-The last methods show how to pass arguments in from Java. Basic types happen
-automatically as long as you specify them in the **@sig** string, but you must
-use objects and you cannot pass in primitives (that is, primitives must be
-ensconced in wrapper objects, such as **Integer**).
-
-In **argIn3()**, you can see that a Java **List** is transparently converted to
-something that behaves just like a Python array, but is not a true array because
-you cannot take a slice from it. If you want a true Python array, then you must
-create and pass a **PyArray** as in **argIn4()**, where the slice is
-successful. Similarly, a Java **Map** must come in as a **PyDictionary** in
-order to be treated as a Python dictionary.
+In **argIn3()**, you can see that a Java **List** is transparently
+converted to something that behaves just like a Python array, but is
+not a true array because you cannot take a slice from it. If you want
+a true Python array, then you must create and pass a **PyArray** as in
+**argIn4()**, where the slice is successful. Similarly, a Java **Map**
+must come in as a **PyDictionary** in order to be treated as a Python
+dictionary.
 
 Here is the Java program to exercise the Java classes produced by the
 above Python code. You can't compile **TestPythonToJavaClass.java**
 
 For Python support, you'll usually only need to import the classes in
 **org.python.core**. Everything else in the above example is fairly
-straightforward, as **PythonToJavaClass** appears, from the Java side, to be
-just another Java class. **dumpClassInfo()** uses reflection to verify that the
-method signatures specified in **PythonToJavaClass.py** have come through
-properly.
+straightforward, as **PythonToJavaClass** appears, from the Java side,
+to be just another Java class. **dumpClassInfo()** uses reflection to
+verify that the method signatures specified in
+**PythonToJavaClass.py** have come through properly.
 
 Building Java Classes from Python
 --------------------------------------------------------------------------------
 
-Part of the trick of creating Java classes from Python code is the @sig
-information in the method documentation strings. But there's a second problem
-which stems from the fact that Python has no "package" keyword -- the Python
-equivalent of packages (modules) are implicitly created based on the file name.
-However, to bring the resulting class files into the Java program, **jythonc**
-must be given information about how to create the Java package for the Python
-code. This is done on the **jythonc** command line using the **--package** flag,
-followed by the package name you wish to produce (including the separation dots,
-just as you would give the package name using the **package** keyword in a Java
-program). This will put the resulting **.class** files in the appropriate
-subdirectory off of the current directory. Then you only need to import the
-package in your Java program, as shown above (you'll need '**.**' in your
-CLASSPATH in order to run it from the code directory).
+Part of the trick of creating Java classes from Python code is the
+@sig information in the method documentation strings. But there's a
+second problem which stems from the fact that Python has no "package"
+keyword -- the Python equivalent of packages (modules) are implicitly
+created based on the file name.  However, to bring the resulting class
+files into the Java program, **jythonc** must be given information
+about how to create the Java package for the Python code. This is done
+on the **jythonc** command line using the **--package** flag, followed
+by the package name you wish to produce (including the separation
+dots, just as you would give the package name using the **package**
+keyword in a Java program). This will put the resulting **.class**
+files in the appropriate subdirectory off of the current
+directory. Then you only need to import the package in your Java
+program, as shown above (you'll need '**.**' in your CLASSPATH in
+order to run it from the code directory).
 
-Here are the **make** dependency rules that I used to build the above example
-(the backslashes at the ends of the lines are understood by **make** to be line
-continuations)::
+Here are the **make** dependency rules that I used to build the above
+example (the backslashes at the ends of the lines are understood by
+**make** to be line continuations)::
 
     TestPythonToJavaClass.class: \\
             TestPythonToJavaClass.java \\
         PythonToJavaClass.py
 
 The first target, **TestPythonToJavaClass.class**, depends on both
-**TestPythonToJavaClass.java** and the **PythonToJavaClass.class**, which is the
-Python code that's converted to a class file. This latter, in turn, depends on
-the Python source code. Note that it's important that the directory where the
-target lives be specified, so that the makefile will create the Java program
-with the minimum necessary amount of rebuilding.
+**TestPythonToJavaClass.java** and the **PythonToJavaClass.class**,
+which is the Python code that's converted to a class file. This
+latter, in turn, depends on the Python source code. Note that it's
+important that the directory where the target lives be specified, so
+that the makefile will create the Java program with the minimum
+necessary amount of rebuilding.
 
 Summary
 =======================================================================
 
-This chapter has arguably gone much deeper into Jython than required to use the
-interpreter design pattern. Indeed, once you decide that you need to use
-interpreter and that you're not going to get lost inventing your own language,
-the solution of installing Jython is quite simple, and you can at least get
-started by following the **GreenHouseController** example.
+This chapter has arguably gone much deeper into Jython than required
+to use the interpreter design pattern. Indeed, once you decide that
+you need to use interpreter and that you're not going to get lost
+inventing your own language, the solution of installing Jython is
+quite simple, and you can at least get started by following the
+**GreenHouseController** example.
 
-Of course, that example is often too simple and you may need something more
-sophisticated, often requiring more interesting data to be passed back and
-forth. When I encountered the limited documentation, I felt it necessary to come
-up with a more thorough examination of Jython.
+Of course, that example is often too simple and you may need something
+more sophisticated, often requiring more interesting data to be passed
+back and forth. When I encountered the limited documentation, I felt
+it necessary to come up with a more thorough examination of Jython.
 
 In the process, note that there could be another equally powerful
 design pattern lurking in here, which could perhaps be called
 to bridge across languages, and at the same time bridging between
 computers and operating systems.
 
-To me, Python and Java present a very potent combination for program development
-because of Java's architecture and tool set, and Python's extremely rapid
-development (generally considered to be 5-10 times faster than C++ or Java).
-Python is usually slower, however, but even if you end up re-coding parts of
-your program for speed, the initial fast development will allow you to more
-quickly flesh out the system and uncover and solve the critical sections. And
-often, the execution speed of Python is not a problem -- in those cases it's an
-even bigger win. A number of commercial products already use Java and Jython,
-and because of the terrific productivity leverage I expect to see this happen
-more in the future.
+To me, Python and Java present a very potent combination for program
+development because of Java's architecture and tool set, and Python's
+extremely rapid development (generally considered to be 5-10 times
+faster than C++ or Java).  Python is usually slower, however, but even
+if you end up re-coding parts of your program for speed, the initial
+fast development will allow you to more quickly flesh out the system
+and uncover and solve the critical sections. And often, the execution
+speed of Python is not a problem -- in those cases it's an even bigger
+win. A number of commercial products already use Java and Jython, and
+because of the terrific productivity leverage I expect to see this
+happen more in the future.
 
 Exercises
 =======================================================================
 
-#.  Modify **GreenHouseLanguage.py** so that it checks the times for the events
-    and runs those events at the appropriate times.
+#.  Modify **GreenHouseLanguage.py** so that it checks the times for
+    the events and runs those events at the appropriate times.
 
-#.  Modify **GreenHouseLanguage.py** so that it calls a function for **action**
-    instead of just printing a string.
+#.  Modify **GreenHouseLanguage.py** so that it calls a function for
+    **action** instead of just printing a string.
 
-#.  Create a Swing application with a **JTextField** (where the user will ente