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


Groups > comp.lang.python > #21294

Re: pickle/unpickle class which has changed

From Gelonida N <gelonida@gmail.com>
Subject Re: pickle/unpickle class which has changed
Date 2012-03-07 01:22 +0100
References <jj508q$i1q$1@dough.gmane.org> <jj54q0$mui$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.450.1331079792.3037.python-list@python.org> (permalink)

Show all headers | View raw


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)
> 

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web