Something weird about re.finditer()
Gilles Ganault
nospam at nospam.com
Wed Apr 15 04:46:28 EDT 2009
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, 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 blocks"
for block in blocks:
#Never displayed!
print "In blocks"
======
Since "blocks" is no longer set to None after calling finditer()...
but doesn't contain a single block... what does it contain then?
Thank you for any tip.
More information about the Python-list
mailing list