Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21294 > unrolled thread

Re: pickle/unpickle class which has changed

Started byGelonida N <gelonida@gmail.com>
First post2012-03-07 01:22 +0100
Last post2012-03-07 01:22 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: pickle/unpickle class which has changed Gelonida N <gelonida@gmail.com> - 2012-03-07 01:22 +0100

#21294 — Re: pickle/unpickle class which has changed

FromGelonida N <gelonida@gmail.com>
Date2012-03-07 01:22 +0100
SubjectRe: pickle/unpickle class which has changed
Message-ID<mailman.450.1331079792.3037.python-list@python.org>
Hi Peter,

A related question.


Is there anyhing like a built in signature which would help to detect,
that one tries to unpickle an object whose byte code has changed?

The idea is to distinguish old and new pickled data and start some
'migration code' fi required


The only thing, that I thought about so far was adding an explicit
version number to each class in order to detect such situations.



On 03/06/2012 02:52 PM, Peter Otten wrote:
> Neal Becker wrote:
> 
>> What happens if I pickle a class, and later unpickle it where the class
>> now has added some new attributes?
> 
> - If the added attributes' values are immutable, provide defaults as class 
> attributes.
> 
> - Implement an appropriate __setstate__() method. The easiest would be
> 
> # untested
> def __setstate__(self, state):
>     self.__dict__.update(newattr1=42, newattr2=[])
>     self.__dict__.update(state)
> 

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web