Retrieving a partial pickle

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jul 18 00:13:18 EDT 2009


En Fri, 17 Jul 2009 21:43:21 -0300, Zac Burns <zac256 at gmail.com> 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:  
http://docs.python.org/library/pickletools.html -- Try the Python Cookbook  
too http://code.activestate.com/recipes/langs/python/

-- 
Gabriel Genellina




More information about the Python-list mailing list