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


Groups > comp.lang.python > #45623

Re: Question about ast.literal_eval

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.045
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'subsequent': 0.05; 'subject:Question': 0.07; '(aka': 0.09; 'components,': 0.09; 'subject:skip:a 10': 0.09; 'python': 0.11; 'anyway': 0.14; '(and,': 0.16; 'bracket': 0.16; 'check.': 0.16; 'discarded': 0.16; 'downside': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'grouped': 0.16; 'messy': 0.16; 'mixture': 0.16; 'nesting': 0.16; 'nightmare': 0.16; 'placeholder': 0.16; 'pushed': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'separate': 0.22; 'entries': 0.24; 'mon,': 0.24; 'sort': 0.25; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'points': 0.29; 'evaluation': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'gives': 0.31; 'getting': 0.31; '(unless': 0.31; 'option': 0.32; 'implemented': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'described': 0.36; 'much.': 0.36; 'entry': 0.36; 'too': 0.37; 'implement': 0.38; 'loss': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'that,': 0.38; 'little': 0.38; 'explain': 0.39; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'range': 0.61; "you're": 0.61; 'first': 0.61; "you've": 0.63; 'costs': 0.63; 'group,': 0.63; 'choose': 0.64; 'our': 0.64; 'more': 0.64; 'approved': 0.65; 'finally': 0.65; 'here': 0.66; 'six': 0.68; '20,': 0.68; 'combining': 0.68; 'frank': 0.68; 'overall': 0.69; 'safe': 0.72; 'bulk': 0.74; 'cut': 0.74; "'and'": 0.84; 'complexity': 0.84; 'everything.': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=Di7Kz5njXk+1NZhDje/Kb1HN5jdA/uVIxdYyVVoCgzU=; b=0Q5e3uE1aSBFrqpRAhYoNDsVl9p59U83xvw3lMw/f2z/BIOKvZa8N5DGcZysnToN5n GoOPwb67jnHGh4g5MQEEM7Ow+WVBJAbIC3qFXRm77DdsYMiNWGF0cxIBxTVfguam6bt9 erpleov0cswQr/EFsnKB9f41K/nHGzCaqXStA00r17kiqzfPaQ0Dth4ghAwHIDtnyjlD k3WTClbNWha3XJtwrZ0M7t8m1Obt+gUe2OUTHFboZUrl4omKK93DznAlSw3I+vrrirnt d4e5BO38ujw7HMMMBsMncI1TD6RK5RMoP9wv2+/oM/5bc0yRBooCbeEutWtDRc0DtrJw +nNw==
MIME-Version 1.0
X-Received by 10.52.65.238 with SMTP id a14mr13050015vdt.24.1369066427428; Mon, 20 May 2013 09:13:47 -0700 (PDT)
In-Reply-To <knd88q$mo9$1@ger.gmane.org>
References <knci07$jol$1@ger.gmane.org> <BLU176-W37EB377C73CD6D7306247DD7AF0@phx.gbl> <knckj0$cft$1@ger.gmane.org> <CAPTjJmpb073XFH5ksNhzRyAJNSJF=6WNq5pGzed4PXqBrJBN=A@mail.gmail.com> <knclk6$lva$1@ger.gmane.org> <knd88q$mo9$1@ger.gmane.org>
Date Tue, 21 May 2013 02:13:47 +1000
Subject Re: Question about ast.literal_eval
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.1890.1369066814.3114.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369066814 news.xs4all.nl 15865 [2001:888:2000:d::a6]:42524
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45623

Show key headers only | View raw


On Mon, May 20, 2013 at 11:26 PM, Frank Millman <frank@chagford.com> wrote:
> 0 - for the first entry in the list, the word 'check' (a placeholder - it is
> discarded at evaluation time), for any subsequent entries the word 'and' or
> 'or'.
>
> 1 - left bracket - either '(' or ''.
>
> 5 - right bracket - either ')' or ''.

I think what you have is safe, but extremely complicated to work with.
Six separate pieces, and things have to be in the right slots... I
think you've spent too many "complexity points" on the above three
components, and you're getting too little return for them. What
happens if the nesting is mucked up? Could get verrry messy to check.

Combining multiple conditions with a mixture of ands and ors is a
nightmare to try to explain (unless you just point to the Python docs,
which IMO costs you even more complexity points); the only safe option
is to parenthesize everything. The system I pushed for at work (which
was finally approved and implemented a few months ago) is more or less
this: conditions are grouped together into blocks; for each group, you
can choose whether it's "all" or "any" (aka and/or), and you choose
whether the overall result is all-groups or any-group. That still
costs a few complexity points (and, btw, our *actual* implementation
is a bit more complicated than that, but I think we could cut it down
to what I just described here without loss of functionality), but it
gives the bulk of what people will actually want without the
complexities of point-and-click code.

The downside of that sort of system is that it requires a two-level
tree. On the flip side, that's often how people will be thinking about
their conditions anyway (eg using a pair of conditions ">" and "<" to
implement a range check - conceptually it's a single check), so that
won't cost too much.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about ast.literal_eval Chris Angelico <rosuav@gmail.com> - 2013-05-21 02:13 +1000

csiph-web