Chapter Persistence and Databases

Serializing Data Using the marshal Module Recipe 7.2. Serializing Data Using the pickle and cPickle Modules Recipe 7.3. Using Compression with Pickling Recipe 7.4. Using the cPickle Module on Classes and Instances Recipe 7.5. Holding Bound Methods in a Picklable Way Recipe 7.6. Pickling Code Objects Recipe 7.7. Mutating Objects with shelve Recipe 7.8. Using the Berkeley DB Database Recipe 7.9. Accesssing a MySQL Database Recipe 7.10. Storing a BLOB in a MySQL Database Recipe 7.11....

Organization

Each chapter is devoted to a particular kind of recipe, such as algorithms, text processing, databases, and so on. The 1st edition had 17 chapters. There have been improvements to Python, both language and library, and to the corpus of recipes the Python community has posted to the cookbook site, that convinced us to add three entirely new chapters on the iterators and generators introduced in Python 2.3 on Python's support for time and money operations, both old and...

With this enriched version of Borg the examples output changes to

The Singleton Design Pattern has a catchy name, but unfortunately it also has the wrong focus for most purposes it focuses on object identity, rather than on object state and behavior. The Borg design nonpattern makes all instances share state instead, and Python makes implementing this idea a snap. In most cases in which you might think of using Singleton or Borg, you don't really need either of them. Just write a Python module, with functions and module-global variables, instead of defining a...