re.search when used within an if/else fails

Ian Kelly ian.g.kelly at gmail.com
Tue Nov 20 20:37:01 CET 2012


On Tue, Nov 20, 2012 at 12:09 PM, Kevin T <kevinintx at 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.


More information about the Python-list mailing list