re.search when used within an if/else fails
Kevin T
kevinintx at gmail.com
Wed Nov 21 11:41:53 EST 2012
On Nov 20, 1:37 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Tue, Nov 20, 2012 at 12:09 PM, Kevin T <kevini... 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.
I went back and tried version a again, blam it is/does work now ?!?!?
I am not sure what changed but version a was the original code that
wouldn't work. All the examples i had read, showed version a as a
working version. I spent significant time trying version a with
parens, spacing changes, different regex values to no avail. hence
the creation of all the other versions.
thanks for your help.
More information about the Python-list
mailing list