Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed3a.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'dan': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:test': 0.09; 'language.': 0.14; 'boolean': 0.16; 'fine.': 0.16; 'finney': 0.16; 'guess.': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'options.': 0.19; 'fit': 0.20; 'command': 0.22; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'own.': 0.24; 'skip:e 30': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'testing': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'gives': 0.31; 'writes:': 0.31; "we're": 0.32; 'something': 0.35; 'test': 0.35; 'false': 0.36; 'leads': 0.36; 'set.': 0.36; "i'll": 0.36; 'operating': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'numbers': 0.61; 'matter': 0.61; 'our': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; '26,': 0.68; 'exclusive': 0.81; 'horrible': 0.84; 'treating': 0.84; 'subject::': 0.85; 'opt': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: (test) ? a:b Date: Sun, 26 Oct 2014 01:09:50 +0100 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> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-176-229.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414282207 news.xs4all.nl 2956 [2001:888:2000:d::a6]:42678 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79695 On 26/10/2014 01:01, Chris Angelico wrote: > 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 > Horrible IMHO, it just doesn't fit in my mind set. Still each to their own. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence