re.finditer

Sean 'Shaleh' Perry shalehperry at attbi.com
Tue Jul 23 11:16:49 EDT 2002


> 
> $ python
> Python 2.2.1 (#1, Apr  9 2002, 13:10:27)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import re
>>>> re.finditer('r+?','library')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'module' object has no attribute 'finditer'
> 
> The command re.finditer is not recognized ! All the other commands
> work, for instance
> 

import re
regex = re.compile(r'\s'+)
dir(regex)
['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner',
'search', 'split', 'sub', 'subn']

as you can see, finditer() is a method of a regular expression object and is
not a generic function in the re module.  This may still be a bug because it is
handy to call regex's directly and not need to compile them.






More information about the Python-list mailing list