Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.09; 'false,': 0.09; 'false.': 0.09; 'happen,': 0.09; 'oh,': 0.09; 'true)': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'notation': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "they'll": 0.31; 'probably': 0.32; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'possible': 0.36; 'either': 0.39; 'skip:t 30': 0.61; 'simple': 0.61; 'become': 0.64; 'calls,': 0.84; 'to:none': 0.92 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=SlxhZjYf2D7LuSfv4NCqTk9WgyqoI2AzE5ZSZDPZNu0=; b=bH93QE3JoLp74Q3z4EhjRo8L32bZ/V+azP8mxyTEq9qJYorHYWn7FU0qvdNJp5YtCM hXrO7e305vIOxut0rD1Lijj/AmWYTYYtmdF8iuCE0KxF8hobLBMs5AyaTH4XZeVjQSFD 6r/Cd7WyrAvVuQktid8sN1FUBBa76XNSWZH2tPkscgEWurhOUVdM53OtVl+IvNMBvXj0 3iYqEa2AMP1jqIvNFj6npGjGUUmoOG568I4gRS63th+ahhA3pYb+r3R14J4W9DyL8VK2 CaqFfjYTzpKZgW0GDqvIdCz3ChPKgvaTcZGf0uUAQSP0FY/R0fMn6gM3TfVevwCmapK7 xWiA== MIME-Version: 1.0 X-Received: by 10.68.221.233 with SMTP id qh9mr91485755pbc.103.1388707678798; Thu, 02 Jan 2014 16:07:58 -0800 (PST) In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Date: Fri, 3 Jan 2014 11:07:58 +1100 Subject: Re: Ifs and assignments 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388707688 news.xs4all.nl 2886 [2001:888:2000:d::a6]:50774 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63011 On Fri, Jan 3, 2014 at 11:06 AM, Chris Angelico wrote: > Pass any object through truth() and it'll either stay the same (if > it's true) or become this object (if it's false). You can then carry > on with other method calls, and they'll all happily return false. > > result = ( > truth(re1.match(string)).group(0) or > truth(re2.match(string)).group(0) or > truth(re3.match(string)).group(0) or > default_value > ) Oh, just thought of a possible snag. Since an empty string comes up as false, this exact notation would fail if the re can match nothing. But you probably know if it's possible for that to happen, so don't use this simple short-hand. :) ChrisA