Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.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; 'explicitly': 0.05; 'json': 0.07; 'suppose': 0.07; 'wednesday,': 0.07; '__init__': 0.09; 'attributes': 0.09; 'converts': 0.09; 'defines': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'run,': 0.09; 'subject:using': 0.09; '6:30': 0.16; 'created.': 0.16; 'dictionary.': 0.16; 'encoders': 0.16; 'json,': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'work,': 0.20; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'decide': 0.24; 'looks': 0.24; 'sort': 0.25; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'code': 0.31; 'implicit': 0.31; 'invoke': 0.31; 'josh': 0.31; 'object.': 0.31; 'pickle': 0.31; 'this.': 0.32; 'another': 0.32; 'but': 0.35; 'version': 0.36; 'method': 0.36; 'should': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'days': 0.60; 'even': 0.60; 'ago.': 0.61; 'new': 0.61; 'chance': 0.65; 'frustrated': 0.68; 'batchelder': 0.84; 'typically,': 0.84 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 22:18:29 -0400 References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409797129 news.xs4all.nl 2930 [2001:888:2000:d::a6]:49785 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77522 On 9/3/14 6:30 PM, Josh English wrote: > On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > >> 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. >> > > I seem to remember having this exact same frustration when I used pickle and shelve 15 years ago. I had hoped to have another way around this. I spent over a decade trying to make an XML-based database work, in part because of this limitation. > > Some days I get so frustrated I think the only data structure I should ever use is a dictionary. > > I suppose to make this sort of thing work, I should look at creating custom json encoders and decoders. > Typically, you need to decide explicitly on a serialized representation for your data. Even if it's JSON, you need to decide what that JSON looks like. Then you need to write code that converts the JSON-able data structure (dict of lists, whatever) into your object. Often a version number is a good idea so that you have some chance of using old data as your code changes. -- Ned Batchelder, http://nedbatchelder.com