Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.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.042 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'dan': 0.09; 'subject:test': 0.09; 'cc:addr:python-list': 0.11; 'boolean': 0.16; 'fine.': 0.16; 'finney': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guess.': 0.16; 'readable': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'options.': 0.19; 'command': 0.22; 'cc:addr:python.org': 0.22; 'skip:e 30': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'writes:': 0.31; "we're": 0.32; 'something': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'leads': 0.36; "i'll": 0.36; 'operating': 0.37; 'ben': 0.38; 'numbers': 0.61; 'matter': 0.61; 'more': 0.64; '26,': 0.68; 'exclusive': 0.81; 'treating': 0.84; 'subject::': 0.85; 'to:none': 0.92; 'opt': 0.97 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:cc :content-type; bh=PFlo1eE78+LO7D7JIEqQyL5CEsxHg7xayN4G7Am2yVE=; b=EgTABWjCjw3g9Yp7vAbue/u5cRVfwwN1e0c+WWC7+aNbSuyvsZXISo+N3sVyy0tvQE hz5GXhauJHbBG0xwfj3mmBmSkloUjKc/WsgJHEwxPHF4Pm+jDcw+SBgTflP9Z1YS/jn6 8LOBUA8YSdwTztbA6tXRbCFdWlJOIhDTV3rXMDfZoeYgUyBDC9OPxDCCKYL5rF9ndj6z RELt2LJQCeb50GBTJ0sHvkkyzgBY5NjL3/NnPB7nFSK6vCK8EH9oIpPgXRWYOlwNPpqr 16bWlNN6RC4rwgEu8pi0uJPs2tJGDt3HOkZKxnaJ4PNPGsZWt8/9sWF6d53zUvbMlaOa UZMg== MIME-Version: 1.0 X-Received: by 10.107.37.15 with SMTP id l15mr13426559iol.40.1414281700586; Sat, 25 Oct 2014 17:01:40 -0700 (PDT) In-Reply-To: <85tx2r3dv3.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> <85tx2r3dv3.fsf@benfinney.id.au> Date: Sun, 26 Oct 2014 11:01:40 +1100 Subject: Re: (test) ? a:b From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 1414281704 news.xs4all.nl 2906 [2001:888:2000:d::a6]:39945 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79693 On Sun, Oct 26, 2014 at 10:53 AM, Ben Finney wrote: > Dan Stromberg writes: > >> 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])) > > That is an excellent illustration of why exploiting this accidental > property of True and False leads to obfuscated code. The above test > gives me no clue that we're operating on boolean values, nor that we're > testing for exclusive options. Would it be more readable thus? if len([opt for opt in (option_a, option_b, option_c) if opt]) != 1: Because that's what it's doing. I think treating bools as numbers is fine. Matter of opinion I guess. ChrisA