Book Review: Python Standard Library

 in
Title: Python Standard Library Author: Fredrik Lundh ISBN: 0-596-00096-0 Publisher: O'Reilly & Associates Price: $29.95 Reviewer: Phil Hughes

When I offered to review Python Standard Library, I expected to find a dull list of library functions with dry descriptions of their arguments. I was pleasantly surprised, though, when I started reading the book. The author claims to spend hundreds of hours answering questions on the comp.lang.python Usenet newsgroup. It shows.

Rather than the dry manual I expected, this book is filled with useful examples. It is comprehensive, with the exception of not covering Tkinter. This seems like a reasonable decision considering that the majority of Python users will not use Tkinter, and it would take a lot of space to document. In fact, Fredrik is working on a separate book on Tkinter.

Python Standard Library is divided into 14 chapters, each covering a related set of modules. As the book is comprehensive there is no reason to enumerate its contents here, but the divisions are quite logical. For example, there are chapters on threads and processes as well as mail and news message processing. Two chapters, "Platform-Specific Modules" and "Implementation Support Modules", cover the non-generic modules.

To give you a feeling for the book, I will describe two specific sections in detail.

The first section is called "The string Module", from the "Core Modules" chapter. This section is a little under two pages, the majority of which is code. After a once-sentence description, you are presented with an example. The example includes the file name (so you can find it on the CD), about ten lines of code and the result of executing the code. The code is mainly print statements with a text string passed to the various functions of string, e.g., string.upper, string.lower, string.split, string.count.

Next comes a brief description of differences between Python 1.5.2 and later versions. As the main difference is the availability of string methods in the later versions of Python, a new example is included that shows the same code written to use string methods instead of string module functions.

A third description and example explains the additional capabilities of the string module for converting other data types to strings. The final paragraphs describe how you can use the int and float functions as an alternative to the string module counterparts.

As a second example, I have selected "The cgi Modules" from the "Network Protocols" chapter. This description is about 1.5 pages long and includes two short paragraphs of text, followed by a listing. The listing is a CGI script that returns a list of files in a specified directory. It uses os.environ.get to grab the QUERY_STRING, os.listdir to get the file names and cgi.escape to clean up strings.

While the example is cleanly written and does what it says it should, I was a little disappointed that it did not go into all the functionality of the cgi module. For example, it mentions that the module can parse CGI form data, but there is no description or example of how to do this.

The CD is a logical addition, it includes all the scripts found in the book. In addition, it contains prebuilt Python 2.0 distributions for Windows and x86 Linux (in RPM format), plus a demo copy of PythonWorks Pro 1.2 for the same two platforms.

PythonWorks is an integrated development environment (IDE) for Python. The included software runs in demo mode, limiting what you can do with the included projects. However, you can get a free, time-limited Evaluation Ticket from the Pythonware web site, so you can see how it runs on your project.

Overall, the book is packed with a lot of practical information. The text seems accurate--the only typo I found was grammatical and insignificant. It doesn't answer every question readers might have, but for its size and readability it does a good job. Unlike some books I have seen on other programming languages--where readers are handed a lot of code but figuring out what it does and what it is related to is left to them--I found all the examples in this book relevant to the subjects being addressed.

As long as you don't expect to find everything in one book, I expect you will be satisfied. If, however, you just must have all the information in one book, the Python Developer's Handbook (reviewed in the February 2001 issue of Linux Journal) may be the better choice.

Phil Hughes is the publisher of Linux Journal.

______________________

Phil Hughes

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix