Chapter 11. Jython Standard Library
The philosophy behind Python is “Batteries included.” As a result, Python ships with more than 100 standard modules that cover all kinds of functionality, from file manipulation to network protocols to unit testing to encryption, and so on. As we’ve seen, in addition to containing the majority of the Python standard library, Jython also includes another set of “batteries”—the standard Java API.
This chapter shows how to use a few of the most useful elements of
the Python library from Jython. We chose the modules for this chapter for
two reasons. Some modules, such as
sys, are so commonly used in Jython that you’ll need
them for nearly anything you write. Others, such as
unittest, offer functionality that is either not
implemented or awkwardly implemented in the Java API. We did not include
modules that had obvious Java counterparts (such as
random), or if they were
covered elsewhere in the book (such as
operator), or if they were considered less than
essential. The CPython documentation contains full documentation on all
CPython modules at http://www.python.org/doc/current/modindex.html—but see the
next section for a sense of which modules will work with Jython. In
addition, you can also see Python Standard Library,
by Fredrik Lundh (O’Reilly), for additional samples of how the different
modules are used.
Using Python Modules
Using a Python module is usually as simple as the
modulename statement. Most Python ...