[Python-Dev] a feature i'd like to see in python #2: indexing of match objects

Georg Brandl g.brandl at gmx.net
Sun Dec 3 22:42:26 CET 2006


Fredrik Lundh wrote:
> Martin v. Löwis wrote:
> 
>>> I know what the Zen says about special cases, but in this case the rules
>>> were apparently broken with impunity.
>> 
>> Well, the proposal was to interpret m[i] as m.group(i), for all values
>> of i. I can't see anything confusing with that.
> 
> it can quickly become rather confusing if you also interpret m[:] as 
> m.groups(), not to mention if you add len() and arbitrary slicing to
> the mix.  what about m[] and m[i,j,k], btw?

What about them? They aren't supposed to be supported by every object
that allows subscript, are they? And why not just not implement len()?

As for the [:] <-> groups() issue, [:] would have to be consistent with
indexing and return the whole match and the subgroups.

(Or, the API could be overhauled completely of course, remember it's Py3k.)

Georg



More information about the Python-Dev mailing list