Python Cookbook and over one million other books are available for Amazon Kindle. Learn more



or
Sign in to turn on 1-Click ordering
More Buying Choices
Have one to sell? Sell yours here
Start reading Python Cookbook on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.
Sorry, this item is not available in
Image not available for
Color:
Image not available

To view this video download Flash Player

 

Python Cookbook [Paperback]

Alex Martelli , Anna Ravenscroft , David Ascher
4.3 out of 5 stars  See all reviews (49 customer reviews)

List Price: $49.95
Price: $30.51 & FREE Shipping. Details
You Save: $19.44 (39%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 10 left in stock.
Ships from and sold by Amazon.com. Gift-wrap available.
Want it Wednesday, May 29? Choose One-Day Shipping at checkout. Details
Free Two-Day Shipping for College Students with Amazon Student

Formats

Amazon Price New from Used from
Kindle Edition $24.79  
Paperback $30.51  
Rent Your Textbooks
Save up to 70% when you rent your textbooks on Amazon. Keep your textbook rentals for a semester and rental return shipping is free.
There is a newer edition of this item:
Python Cookbook Python Cookbook
$28.35
In stock but may require an extra 1-2 days to process.

Book Description

March 25, 2005 0596007973 978-0596007973 Second Edition

Portable, powerful, and a breeze to use, Python is the popular open source object-oriented programming language used for both standalone programs and scripting applications. It is now being used by an increasing number of major organizations, including NASA and Google.

Updated for Python 2.4, The Python Cookbook, 2nd Edition offers a wealth of useful code for all Python programmers, not just advanced practitioners. Like its predecessor, the new edition provides solutions to problems that Python programmers face everyday.

It now includes over 200 recipes that range from simple tasks, such as working with dictionaries and list comprehensions, to complex tasks, such as monitoring a network and building a templating system. This revised version also includes new chapters on topics such as time, money, and metaprogramming.

Here's a list of additional topics covered:

  • Manipulating text
  • Searching and sorting
  • Working with files and the filesystem
  • Object-oriented programming
  • Dealing with threads and processes
  • System administration
  • Interacting with databases
  • Creating user interfaces
  • Network and web programming
  • Processing XML
  • Distributed programming
  • Debugging and testing
Another advantage of The Python Cookbook, 2nd Edition is its trio of authors--three well-known Python programming experts, who are highly visible on email lists and in newsgroups, and speak often at Python conferences.

With scores of practical examples and pertinent background information, The Python Cookbook, 2nd Edition is the one source you need if you're looking to build efficient, flexible, scalable, and well-integrated systems.


Frequently Bought Together

Python Cookbook + Python Pocket Reference: Python in Your Pocket (Pocket Reference (O'Reilly)) + Programming Python
Price for all three: $79.29

Buy the selected items together


Editorial Reviews

Review

"I have no reservations recommending this book." - Tim Penhey, Cvu, February 2003 --This text refers to an out of print or unavailable edition of this title.

About the Author

Alex Martelli spent 8 years with IBM Research, winning three Outstanding Technical Achievement Awards. He then spent 13 as a Senior Software Consultant at think3 inc, developing libraries, network protocols, GUI engines, event frameworks, and web access frontends. He has also taught programming languages, development methods, and numerical computing at Ferrara University and other venues. He's a C++ MVP for Brainbench, and a member of the Python Software Foundation. He currently works for AB Strakt, a Python-centered software house in G teborg, Sweden, mostly by telecommuting from his home in Bologna, Italy. Alex's proudest achievement is the articles that appeared in Bridge World (January/February 2000), which were hailed as giant steps towards solving issues that had haunted contract bridge theoreticians for decades.

Anna Martelli Ravenscroft has a background in training and mentoring, particularly in office technologies. She brings a fresh perspective to Python with a focus on practical, real-world problem solving. Anna is currently pursuing a degree at Stanford University and often pair programs (in Python) with her husband and children.

David Ascher is the lead for Python projects at ActiveState, including Komodo, ActiveState's integrated development environment written mostly in Python. David has taught courses about Python to corporations, in universities, and at conferences. He also organized the Python track at the 1999 and 2000 O'Reilly Open Source Conventions, and was the program chair for the 10th International Python Conference. In addition, he co-wrote Learning Python (both editions) and serves as a director of the Python Software Foundation. David holds a B.S. in physics and a Ph.D. in cognitive science, both from Brown University.


Product Details

  • Paperback: 846 pages
  • Publisher: O'Reilly Media; Second Edition edition (March 25, 2005)
  • Language: English
  • ISBN-10: 0596007973
  • ISBN-13: 978-0596007973
  • Product Dimensions: 7 x 1.6 x 9.2 inches
  • Shipping Weight: 2.5 pounds (View shipping rates and policies)
  • Average Customer Review: 4.3 out of 5 stars  See all reviews (49 customer reviews)
  • Amazon Best Sellers Rank: #68,712 in Books (See Top 100 in Books)

More About the Authors

Discover books, learn about writers, read author blogs, and more.

Customer Reviews

Most Helpful Customer Reviews
103 of 109 people found the following review helpful
3.0 out of 5 stars Half-cooked September 6, 2005
Format:Paperback
Good:

As other reviewers have pointed out, this book offers solutions for a broad range of programming problems. There is something for every level from beginner to expert (the most advanced examples were well over my head). The recipes are enhanced by discussions that are mostly very well and clearly written, giving insight into the design and logic of the presented recipes. They thus guide the way to adapting the recipes to your own programs.
So, most of the content of this book is good. 4-5 stars for that.

Bad / Production:

The recipes (so I gather) are mostly edited versions of what is available at ActiveState's online cookbook. However, the edited versions seem not to be available online (at least there is no pointer, and O'Reilly's website does not provide one either). Nor does the book include a CD. For all the hype in the book about this being a book by the Python community for the Python community, this is disappointing. Not even pointers are provided to on-line cookbook recipes that were used as starting points for those printed in this book. This is just bad craftsmanship on the part of O'Reilly. (On a similar note, the back cover promises a foreword by Guido but there isn't one.)

Bad / Content:

Sugar is sweet but bad for your health. So it is with this book - too many recipes add only (syntactic) sugar but no minerals and vitamins. Several 'shortcuts' are just wasted ink and breath - they will save you 1-2 lines of code when writing a function but then you have to import the shortcut implementation and get to make the extra function calls... Where these 'shortcuts' help to avoid some Python gotchas, it would have been more useful to just document the gotcha in question and show how to avoid it in straight Python code without any sugaring. Case in point: The once-only initialization of function default arguments. If you write:

def foo(bar=[])
bar.append(quux)

then previous quuxes will be lurking in the bars of every subsequent foo call that does not pass bar itself. So, you must write:

def foo(bar=None):
if not bar: bar=[]

to get an empty [] for every call. Now does this 'problem' merit a more elaborate, sugary 'solution'? I don't think so.

Some recipes are recipes for disaster. We are told how to automatically call the __init__ routines of every superclass... what we are not told is how to automatically call them in the appropriate order or with the respective arguments for making things work. How often do you write an __init__ that takes only the 'self' argument? Sure, it occurs, but... The omission of implicit superclass calls was a conscious design choice in Python and a wise one at that. Too many recipes like this one just want to show you how to subvert Python's conscious design choices. The sweet taste won't last but give way to heartburn.

For a book of this scope and design it is of course impossible to avoid criticism of the kind 'why did you include A but not B...'
Still, here goes:

XML: There are excellent libraries such as ElementTree and now cElementTree that offer fast, clean and 'Pythonic' alternatives to the standard library modules for XML parsing. More than just a URL pointer should have been provided.

Web programming: Only Jython and Twisted are mentioned as alternatives to CGI. Now Twisted may be the greatest thing since sliced bread, but ordinary mortals will never know, because it has about the the most confusing and unfathomable documentation of anything on the web (ooh I forgot Zope...). Presenting Twisted 'recipes' (or rather, plugs) with 'discussions' that drone about its power but are again just the same handwaving stuff as in the on-line docs is useless.

(If you just want to get your web stuff done with minimal pain: For simple PHP-like embedded scripting but with the advantages of Python, look at Spyce, and for an easy application server, look at Cherrypy or Webware).

So, altogether, a good book but not quite on par with e.g. Python in a Nutshell.

Was this review helpful to you?
76 of 96 people found the following review helpful
5.0 out of 5 stars Valuable tricks&tips from _real_ Python experts October 11, 2002
Format:Paperback
Of the many successes of Python, this is the least known but one of the most impressive: it has gained the affection and the respect of a hard guy like Alex Martelli. That is not an easy task for a small, interpreted programming language like Python.

When I first met Alex Martelli, at Think3, he was one of the oldest and most experienced programmers of the company, a programmer who had already used most of the existing languages and had used these languages for the development of large and complex applications, the kind of projects that took months or years to complete. He knew Perl very, _very_ well and was used to rely on a robust, elegant and sophisticated language like C++ for the development of his applications (like Think3's Thinkdesign, a very complex 3D CAD program). He was writing a _lot_ of software, using a large array of different languages and tools. He was a well respected internal consultant at Think3, charged to solve difficult problems related to the software architecture of the program being developed. He was not an easy guy to impress with "yet another small language".

Despite this, Python has gained some room in his heart. I consider this fact as one of the most significant success of this elegant and powerfull language. To be completely honest, I'm not completely surprised by this ending.

Alex Martelli is the kind of scientist and professional that appreciate elegance, wherever he can see it. The taste for elegance, the ability to take pleasure in elegance, is an important part of the scientist and engineer personality. It is hard to be a really good software professional without having any kind of interest for elegance. When you need a simple tool that can face complex problems, you are asking for elegance. When you need a language that leave you with maintenable code, you are asking for elegance. When you want a single language for a wide array of applications, you are asking for elegance. Python can supply you with all the elegance you can ever ask for.

Alex's and David's book is a collection of good techniques that you can use to face a large set of problems with Python, from text transformation to GUI building to OpenGL grahics. You will not find here an introductory book, rather you will find a good second-reading book, the kind of book that can take you from the beginner level to the advanced. It is also the kind of book that can widen your knowledge of the Python world, showing you how this modern language can easily deal with problems that you usually face with C++ or the like.

If you are looking for an introductory book, buy "Learning Python" by Mark Lutz and David Ascher: it is the best one for this task. If you already know Python, buy this book and see how much you still do not know about it.

Comment | 
Was this review helpful to you?
22 of 26 people found the following review helpful
4.0 out of 5 stars A Fun Resource for Python Programmers at Most Levels November 1, 2005
Format:Paperback
Full disclosure: I purchased the first edition of this book, and received the second edition as a reviewers copy. I work for Zope Corporation.

The O'Reilly Python Cookbook is a fun resource for Python programmers at most levels. The fun comes in part from the personalities that shine through the introductions and the community-authored recipes gathered from the ActiveState Python Cookbook website. The other fun comes from the smorgasbord of topics and technologies laid out for the reader, encouraging browsing and experimentation. New Python programmers will find recipes that highlight some of the newer features of the Python language, and experienced Python programmers will likely find thought-provoking recipes both peripherally and directly related to their specialties and interests.

Like the first edition, this second edition covers a wide range of topics. Each topic has a usually-interesting introduction by well-known names in the Python community. Some topics are of general interest-shortcuts and algorithms, for instance-while others explore somewhat more specialized topics, such as networks, XML, and databases. Each cookbook recipe I read was impressively short, while often still having enough weight to them to address non-toy usages of the approaches. Many examples can also be used as introductions to the modules and packages they use. Another important similarity to the first edition is that a portion of the proceeds from the book sales are donated to the Python Software Foundation.

This edition of the cookbook does have some significant changes from the previous one. While the first edition addressed Python versions in the 1.x and 2.x line, this one addresses only Python 2.3 and 2.4. It adds about a third more recipes than the first edition, and tops the first edition's page count by over 200 pages. Some of the new additions address relatively new packages, such as the datetime, dateutils, pytz, and decimal packages, while others focus on older packages that are waxing in their influence and popularity, such as Twisted. Many recipes are more polished, such as the "Synchronizing All Methods in an Object," which has an arguably more general purpose approach and an interesting discussion in the new edition.

Omissions are sometimes as interesting as inclusions in recipe books, but an interpretation of their significance can be difficult. The new edition dropped almost 100 of the first edition's recipes. In the "Distributed Programming" topic, the SOAP references in the first edition have disappeared, and a recipe for Twisted's Perspective Broker has surfaced. While the Perspective Broker is an interesting technology with an elegant cookbook example, the seeming judgement-SOAP is now less worth discussion than one of the Twisted project's packages-might raise some eyebrows. Similarly, Zope and the ZODB (Zope Object Database) are acknowledged as heavyweights in the introductions to their respective topics ("Web Programming" and "Persistence and Databases"). Zope 3 is even granted a rave review: "The new, revolutionary major release, Zope 3, makes Zope more Pythonic and powerful than ever." But not a single recipe can be found for either, in either edition. Perhaps that simply is indicative that the Zope community ought to pay more attention to the Cookbook website.

This returns us to the initial observation of this review: the cookbook is a community driven project, and thus reflects the personalities of the programmers who contributed to it, rather than necessarily to trends of the Python or IT community. But it also benefits from the energy and enthusiasm of the contributors who often have palpable excitement for the technologies they are demonstrating. This also makes me more interested in the book as a source for introductions than as a source for ready-made recipes.

If a picture is worth a thousand words, a working, explained example of a new package ought to be worth quite a few too. The cookbook is a fun browse and a fun introduction to other aspects of the Python language. While I have found myself using one or two of the recipes from the first edition, that use alone is not enough to justify the cover price. It is more compelling to me as a fun introduction to Python topics and approaches. In that light, I recommend it.
Comment | 
Was this review helpful to you?
Most Recent Customer Reviews
1.0 out of 5 stars NOT a cookbook!
A cookbook is a set of top-level dishes and concise instructions about how to prepare them.
The "Python Cookbook" is emphatically not that! Read more
Published 5 months ago by CEO in Illinois
3.0 out of 5 stars Not quite in the league of perl cook book
I was hoping to get something like the perl cook book, bu was a bit dissapointed. The book is less organized and less informative compared to the perl book. Read more
Published 8 months ago by Lars Christoffersen
5.0 out of 5 stars Great Reference Guide
Book provides numerous examples divided into logical groups (operations with text, numbers, databases etc.). It is easy to navigate and find helpful code. Read more
Published 13 months ago by Zoli
5.0 out of 5 stars Forces you to Learn!
I love this book, its categorized so nicely and you get down to brass tax. No need to beat around the bush here, it's brass tax folks and this book will help you roll on.
Published 20 months ago by Jesse B.
4.0 out of 5 stars Easy to read. Very easy to use.
Great book. It does a great job explaining how to code in a pythonic way. It's a great desktop reference for solving those problems that tend to pop up over and over again. Read more
Published on May 20, 2011 by Greg
4.0 out of 5 stars it simply gets you what you want fast
This is really what you want from a cookbook: it is fast and easy to understand and implement what you want. Read more
Published on February 8, 2011 by Louis
4.0 out of 5 stars Good book for quick solution to a problem
This book is a very good source to use as a starting point for coming up with solutions to various problems. The recipes presented are concise and explained well. Read more
Published on June 27, 2010 by Tamara Wauchope
5.0 out of 5 stars This book rocks!
This book rocks. 'Nuff said. Great examples, thought-out explanations, and lots of "Wow, I never knew Python could do that! Read more
Published on May 17, 2010 by Chad Cooper
3.0 out of 5 stars Out of date. Not very useful.
This book is in need of an update for Python 2.6/3.0 syntax. It covers the "new" Python 2.4.

I bought the book for a project in Python at work, but I never even... Read more
Published on April 1, 2009 by G. Norton
5.0 out of 5 stars Very useful book to see how to best address everyday problems
This is not a learning book, nor a reference book. It is a book that contains "recipes", descriptions of how to perform everyday issues, such as reading a file, sorting a... Read more
Published on March 16, 2009 by David Alan Tussey
Search Customer Reviews
Only search this product's reviews

What Other Items Do Customers Buy After Viewing This Item?


Forums

There are no discussions about this product yet.
Be the first to discuss this product with the community.
Start a new discussion
Topic:
First post:
Prompts for sign-in
 



So You'd Like to...



Look for Similar Items by Category