[issue14991] Option for regex groupdict() to show only matching names

2012-06-03 Thread Raymond Hettinger

New submission from Raymond Hettinger :

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'(?PMrs |Mr |Dr )?(?P\w+)(?P 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().

--
messages: 162223
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Option for regex groupdict() to show only matching names
type: enhancement
versions: Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14991] Option for regex groupdict() to show only matching names

2012-06-15 Thread Ezio Melotti

Changes by Ezio Melotti :


--
components: +Regular Expressions
nosy: +ezio.melotti, mrabarnett
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14991] Option for regex groupdict() to show only matching names

2012-06-16 Thread Larry Hastings

Larry Hastings  added the comment:

Just a thought--how about a new constant in the re module:
SUPPRESSED=object()
and have the interface be
mo.groupdict(default=re.SUPPRESSED)

--
nosy: +larry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14991] Option for regex groupdict() to show only matching names

2012-06-17 Thread Matthew Barnett

Matthew Barnett  added the comment:

@rhettinger: The problem with "nodefault" is that it's negative, so that 
"nodefault=False" means that you don't not want the default, if you see what I 
mean. I think that "suppress" would be better:

mo.groupdict(suppress=True)

@larry: If the parameter was "default", would that mean that you could provide 
a different default, such as:

mo.groupdict(default="")

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14991] Option for regex groupdict() to show only matching names

2012-06-17 Thread Larry Hastings

Larry Hastings  added the comment:

@mrabarnett: That's right--except your tense is wrong.  mo.groupdict() has 
supported the "default" parameter since the function was first added, way back 
in 1.5.2.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com