Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'json': 0.07; '__init__': 0.09; 'attributes': 0.09; 'defines': 0.09; 'definition,': 0.09; 'lost.': 0.09; 'methods,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'refresh': 0.09; 'run,': 0.09; 'subject:using': 0.09; 'stored': 0.12; 'changes': 0.15; 'attributes,': 0.16; 'created.': 0.16; 'ignoring': 0.16; 'instances,': 0.16; 'objects.': 0.16; 'properties,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'separate': 0.22; 'header:User- Agent:1': 0.23; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'implicit': 0.31; 'invoke': 0.31; 'josh': 0.31; 'pickle': 0.31; 'class': 0.32; 'knowledge': 0.35; 'definition': 0.35; 'but': 0.35; 'instances': 0.36; 'object,': 0.36; 'method': 0.36; 'possible': 0.36; 'being': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: Storing instances using jsonpickle Date: Wed, 03 Sep 2014 16:52:50 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 18.189.8.234 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409777587 news.xs4all.nl 2929 [2001:888:2000:d::a6]:53183 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77506 On 9/3/14 4:32 PM, Josh English wrote: > I am using jsonpickle to store instances of an object into separate data files. > > If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new attributes, methods, or properties, are lost. > > I think this is happening because JSON is internalizing the class definition, ignoring the updates. Is this true? Is it possible to refresh JSON's knowledge of a class? > Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are not being created. This is one of the reasons that people avoid pickle: being completely implicit is very handy, but also fragile. -- Ned Batchelder, http://nedbatchelder.com