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


Groups > comp.lang.python > #21294

Re: pickle/unpickle class which has changed

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'defaults': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'class,': 0.15; 'method.': 0.15; 'tries': 0.15; 'attributes.': 0.16; 'immutable,': 0.16; 'subject:which': 0.16; 'question.': 0.16; 'wrote:': 0.18; 'later': 0.19; 'detect': 0.21; 'appropriate': 0.22; 'header:In-Reply-To:1': 0.22; 'byte': 0.24; 'code': 0.26; 'explicit': 0.29; 'class': 0.29; 'pm,': 0.29; 'version': 0.32; 'values': 0.32; 'idea': 0.32; 'implement': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'object': 0.33; 'header:X-Complaints-To:1': 0.34; 'easiest': 0.34; 'subject:/': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'happens': 0.38; 'skip:_ 10': 0.38; 'some': 0.38; 'data': 0.38; 'received:de': 0.39; 'to:addr:python.org': 0.40; 'situations.': 0.73; '02:52': 0.84; 'distinguish': 0.84; 'otten': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Gelonida N <gelonida@gmail.com>
Subject Re: pickle/unpickle class which has changed
Date Wed, 07 Mar 2012 01:22:46 +0100
References <jj508q$i1q$1@dough.gmane.org> <jj54q0$mui$1@dough.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host unicorn.dungeon.de
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 ""
In-Reply-To <jj54q0$mui$1@dough.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.450.1331079792.3037.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331079792 news.xs4all.nl 6914 [2001:888:2000:d::a6]:49170
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21294

Show key headers only | 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