how to go around non-picklable object types?

inhahe inhahe at gmail.com
Mon Sep 15 13:36:14 EDT 2008


There are certain types of objects that can't be pickled, like file objects. 
My question is how could I pickle a hierarchy while automatically skipping 
all such objects instead of just aborting the pickle when it comes across 
one.

The only thing I can think of is to make my own classes that wrap file 
objects and so forth and use __getstate__ to leave out the underlying file, 
etc. objects, or to set __getstate__ for every class that holds an offending 
object type and filter such objects out of dictionaries when I pickle those. 
And I don't even have a list of common object types that would make it 
break.

Is there a better way?  thx..






More information about the Python-list mailing list