Message162223
Currently, mo.groupdict() always inserts a default value for unmatched named groups. This is helpful in some use cases and awkward in others.
I propose adding an option to suppress default entries:
>>> # CURRENT WAY
>>> pattern = r'(?P<TITLE>Mrs |Mr |Dr )?(?P<LASTNAME>\w+)(?P<SUFFIX> Phd| JD)?'
>>> print re.match(pattern, 'Dr Who').groupdict()
{'LASTNAME': 'Who', 'SUFFIX': None, 'TITLE': 'Dr '}
>>> # PROPOSED WAY
>>> print re.match(pattern, 'Dr Who').groupdict(nodefault=True)
{'LASTNAME': 'Who', 'TITLE': 'Dr '}
>>> # UPSTREAM VARIANT
>>> print re.match(pattern, 'Dr Who', re.NODEFAULT).groupdict()
{'LASTNAME': 'Who', 'TITLE': 'Dr '}
There is probably a better name than "nodefault", but I would like to see someway to improve the usability of groupdict(). |
|
Date |
User |
Action |
Args |
2012-06-03 17:01:01 | rhettinger | set | recipients:
+ rhettinger |
2012-06-03 17:01:01 | rhettinger | set | messageid: <1338742861.24.0.324062376049.issue14991@psf.upfronthosting.co.za> |
2012-06-03 17:01:00 | rhettinger | link | issue14991 messages |
2012-06-03 17:01:00 | rhettinger | create | |
|