Re: Something weird about re.finditer()

2009-04-17 Thread Aaron Brady
On Apr 17, 9:37 pm, Steven D'Aprano wrote: > On Sat, 18 Apr 2009 12:37:09 +1200, Lawrence D'Oliveiro wrote: > > In message , > > Steven D'Aprano wrote: > > >> BTW, testing for None with == is not recommended, because one day > >> somebody might pass your function some strange object that compares

Re: Something weird about re.finditer()

2009-04-17 Thread Steven D'Aprano
On Sat, 18 Apr 2009 12:37:09 +1200, Lawrence D'Oliveiro wrote: > In message , > Steven D'Aprano wrote: > >> BTW, testing for None with == is not recommended, because one day >> somebody might pass your function some strange object that compares >> equal to None. > > Presumably if it compares equ

Re: Something weird about re.finditer()

2009-04-17 Thread Lawrence D'Oliveiro
In message , Steven D'Aprano wrote: > BTW, testing for None with == is not recommended, because one day > somebody might pass your function some strange object that compares equal > to None. Presumably if it compares equal to None, that is by design, precisely so it would work in this way. --

Re: Something weird about re.finditer()

2009-04-15 Thread Steven D'Aprano
On Wed, 15 Apr 2009 10:46:28 +0200, Gilles Ganault wrote: > Since "blocks" is no longer set to None after calling finditer()... but > doesn't contain a single block... what does it contain then? It probably took you twenty times more time and effort to ask the question than it would have to look

Re: Something weird about re.finditer()

2009-04-15 Thread Justin Ezequiel
On Apr 15, 4:46 pm, Gilles Ganault wrote: > re_block = re.compile('before (.+?) after',re.I|re.S|re.M) > > #Here, get web page and put it into "response" > > blocks = None > blocks = re_block.finditer(response) > if blocks == None: >         print "No block found" > else: >         print "Before b

Re: Something weird about re.finditer()

2009-04-15 Thread Peter Otten
Gilles Ganault wrote: > I stumbled upon something funny while downloading web pages and > trying to extract one or more blocks from a page: Even though Python > seems to return at least one block, it doesn't actually enter the for > loop: > > == > re_block = re.compile('before (.+?) a

Re: Something weird about re.finditer()

2009-04-15 Thread John Machin
On Apr 15, 6:46 pm, Gilles Ganault wrote: > Hello > >         I stumbled upon something funny while downloading web pages and > trying to extract one or more blocks from a page: Even though Python > seems to return at least one block, it doesn't actually enter the for > loop: > > == > re_block

Re: Something weird about re.finditer()

2009-04-15 Thread Jeremiah Dodds
On Wed, Apr 15, 2009 at 9:46 AM, Gilles Ganault wrote: > Hello > >I stumbled upon something funny while downloading web pages and > trying to extract one or more blocks from a page: Even though Python > seems to return at least one block, it doesn't actually enter the for > loop: > >

Something weird about re.finditer()

2009-04-15 Thread Gilles Ganault
Hello I stumbled upon something funny while downloading web pages and trying to extract one or more blocks from a page: Even though Python seems to return at least one block, it doesn't actually enter the for loop: == re_block = re.compile('before (.+?) after',re.I|re.S|re.M) #Here,