There are two ways to learn how to do something completely new in just about any programming language. You can either
• hack away using whatever references you can cobble together and write it on your own or
• find someone who's already written it - or something close to it - and "borrow" his or her solution.
Except for those working on ridiculously proprietary tasks such as programming simulations of nuclear explosions or demultiplexing three-D seismic signals, programmers are generally pleased to share their bits of code - it's quite an ego-boost to believe you're smarter than the next guy, after all. Out of this not completely altruistic desire to share arise the collections of solutions known as "cookbooks." You can find a cookbook or two for just about any programming language you've ever heard of, and more than one you haven't heard of. This cookbook serves up a healthy portion of Python, although it probably doesn't really taste like chicken (although rattlesnake kind of does).
The current release is the second edition of Python Cookbook, subtitled "Recipes from the Python Community." In the three years since the publication of the first edition, Python has evolved to version 2.4 (one of the most robust versions), and many of the recipes take advantage of new functionality included in that release. The text includes not only the original 200 or so recipes but an additional 140 or so for a final count of 338. Recipes from the first edition have been updated to include reference to version 2.4 - some have even been rendered obsolete, but are retained for those who must support old code or are laboring under an older version.
Each recipe contains
• A statement of the problem
• A coded solution
• Discussion, including hints for expanding or modifying the code
• References (mostly to Python in a Nutshell or the Python Library Reference)
All recipes are credited to the original programmer, and many or all are available on-line, absent the discussion.
In all, twenty general areas are covered by these recipes*, covering a broad range of topics from simple text handling (25 recipes) to web programming (14 recipes), distributed programming (11 recipes) , extending Python and embedding Python modules in other code and vice versa (10 recipes). In the section on Iterators and Generators you'll find a recipe for generating a Fibonacci sequence; in Web Programming, for checking for a web page's existence; in User Interfaces, for converting among Image formats or displaying a progress indicator.
Many of the recipes are, frankly, solutions for which most programmers will never have a problem - I can't see ever a personal need for "Forking a Daemon Process on Linux," or "Using a Single Parameter-Passing Style Across Various DB API Modules," although your mileage will most certainly vary. Heck, I'm not even certain what some of the topics mean... Other recipes have likely appeal for anyone who writes his or her own code, especially those in the debuggingsection such as "Trapping and Recording Exceptions."
While many recipes in early chapters - on Text, Files, and Sorting - are simplistic enough that rank Python novices might find them useful, the recipes' complexity (and level of esotericism) begins to rise rapidly after about chapter six. Beyond that point, you're getting into highly specialized programming that ordinary tyros like me usually leave to the pros. After all, however, this book is written for those pros.
Unlike conventional recipes, most Python recipes do not require a special trip to the grocery. That's mostly because Python is a remarkably full-featured and self-contained language. In a few cases you might find reference to a third-party module necessary to make the recipe work, but these are rare. For the most part you simply type the text (or go to the website and download it) and poof! there you are.
In cooking, the beauty of a recipe is you get to spice up the dish however you like it or modify it to use whatever ingredients you happen to have on hand. The procedure is exactly the same with the recipes in the Python Cookbook: the user is not only encouraged but expected to modify the solution to fit his or her own needs. These solutions are meant not as complete answers, but departure points or templates for your own use.
So although Python doesn't actually taste like chicken, this cookbook contains some truly delicious - maybe you should read that as "very useful" - recipes for anyone who regularly works with this language. If yours is a Python shop, you need this one on the shelf somewhere!
*Chapter headings:
1: Text
2: Files
3: Time and Money
3: Python Shortcuts
5: Searching and Sorting
6: Object-Oriented Programming
7: Persistence and Databases
8: Debugging and Testing
9: Processes, Threads, and Synchronization
10: System Administration
11: User Interfaces
12: Processing XML
13: Network Programming
14: Web Programming
15: Distributed Programming
16: Programs about Programs
17: Extending and Embedding
18: Algorithms
19: Iterators and generators
20: Descriptors, Decorators, and Metaclasses
Portable, powerful, and a breeze to use, Python is the popular open source object-oriented programming language used for both standalone programs and ...More at Buy.com
Epinions.com periodically updates pricing and product information from third-party sources, so some information may be slightly out-of-date. You should confirm all information before relying on it.