Re: pickle/unpickle class which has changed

2012-03-07 Thread Gelonida N
On 03/07/2012 09:04 AM, Peter Otten wrote: > Gelonida N wrote: > If you know in advance that your class will undergo significant changes you > may also consider storing more stable data in a file format that can easily > be modified, e. g. json. > Good point, that's what I'm partially doing. I

Re: pickle/unpickle class which has changed

2012-03-07 Thread Peter Otten
Gelonida N wrote: > 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? No. The only thing that is stored is the "protocol", the format used to store the data. > The idea is to distinguish old and new pickle

Re: pickle/unpickle class which has changed

2012-03-06 Thread Gelonida N
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

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Neal Becker wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >>> What happens if I pickle a class, and later unpickle it where the class now has added some new attributes? >>> >>> Why don't you try it? >>> >>> py>

Re: pickle/unpickle class which has changed

2012-03-06 Thread Neal Becker
Peter Otten wrote: > Steven D'Aprano wrote: > >> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >> >>> What happens if I pickle a class, and later unpickle it where the class >>> now has added some new attributes? >> >> Why don't you try it? >> >> py> import pickle >> py> class C: >> .

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > Why don't you try it? > > py> import pickle > py> class C: > ... a = 23 > ... > py> c = C()

Re: pickle/unpickle class which has changed

2012-03-06 Thread Steven D'Aprano
On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? Why don't you try it? py> import pickle py> class C: ... a = 23 ... py> c = C() py> pickled = pickle.dumps(c) py> C.b = 42 #

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
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 # unte

pickle/unpickle class which has changed

2012-03-06 Thread Neal Becker
What happens if I pickle a class, and later unpickle it where the class now has added some new attributes? -- http://mail.python.org/mailman/listinfo/python-list