re.search when used within an if/else fails

Kevin T kevinintx at gmail.com
Tue Nov 20 20:09:12 CET 2012


On Monday, November 19, 2012 7:29:20 PM UTC-6, Steven D'Aprano wrote:
> On Tue, 20 Nov 2012 01:24:54 +0000, Steven D'Aprano wrote:
> 
> 
> 
> - use "if something is None", not == None.
> 
> 
> Steven

i will not include line #'s in the future, point taken
i will change ==/!= to is/is not as most people pointed out.

there is no else because it doesn't work.

i used eclipse in debug mode and a command line execution of the code, both behave the same way

#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!!  

thanks for the input all..

kevin

Now if i change


More information about the Python-list mailing list