Troubleshooting: re.finditer() creates object even when no match found

Chris Lasher chris.lasher at gmail.com
Fri Dec 17 11:38:52 EST 2004


Hello,
I really like the finditer() method of the re module. I'm having
difficulty at the moment, however, because finditer() still creates a
callable-iterator oject, even when no match is found. This is
undesirable in cases where I would like to circumvent execution of code
meant to parse out data from my finditer() object.

I know that if I place a finditer() object in an iterative for loop,
the loop will not execute, but is there some way I can test to see if
the object contains no matches in the first place? I thought about
using .next() but I don't want to lose the ability to process the first
(sometimes only) match in the finditer() object.
Thanks in advance,
Chris




More information about the Python-list mailing list