New submission from Francisco Gracia <fgragu...@gmail.com>: 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. ---------- components: Regular Expressions messages: 161705 nosy: ezio.melotti, fgracia, mrabarnett priority: normal severity: normal status: open title: re.finditer() oddity type: behavior versions: Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14924> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com