Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Using 'Or' Date: Sun, 17 Jan 2016 10:15:29 +1100 Lines: 39 Message-ID: References: <48smy.82436$Dn6.27537@fx46.am4> <569abbf3$0$1603$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de RIIhOVLOIFq/u7KhkZIqWw+QK2A803Y4VMn7pLtoadag== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'dict': 0.09; 'jan': 0.11; '2016': 0.16; 'bars': 0.16; 'conditional': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '"you': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; '(or': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'operators': 0.29; 'received:209.85.213.174': 0.29; 'print': 0.30; 'code': 0.30; 'etc.)': 0.32; 'statement': 0.32; 'maybe': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'skip:p 30': 0.35; 'sometimes': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:209.85.213': 0.37; 'skip:v 20': 0.38; 'received:209': 0.38; 'test': 0.39; 'enough': 0.39; 'hope': 0.61; 'default': 0.61; 'yes': 0.62; 'decided': 0.66; 'production': 0.67; '01:06': 0.84; 'chrisa': 0.84; 'subject:Using': 0.84; 'to:none': 0.91; 'why?': 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:cc :content-type; bh=Ukgw01ASKEGpEh7iH41F/RBVyZ71G87P80WhHVZkAmo=; b=IMC/nFeyUrbFAOaadTWhgm6I4AbU0fMeHsyXROvtmzAGcWiopUfl8FtCLqcpHiPAxy co4vejpNwQ1ik/d6PWN6rPOvpp9XbxnEOHD9Pfm0kD0c3F6yVymq246LNSv8pwp0ivy0 1yUylbAjVTv+YDQ7FKPsSvBMskkDcXH9TqtVJ+CGkjz9IF3zG/lbeENo2LAItWHTbJOk cmVe2UuHDr/30/LYdzMrgR62oavIU4AQ8LWnGIXCncRb5pgjOlqZcTY/0CalWiH71KED 1BOzy4aPnwEazFCYT+3VWWZK8bR9CFiHvb6kyLoNB7m2VxoI8RqNP3X8ttLGMgVeCEaT MImA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=Ukgw01ASKEGpEh7iH41F/RBVyZ71G87P80WhHVZkAmo=; b=YUjrb1+jNv59KGKp/5MqrilsMYAqdUKofuAEP3dplNPWXCxaQlJIgrsUgHKAD/lNcH fKUFJj+meuN8QhXWAjOoN1YaIK5bMXR4L+9pxN+2ooo+aKQcj9nZd5nrR1ewYFgjE+kS 8iTwMKXg+oAq3v/4VEzk3tXzq5BorKV2K99Bbbu3wvSBR1qfIRsGnicQ3lBkogd99laH 3XKTR8VK0m5T5W80zWIu6Mfw5j/uECpzNRanSeyHpQydPZimtQu0TeoaHGDbTWjtq/gE E5j7g+8e2f4dBfnhJsB2G03z1FTz+BODxdVYJRHeSTat3oG+KFjpSYF4FAsGupZcSj+q p2mg== X-Gm-Message-State: AG10YOSKlC4ly/4ol4w132C4LkHKIqrMrjLvop2rsZapnf9sqH/IZknPHjCOkyU1QLF7uhXT1c7OWK2256NJ+w== X-Received: by 10.50.66.179 with SMTP id g19mr5141974igt.94.1452986129952; Sat, 16 Jan 2016 15:15:29 -0800 (PST) In-Reply-To: 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: , Xref: csiph.com comp.lang.python:101825 On Sun, Jan 17, 2016 at 9:47 AM, Alister wrote: > On 16/01/16 21:53, Steven D'Aprano wrote: >> >> On Sun, 17 Jan 2016 01:06 am, Alister wrote: >> >>> Conditional operators (or and not == etc.) need to be used in a test >> >> >> Technically, that is incorrect. > > yes but the op is confused in his usage enough at present Adding a falsehood sometimes helps reduce the confusion, but in this case it just worsens things, I think. >>> how else would you expect you print statement to be able to decided >>> which to print? >> >> >> >> default = "I like Brussels sprouts." >> message = random.choice(["", "I like boiled cabbage."]) >> print( message or default ) >> >> >> > I hope I never see production code like that Why? Okay, maybe not with a random.choice, but what about dict lookup? specific_messages = { "foo": "You use a new foo.", "bar": "You sing a few bars of music.", } print(specific_messages.get(kwd) or "You {} vehemently.".format(kwd)) Seems fine to me. ChrisA