Something weird about re.finditer()
nospam at nospam.com
Wed Apr 15 10:46:28 CEST 2009
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
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"
print "Before blocks"
for block in blocks:
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