Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33650

Re: re.search when used within an if/else fails

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 <ian.g.kelly@gmail.com>
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 <CALwzidmQH=4jU5cntY8zMK1ZB564Apm+FPp2b0bxpF6PbFYJPQ@mail.gmail.com>
References <f0f27287-17ea-4fa5-ad26-ad2b6d3c0031@googlegroups.com> <50aadbe6$0$29983$c3e8da3$5496439d@news.astraweb.com> <50aadcf0$0$29983$c3e8da3$5496439d@news.astraweb.com> <a14abf7d-b231-4cf5-989a-f38e6307867d@googlegroups.com> <CALwzidmQH=4jU5cntY8zMK1ZB564Apm+FPp2b0bxpF6PbFYJPQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 20 Nov 2012 12:39:10 -0700
Subject Re: re.search when used within an if/else fails
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.83.1353440383.29569.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Tue, Nov 20, 2012 at 12:37 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, Nov 20, 2012 at 12:09 PM, Kevin T <kevinintx@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

re.search when used within an if/else fails Kevin T <kevinintx@gmail.com> - 2012-11-19 15:43 -0800
  Re: re.search when used within an if/else fails MRAB <python@mrabarnett.plus.com> - 2012-11-20 01:21 +0000
  Re: re.search when used within an if/else fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-20 01:24 +0000
    Re: re.search when used within an if/else fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-20 01:29 +0000
      Re: re.search when used within an if/else fails Kevin T <kevinintx@gmail.com> - 2012-11-20 11:09 -0800
        Re: re.search when used within an if/else fails Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-20 12:37 -0700
          Re: re.search when used within an if/else fails Kevin T <kevinintx@gmail.com> - 2012-11-21 08:41 -0800
            Re: re.search when used within an if/else fails Chris Angelico <rosuav@gmail.com> - 2012-11-22 16:00 +1100
              Re: re.search when used within an if/else fails Kevin T <kevinintx@gmail.com> - 2012-11-28 11:39 -0800
                Re: Re: re.search when used within an if/else fails Evan Driscoll <driscoll@cs.wisc.edu> - 2012-11-28 14:08 -0600
                Re: re.search when used within an if/else fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-28 21:39 +0000
                Re: re.search when used within an if/else fails Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-28 19:20 -0500
                Re: re.search when used within an if/else fails Duncan Booth <duncan.booth@invalid.invalid> - 2012-11-29 09:34 +0000
                Re: re.search when used within an if/else fails Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-29 13:38 -0500
                RE: re.search when used within an if/else fails "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-29 22:57 +0000
                RE: re.search when used within an if/else fails "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-29 22:53 +0000
              Re: re.search when used within an if/else fails Kevin T <kevinintx@gmail.com> - 2012-11-28 11:39 -0800
                Re: re.search when used within an if/else fails Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-28 20:50 +0000
        Re: re.search when used within an if/else fails Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-20 12:39 -0700

csiph-web