Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'indexing': 0.07; 'abstraction': 0.09; 'subject:test': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'exploits': 0.16; 'finney': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'command': 0.22; 'cc:addr:python.org': 0.22; 'fixed.': 0.24; 'skip:e 30': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "skip:' 10": 0.31; '25,': 0.31; "d'aprano": 0.31; 'equality': 0.31; 'steven': 0.31; 'writes:': 0.31; 'anyone': 0.31; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'words,': 0.36; "i'll": 0.36; 'should': 0.36; 'clear': 0.37; 'ben': 0.38; 'fact': 0.38; 'pm,': 0.38; 'exclusive': 0.81; 'history,': 0.84; 'sometimes.': 0.84; 'subject::': 0.85; 'thing,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zRlUDJIjfnRFipivb3x9WZYhheZGnFwlouFj1S1F3rs=; b=x+EcVwsFK55B0nmyZbJ7QueVuKwPLBxowyuInExqHG7oWPf1XXczEqvteJo+60Kcbk 4qfIb7ELayoQoaZ+cbxdC4LuUp/Za7fV2IbjnNLJ6IWcot6hi4okTuyUkebEhaCj6NmR gZ7ZZHb0nIhVY+y1AKqvODBMtfYWG+pMeExY6H+vA56aQpSpIPf50ed5o3WYkQ8+ccsr 2uRIlJMP6nVhAHbLHRy6ChTyWN9k9iUD/u2DpS/6gxvZvYnso9X0JRZcCXjqVPtZ5ACS 4PbdMrVhiFL523p7+TuKp6Ta47F/Pb+I7Vc/V54O6aCo7d/mX5GElAMrojpLGbWkrGV1 oQ4Q== MIME-Version: 1.0 X-Received: by 10.152.22.194 with SMTP id g2mr13375238laf.33.1414276447120; Sat, 25 Oct 2014 15:34:07 -0700 (PDT) In-Reply-To: <85y4s33ml1.fsf@benfinney.id.au> References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> <7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com> <878uk6x5nd.fsf@elektro.pacujo.net> <544a1016$0$13000$c3e8da3$5496439d@news.astraweb.com> <544b2f15$0$12978$c3e8da3$5496439d@news.astraweb.com> <85y4s33ml1.fsf@benfinney.id.au> Date: Sat, 25 Oct 2014 15:34:06 -0700 Subject: Re: (test) ? a:b From: Dan Stromberg To: Ben Finney Content-Type: text/plain; charset=UTF-8 Cc: Python List 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414276449 news.xs4all.nl 2880 [2001:888:2000:d::a6]:53151 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79688 On Sat, Oct 25, 2014 at 1:45 PM, Ben Finney wrote: > Steven D'Aprano writes: >> title = ('Mr', 'Ms')[person.sex == 'F'] >> >> which should be clear to anyone who understands indexing in Python and >> that True == 1 and False == 0. > > I consider it an accident of history, and one which should not be > necessary to understand Python code. > > In other words, I consider code which exploits the equality of True with > 1, or False with 0, is code with a leaky abstraction and should be > fixed. I don't like the (a, b)[True] thing, but I use the fact that True is 1 and False is 0 sometimes. EG, if I have 3 mutually exclusive command line options, I'll do something like: if option_a + option_b + option_c != 1: sys.stderr.write('{}: -a, -b and -c are mutually exclusive\n'.format(sys.argv[0]))