1. Home
  2. Computing & Technology
  3. Python
Python Blog

From Al Lukaszewski, for About.com

Python Object Persistence: pickle, shelve, and marshal

Wednesday August 29, 2007
There are three modules for object persistence within Python: pickle, shelve, and marshal. Given Python's golden rule that there should be one -- and only one -- way to do anything, the situation begs the question of why there are three modules for persistence. As with most modules and functions, what you use depends on what you need. In fact, each module has a very precise design for very specific purposes.

The pickle module saves objects as streams of bytes. Each data file holds exactly one stream. This simplicity saves you from the overhead of a dictionary object when one is not needed.

The shelve module, on the other hand, saves its data as a dictionary database. This saves you from a multiplicity of object files and the administration inherent in their creation and maintenance.

The marshal module, however, is not meant to be employed for external object persistence. It is, rather, intended solely for internal use. To learn more about its precise purpose, see the Python documentation.
Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.