Welcome to UnixReview.com

Main Menu
  Geek Links
  Contact Us


  Tool of the Month
  Open Source
  Shell Corner

Get the Newsletter
Get the Newsletter

  Print-Friendly Version

 Book Review: Python Cookbook January 2003

by Cameron Laird

Python Cookbook
Edited by Alex Martelli, David Ascher
O'Reilly, July 2002
606 pages, $39.95

The Python Cookbook (PC) is superb.

Demonstrably so, in fact. Most book reviews are matters of judgment and discrimination, dependent on the taste and wisdom of the reviewer. PC's quality is so unique that it deserves a different, more objective style of review.

Review Practices

Here's why — I know too much. I'm an acquaintance and/or collaborator not only of PC's editors, but also of several of the other contributors and staffers of publisher O'Reilly's Cookbook series. For several months, I thought I was too close to do PC justice.

That was a mistake — particularly in light of the missed opportunity to recommend PC as a seasonal stocking stuffer for the programmers in your life. PC is so good that it's hard to go wrong buying a copy for yourselves or others.

I write that with confidence because the words aren't mine. Shortly after PC hit the bookshelves at the end of summer, Python programmers began talking about it — at interest group meetings, over lunch, and in all sorts of online forums. Agreement was near universal that the book is extraordinary.

A proper review of the book, then, depends less on my critical assessment of it, and more on the ability simply to report what the community of Python programmers has to say about it. Developer Edward Ream, for example, praised it in the comp.lang.python Usenet newsgroup:

"This really is an awe-inspiring book for the breadth of its coverage and the complete excellence of its presentation. The authors and especially the editors deserve the highest praise. Even when explaining the most elementary topics the editors manage to be interesting and even surprising. ...In short, this is just a superb job. It shows the power of a community of users enhanced by the editing of stars."

Quality of writing

Reader reactions to PC are closer to those of a New Yorker or Granta feature than a language manual; many programmers talk about how they go back and re-read sections of PC to savor the quality of the exposition, and to discover new layers of meaning.

PC is, in fact, two books packed into something less than 600 pages. The recipes are certainly indispensable for a working Python programmer. A "Discussion" follows each one, in the usual O'Reilly Cookbook style. These Discussions are so meaty, eloquent, and well-informed that they could stand by themselves as a valuable course in software engineering.

The recipes themselves are generally more ambitious than in other Cookbooks. The Perl Cookbook, for example, is more than 700 pages, and was itself edited with considerable precision and insight. For the most part, though, it seems rarely to elevate its vision to the heights of PC. While the Perl Cookbook "tops out" with calculations of prime factors, randomized arrays, regular expression techniques, and a binary tree manager, PC gracefully tackles a (readably!) three-line quicksort implementation, Unicode manipulation, a ring buffer, generation of random passwords, interactive GUI construction, lazy database connection, sophisticated network programming, Windows-specific tricks, fascinating metaprogramming and introspection, and much more. I think we still don't know how to partition this achievement accurately between the virtues of the Python language, its community of practitioners, and the editors of PC. What's certain, though, is that the combination is a winning one.

Experienced programmer Fernando Perez wrote at length about the contrast between PC and other references. Most of us keep various language books at hand to ensure we've got syntax right, or to jog our memories about the details of library members. With PC, in contrast,

"Instead of being devoted to reminding you how to do things you should be able to do without a book, it's mostly a discussion of the type 'here's a common problem for which naive solutions can have subtle pitfalls, and here are various ways to tackle it with real intelligence and power'. ... [PC] reads almost more like an algorithms/computer science book than a 'Python' book."

Perez also echoes many other readers in praising the editors' balancing act:

"Even though it has many authors for the recipes, the book managed to remain very cohesive in tone and style. You can feel enough differences to hear the 'community voices', but not to the point of being distracted by them."

This is the challenge co-editor Alex Martelli calls, "unifying without homogenizing", and PC achieves it gratifyingly.


If you work with Python, you'll want your own copy of PC. It joins the Python Essential Reference on the top rung of Python-oriented books, just ahead of Learning Python, Python Web Programming, and The Python Standard Library in universality and quality. While the collection of Python books is quite good as a whole (see also this earlier issue of UnixReview.com, for example), the merits of these five distinguish them from the rest.

Even if your primary programming interest is in a language other than Python, you should consider PC. Its ideas apply more or less easily to work in Java, Ruby, Perl, and others.

As Vice President of Phaseit, Inc., Cameron Laird programs in Python most days. He frequently reviews books for UnixReview, and co-authors the monthly "Regular Expressions" column.

Home | Top

Copyright 2002 CMP Media LLC, Privacy Policy
Comments about the Web site: webmaster@unixreview.com
SDMG Web Sites: Byte.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network