[issue24454] Improve the usability of the match object named group API
Raymond Hettinger
report at bugs.python.org
Mon Jun 15 05:47:52 CEST 2015
New submission from Raymond Hettinger:
The usability, learnability, and readability of match object code would be improved by giving it a more Pythonic API (inspired by ElementTree).
Given a search like:
data = 'Answer found on row 8 column 12.'
mo = re.search(r'row (?P<row>\d+) column (?P<col>\d+)', data)
We currently access results with:
print(mo.group('col'))
print(len(mo.groups())
A better way would look like this:
print(mo['col'])
print(len(mo))
This would work nicely with string formatting:
print('Located coordinate at (%(row)s, %(col)s)' % mo)
print('Located coordinate at ({row}, {col})'.format_map(mo))
----------
components: Library (Lib)
messages: 245361
nosy: rhettinger
priority: low
severity: normal
status: open
title: Improve the usability of the match object named group API
type: enhancement
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24454>
_______________________________________
More information about the Python-bugs-list
mailing list