Issue 1441072: No simple example for pickle (original) (raw)

The docs for pickle lack a simple example of typical usage. The Example page has only an advanced example. I suggest something like this be added to the Usage or Examples page:

Here is a simple example that shows how to use pickle to save and restore a dictionary:

import pickle data = dict(a=1, b=2, c=[3,4,5], d='cheese') f=open('data.pickle', 'wb') pickle.dump(data, f) f.close()

f=open('data.pickle', 'rb') data2=pickle.load(f) f.close() data2 {'a': 1, 'c': [3, 4, 5], 'b': 2, 'd': 'cheese'}

Kent