How to cPickle dump and load separate dictionaries to the same file?

Viewed 40787

I have a process which runs and creates three dictionaries: 2 rather small, and 1 large.

I know I can store one dictionary like:

import cPickle as pickle
with open(filename, 'wb') as fp:
  pickle.dump(self.fitResults, fp)

What I'd like to do is store all 3 dictionaries in the same file, with the ability to load in the three dictionaries separately at another time. Something like

with open(filename, 'rb') as fp:
  dict1, dict2, dict3 = pickle.load(fp)

Or even better just load the first two dictionaries, and make it optional whether to load the third (large) one. Is this possible or should I go about this in a completely different way?

3 Answers
Related