[Tutor] problem with unpickling an object

Kent Johnson kent37 at tds.net
Mon Jun 5 12:12:24 CEST 2006


 From a quick read of the docs, it looks like you should set the 
unpickler's find_global attribute to a function you define. This 
function can first attempt to load the desired class (see 
pickle.find_class() for an example). If the load fails, then return a 
placeholder class that you define.

This won't give exactly the result you ask for, instead of None in the 
dictionary you will have instances of the placeholder. You could then 
post-process the dict to change the placeholder instances to None if you 
like.

Kent

Yi Qiang wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi list,
> I am pickling a dictionary that has as one of it's values an object I
> create on the fly.  When I try to unpickle that object, cPickle attempts
> to recreate that object but of course that module is not present
> anymore.  How can I just make it skip over that particular key and just
> set the value to None?
> 
> Thanks,
> - --
> Yi Qiang (yi at yiqiang.net)
> Web: http://www.yiqiang.net
> Tel: (206) 661-8469
> PGP: 0xB515564B
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> 
> iD8DBQFEg8k0tXlIMrUVVksRAt2tAJ4hq/3KmDo6BbS3p3AwhKf4Ga52DQCfXFtx
> GERJqs3IcLXuKaRcq/zuRUE=
> =SEZ6
> -----END PGP SIGNATURE-----
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 




More information about the Tutor mailing list