Message54746
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 |
|
Date |
User |
Action |
Args |
2007-08-23 16:11:43 | admin | link | issue1441072 messages |
2007-08-23 16:11:43 | admin | create | |
|