How to pickle a subclass of tuple?
glc at well.com
Fri Jun 4 18:09:25 CEST 2004
On Thu, 03 Jun 2004 19:26:37 +0300, Christos "TZOTZIOY" Georgiou
<tzot at sil-tec.gr> wrote:
>__getstate__ is easy:
> return tuple(self)
> return self
>seems to work, as far as Pickle.dump is concerned. The problem is, how
>one writes a __setstate__ for an immutable class?
You'll probably need to use some of the extended pickle protocol hooks
In particular, you can give your subclass a __reduce__ implementation, which
pretty much gives you complete control over how it is pickled and unpickled.
More information about the Python-list