This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fgracia
Recipients ezio.melotti, fgracia, mrabarnett
Date 2012-05-27.09:13:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338109997.99.0.370113417988.issue14924@psf.upfronthosting.co.za>
In-reply-to
Content
I find baffling the following behaviour of *re.finditer()*:

    Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.
    >>> import re
    >>> m = re.finditer( '123', 'abc' )
    >>> m
    <callable_iterator object at 0x00BF09B0>
    >>> if m : 'I am Napoleon'
    
    'I am Napoleon'

No other way of formulating the condition that I have tried has worked either. Apparently *m* is always true, although all efforts to test its value indicate the contrary:

    >>> m == True
    False
    >>>

This does not happen with any other of the related methods (*findall*, *match*, *search*), which no doubt is the correct and logical behaviour:

    >>> n = re.findall( '123', 'abc' )
    >>> n
    []
    >>> if n : 'I am Napoleon'
    
    >>> 

I have not seen any warning or explanation for this fact in the official or third party documentation that I have consulted. Perhaps it is not a bug, but, as the preceding lines show, it makes impossible to test the result of the operation and direct the subsequent program flow.

If this were an unavoidable feature of *re.finditer*, it should be at least clearly exposed and, if possible, with indications of how to circumvent its undesirable consequences.

Thanks for your attention and efforts.
History
Date User Action Args
2012-05-27 09:13:18fgraciasetrecipients: + fgracia, ezio.melotti, mrabarnett
2012-05-27 09:13:17fgraciasetmessageid: <1338109997.99.0.370113417988.issue14924@psf.upfronthosting.co.za>
2012-05-27 09:13:17fgracialinkissue14924 messages
2012-05-27 09:13:16fgraciacreate