Retrieving a partial pickle

Gabriel Genellina gagsl-py2 at
Sat Jul 18 06:13:18 CEST 2009

En Fri, 17 Jul 2009 21:43:21 -0300, Zac Burns <zac256 at> escribió:

> I have a large pickle file, which happens to be a list with lots of
> objects in it.
> What sort of things can I do without unpickling the whole object?
> I would particularly like to retrieve one of the elements in the list
> without unpicking the whole object.

I'm afraid you can't do that, in general. A pickle is actually *code* for  
a stack-based machine; you have to execute all the previous instructions  
to have a sane stack contents; it's not possible (at least, not easily)  
just to jump in the middle of the pickle and execute just a section.

> If the answer is not specific to lists that would be useful (works on
> getting items in a dictionary, or doing introspection on the objects
> or whatever)

The pickletools module might be a starting point: -- Try the Python Cookbook  

Gabriel Genellina

More information about the Python-list mailing list