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


Groups > comp.lang.python > #33575

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

Date 2012-11-20 01:21 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: re.search when used within an if/else fails
References <f0f27287-17ea-4fa5-ad26-ad2b6d3c0031@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.26.1353374516.29569.python-list@python.org> (permalink)

Show all headers | View raw


On 2012-11-19 23:43, Kevin T wrote:
> python version 2.4.3, yes i know that it is old.  getting the sysadmin to update the OS requires a first born.
>
> with the following code..
>                  for signal in register['signals'] :
>
> 351                   sigName = signal['functionName']
> 352                   if re.search( "rsrvd", sigName ) == None :
> 353                      print sigName
> 354                      newVal = "%s%s" % ( '1'*signal['bits'] , newVal ) #prepend 0's
> 355                   if re.search( "rsrvd", sigName ) != None :
> 356                      print sigName
> 357                      newVal = "%s%s" % ( '0'*signal['bits'], newVal )
>
> regardless of how i code line 352, i can not EVER use an else clause with it.  if i use an else clause, the else will NEVER get executed...
>
> has any one experienced anything like this behavior?  any suggestions?  the above code works but... why should i have to code it like this?
>
Have you checked the indentation? There may be a mixture of tabs and spaces.

A couple of points:

1. You should be using "is None" and "is not None" instead of "== None" 
and "!= None".

2. You don't need to use regex. Use "rsrvd" in sigName and "rsrvd" not 
in sigName.

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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