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

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 3 16:53:35 CET 2006


Fredrik Lundh schrieb:

the most important issue is that if you want an object to behave as a sequence of something, you need to decide what that something is before you start tinkering with the syntax.

under Ben's simple proposal, m[:][1] and m[1] would be two different things. I'm not sure that's a good idea, really.

Ah, right; I misread his proposal as saying that m[:] should return [m[0]] + list(m.groups()) (rather, I expected that m.groups() would include m.group(0)).

To answer your first question: it is clearly groups that you want to index, just as the .group() method indexes groups.

The typical equivalences should hold, of course, e.g. m[1:5][1] == m[2] etc.

Regards, Martin



More information about the Python-Dev mailing list