Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'xml,': 0.05; 'apis': 0.07; 'json': 0.07; 'seemed': 0.07; 'buffer.': 0.09; 'objects.': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'obviously': 0.15; 'wed,': 0.15; '(but': 0.15; 'file,': 0.15; 'importing': 0.15; 'thu,': 0.15; 'api,': 0.16; 'buffers,': 0.16; 'egg': 0.16; 'enough.': 0.16; 'json,': 0.16; 'ported': 0.16; 'subject:make': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'yaml': 0.16; 'wrote:': 0.16; 'config': 0.18; 'module,': 0.18; 'tests.': 0.18; '>>>': 0.20; 'all,': 0.20; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; "aren't": 0.22; 'either.': 0.22; 'exists.': 0.22; 'parser': 0.22; 'parsing': 0.22; 'subject:request': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'wrote': 0.23; 'errors': 0.23; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'written': 0.24; 'testing': 0.25; 'idea': 0.26; 'defining': 0.27; 'format,': 0.27; 'said,': 0.27; 'message- id:@mail.gmail.com': 0.28; 'subject:/': 0.29; "i'm": 0.29; 'feature,': 0.29; 'obscure': 0.29; 'no,': 0.29; 'objects': 0.29; 'correct': 0.29; 'sense': 0.29; 'that.': 0.30; 'compared': 0.31; "can't": 0.32; 'class': 0.33; 'combination': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'another': 0.34; 'everyone': 0.34; 'weeks': 0.34; 'file': 0.34; 'received:google.com': 0.34; "i'll": 0.34; 'could': 0.35; 'files,': 0.35; 'protocol': 0.35; 'something': 0.35; 'but': 0.36; 'text': 0.36; 'basic': 0.36; 'cases': 0.36; 'subject:: ': 0.37; 'beyond': 0.37; 'correctly': 0.37; "won't": 0.38; 'say': 0.38; 'pm,': 0.39; 'build': 0.40; 'where': 0.40; 'learn': 0.60; 'even': 0.61; 'simple': 0.61; 'provide': 0.61; 'more': 0.62; 'needs,': 0.63; 'day.': 0.63; 'you.': 0.64; 'spend': 0.64; 'talking': 0.67; 'risk': 0.67; 'comparable': 0.84; 'face,': 0.84; 'limitations.': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'minute.': 0.91; 'received:mail-wi0-x229.google.com': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=oyTXkHeak64o/FIy1PBeQQbXP+wHzsCENHuelq4prgo=; b=BQsjb/vJNkPlAVddeY0ef0Xyw6G7LOwnAAEDIkfB9bMYs/xR4iY0Mb/F5ncAc3KzoC hzX/EW/4S4ovvWaVWX6wpeUM0BEmtIhAuK7PCRMhK/QBmVfbK7mgyh+AoasjJDqEz4XF 8JiViMKSZWzmDo/P/BH9Vwmc6gNpO0msThu/siMFL2/WIHpFeKlmCqoTz+XUdVJYcOVP XF8J/R/EpydKV3XtlBORRuG3RpperTZJ5cv2WTua6/FbpBk1v+cuAVSyzixI3TelBUhS aVHJClgayx9T/DEHOPx3wnrmgPHugKDSJsrbnvpuuTowaKvGUrdYDQow7iuubi4HbpTH 41KA== X-Received: by 10.194.21.232 with SMTP id y8mr13419682wje.36.1434001226646; Wed, 10 Jun 2015 22:40:26 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <5578feb6$0$12984$c3e8da3$5496439d@news.astraweb.com> References: <55778208$0$2899$e4fe514c@news2.news.xs4all.nl> <5577b46d$0$12975$c3e8da3$5496439d@news.astraweb.com> <5578053a$0$11102$c3e8da3@news.astraweb.com> <5578feb6$0$12984$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Wed, 10 Jun 2015 22:39:46 -0700 Subject: Re: enhancement request: make py3 read/write py2 pickle format To: "Steven D'Aprano" Cc: "comp.lang.python" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434001230 news.xs4all.nl 2829 [2001:888:2000:d::a6]:34312 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92455 Snipped aplenty. On Wed, Jun 10, 2015 at 8:21 PM, Steven D'Aprano wrote: > On Thu, 11 Jun 2015 08:10 am, Devin Jeanpierre wrote: > [...] >> I could spend a bunch of time writing yet another config file format, >> or I could use text format protocol buffers, YAML, or TOML and call it >> a day. > > Writing a rc parser is so trivial that it's almost easier to just write it > than it is to look up the APIs for YAML or JSON, to say nothing of the > rigmarole of defining a protocol buffer config file, compiling it, > importing the module, and using that. > -snip > > That's a basic, *but acceptable*, rc parser written in literally under a > minute. At the risk of ending up with egg on my face, I reckon that it's so > simple and so obviously correct that I can tell it works correctly without > even testing it. (Famous last words, huh?) I won't try to egg you. That said, you have to write tests. Also, everyone who uses it has to learn the format and API, and it may have corner cases you aren't aware of, it has to get ported to python 3 if you wrote it for python 2, the parsing errors are obscure and might need improvement, and so on. There's a place for this, but I suspect it is small compared to the place where it seemed like a good idea at the time. >>> Beyond simple needs, like rc files, literal_eval is not sufficient. You >>> can't use it to deserialise arbitrary objects. That might be a feature, >>> but if you need something more powerful than basic ints, floats, strings >>> and a few others, literal_eval will not be powerful enough. >> >> No, it is powerful enough. After all, JSON has the same limitations. > > In the sense that you can build arbitrary objects from a combination of a > few basic types, yes, literal_eval is "powerful enough" if you are prepared > to re-invent JSON, YAML, or protocol buffer. > > But I'm not talking about re-inventing what already exists. If I want JSON, > I'll use JSON, not spend weeks or months re-writing it from scratch. I > can't do this: > > class MyClass: > pass > > a = MyClass() > serialised = repr(a) > b = ast.literal_eval(serialised) > assert a == b I don't understand. You can't do that in JSON, YAML, XML, or protocol buffers, either. They only provide a small set of types, comparable to (but smaller) than the set of types you get from literal_eval/repr. -- Devin