Type-checking unpickled objects

Gordon Airporte JHoover at fbi.gov
Fri Nov 18 15:27:56 EST 2005


I have this class, and I've been pickling it's objects as a file format 
for my program, which works great. The problems are a.) how to handle 
things when the user tries to load a non-pickled file, and b.) when they 
load a pickled file of the wrong class.

a. I can handle with a general exception I guess. I just tried to 
pickle.load() a .pyc and it failed with a 'KeyError' exception - however 
that works. It might do that every time, it might not.

Regarding b., if I type check I simply get the 'instance' type, which 
doesn't get me all of the way there because I might have an instance of 
the wrong class. I can't find any sort of __type__ attribute to set in 
the objects. Perhaps I should use __str__?



More information about the Python-list mailing list