Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '#if': 0.05; '*not*': 0.07; 'clause': 0.07; 'executed': 0.07; 'python': 0.09; '*is*': 0.09; 'none.': 0.09; 'noted,': 0.09; 'result;': 0.09; 'both.': 0.16; 'made-up': 0.16; 're.search(': 0.16; 'subject:fails': 0.16; 'subject:when': 0.16; 'wrote:': 0.17; 'logical': 0.22; 'kevin': 0.23; 'testing': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; '2.3': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'testing.': 0.29; "skip:' 20": 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'nov': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; '20,': 0.65; 'truth': 0.75; 'fortunately,': 0.84; 'subject:else': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=8QwAjAKGnU/c9VgGieQQmGE2XwpsdirY7QapJXV/i6o=; b=oYtXQiD/gtFrvY5iHrCodzAqKDqpzMQ1cQOFkZCHyUfS3EAotc13aj8HKNFb/HMeV+ P2FYSYx361ZaI0OeOuTjOC01y6EZVo6t1ZjIiKt5L85Z/IKbQb62APsOj6WTx+tHAjwo xJXOFi4CToaZqqG9rHC82kFueI+s88edHG12VhQtsrCyIER8ZaCHLfuQ1dIBJbZwI6B5 B4dnTyMj/A3AVgG7MNcDB9smtXaOnue6NWFSHO9f7+juZXtkYqZ/NdW7klsSTvN9vYkC kyMoD5ce9clfXU+2MCpIaka/kjrEbNyLT39iPJviqp+LiI28nkyVENI4bn471lA6DiaZ S3tg== MIME-Version: 1.0 In-Reply-To: References: <50aadbe6$0$29983$c3e8da3$5496439d@news.astraweb.com> <50aadcf0$0$29983$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Tue, 20 Nov 2012 12:39:10 -0700 Subject: Re: re.search when used within an if/else fails To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353440383 news.xs4all.nl 6845 [2001:888:2000:d::a6]:55711 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33650 On Tue, Nov 20, 2012 at 12:37 PM, Ian Kelly wrote: > On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote: >> #if re.search( "rsrvd", sigName ) : #version a >> #if re.search( "rsrvd", sigName ) == None : #version b >> if re.search( "rsrvd", sigName ) is None : #version bb >> print sigName >> newVal = "%s%s" % ('1'*signal['bits'] , newVal ) >> #else: #version c >> if re.search( "rsrvd", sigName ) != None : #version d >> print sigName >> newVal = "%s%s" % ( '0'*signal['bits'],> newVal ) >> >> i can use either version a/b the else clause (version c) will not execute. >> fortunately, with version bb, the else clause will execute!! > > There must be some other difference in your testing. I don't have > Python 2.4 available, but I tried your version a in both Python 2.3 > and 2.5 using made-up values for sigName, and the else clause is > executed in both. It should be noted, however, that version a is the logical *inverse* of both b and bb. With version a, you're testing for the logical truth of the re.search result; it will be true if it is *not* None. With the other two you are testing that the result *is* None.