PYTHON 3 users will be very pleased with this new book. Those who still cling to Python 2 likely will not.
Even though “most working Python programmers continue to use Python 2 in production,” its authors concede, and “Python 3 is not backward compatible with past versions,” this third edition of the popular Python Cookbook is intended to be used only with Python 3.3 and above.
“Just as Python 3 is about the future, this edition…represents a major change over past editions,” Beazley and Jones state. “First and foremost, this is meant to be a very forward looking book. All of the recipes have been written and tested with Python 3.3 without regard to past Python versions or the ‘old way’ of doing things. In fact, many of the recipes will only work with Python 3.3 and above.”
THEIR “ultimate goal,” they point out, was “to write a book of recipes based on the most modern tools and idioms possible. It is hoped that the recipes can serve as a guide for people writing new code in Python 3 or those who hope to modernize existing code.”
The 687-page Python Cookbook, 3rd Edition is not intended for beginning programmers. However, beginners can learn a few things from it and keep the book on their shelves for future use as they gain experience with Python 3.
And, it can be a helpful guide if you are working to update some Python 2 code to Python 3. According to the authors, “many of the recipes aim to illustrate features that are new to Python 3 and more likely to be unknown to even experienced programmers using older versions.”
THE book offers 15 chapters of how-to recipes organized into the following major categories:
- Data Structures and Algorithms
- Strings and Text
- Numbers, Dates, and Times
- Iterators and Generators
- Files and I/O
- Data Encoding and Processing
- Classes and Objects
- Modules and Packages
- Network and Web Programming
- Utility Scripting and Administration
- Testing, Debugging, and Exceptions
- C Extensions
Each of the approximately 260 recipes is presented using a “problem-solution-discussion” format. Here are a few recipe titles chosen at random:
- “Combining and Concatenating Strings”
- “Reformatting Text to a Fixed Number of Columns”
- “Bypassing Filename Encoding”
- “Iterating over the Index-Value Pairs of a Sequence”
- “Capturing Variables in Anonymous Functions”
- “Implementing Stateful Objects or State Machines”
- “Enforcing an Argument Signature on *args and **kwargs”
- “Creating Custom Exceptions”
- “Writing a Simple C Extension Module”
SOME of the book’s code examples are complete. But others, the authors caution, “are often just skeletons that provide essential information for getting started, but which require the reader to do more research to fill in the details.”
If you are serious about Python and keeping pace with its progress, you should seriously consider getting this excellent how-to book.
– Si Dunn