Message161705
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. |
|
Date |
User |
Action |
Args |
2012-05-27 09:13:18 | fgracia | set | recipients:
+ fgracia, ezio.melotti, mrabarnett |
2012-05-27 09:13:17 | fgracia | set | messageid: <1338109997.99.0.370113417988.issue14924@psf.upfronthosting.co.za> |
2012-05-27 09:13:17 | fgracia | link | issue14924 messages |
2012-05-27 09:13:16 | fgracia | create | |
|