[issue39165] Completeness and symmetry in RE, avoid `findall(...)[0]`

Serhiy Storchaka report at bugs.python.org
Fri Jan 17 08:52:55 EST 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Most of examples do not test whether findall() returns an empty list. So there is no significant difference with using search() -- just different type of exception if fails (IndexError, TypeError or AttributeError). Since most examples do not handle errors, this will only affect a traceback if you use the script improperly.

If it is important to you, you can write (re.search(...) or [])[0] and get the same IndexError.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39165>
_______________________________________


More information about the Python-bugs-list mailing list