saving and reloading variables for interactive work
Darren Dale
dd55 at cornell.edu
Wed Jul 28 16:19:29 EDT 2004
>
> I've done some poking though, and there a better way than that. It seems
> all picklable objects define a __reduce__ method, so you could generalize
> this check like this:
>
> def ispicklable(item):
> try:
> item.__reduce__()
> except KeyError,TypeError:
> return False
> return True
>
I think this may only be true for new-style classes, or objects that
pickle "is unfamiliar with". I tried calling this method for strings,
dicts, lists, and it complains that these are all unpicklable.
object().__reduce__() does work though.
I'll give it some thought.
More information about the Python-list
mailing list