homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2012年06月03日.17:01:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338742861.24.0.324062376049.issue14991@psf.upfronthosting.co.za>
In-reply-to
Content
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().
History
Date User Action Args
2012年06月03日 17:01:01rhettingersetrecipients: + rhettinger
2012年06月03日 17:01:01rhettingersetmessageid: <1338742861.24.0.324062376049.issue14991@psf.upfronthosting.co.za>
2012年06月03日 17:01:00rhettingerlinkissue14991 messages
2012年06月03日 17:01:00rhettingercreate

AltStyle によって変換されたページ (->オリジナル) /