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

2006-12-04 Thread Fredrik Lundh
Ka-Ping Yee wrote: > I'd say, don't pretend m is a sequence. Pretend it's a mapping. > Then the conceptual issues go away. almost; that would mean returning KeyError instead of IndexError for groups that don't exist, which means that the common pattern a, b, c = m.groups() cannot be rewr

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

2006-12-04 Thread Ka-Ping Yee
On Sun, 3 Dec 2006, Fredrik Lundh wrote: > Martin v. Löwis wrote: > > 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 y

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

2006-12-04 Thread Gregory P. Smith
On Sun, Dec 03, 2006 at 07:38:21PM +0100, "Martin v. L?wis" wrote: > Aahz schrieb: > >>> this one is fairly simple. if `m' is a match object, i'd like to be > >>> able to write m[1] instead of m.group(1). (similarly, m[:] should return > >>> the same as list(m.groups()).) this would remove some of

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

2006-12-03 Thread Fredrik Lundh
Martin v. Löwis wrote: >> 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? > > I take it that you are objecting to that feature, then? I haven't seen a comp

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

2006-12-03 Thread Greg Ewing
Steve Holden wrote: > So the subgroups are numbered starting from > 1 and subgroup 0 is a special case which returns the whole match. But the subgroups can be nested too, so it's not really as special as all that. -- Greg ___ Python-Dev mailing list Py

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

2006-12-03 Thread Martin v. Löwis
Fredrik Lundh schrieb: > 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? I take it that you are objecting to that feature, then? Regards, Martin _

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

2006-12-03 Thread Georg Brandl
Georg Brandl wrote: > (Or, the API could be overhauled completely of course, remember it's Py3k.) Erm, no, it's not. Strike that remark. Georg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubsc

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

2006-12-03 Thread Georg Brandl
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. >

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

2006-12-03 Thread Steve Holden
Martin v. Löwis wrote: > Steve Holden schrieb: >> Precisely. But your example had only one group "(b)" in it, which is >> retrieved using m.group(1). So the subgroups are numbered starting from >> 1 and subgroup 0 is a special case which returns the whole match. >> >> I know what the Zen says about

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

2006-12-03 Thread Fredrik Lundh
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 co

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

2006-12-03 Thread Martin v. Löwis
Steve Holden schrieb: > Precisely. But your example had only one group "(b)" in it, which is > retrieved using m.group(1). So the subgroups are numbered starting from > 1 and subgroup 0 is a special case which returns the whole match. > > I know what the Zen says about special cases, but in this c

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

2006-12-03 Thread Steve Holden
Martin v. Löwis wrote: > Fredrik Lundh schrieb: match groups are numbered 1..N, not 0..(N-1), in both the API and in the RE syntax (and we don't have much control over the latter). >>> py> m = re.match("a(b)","ab") >>> py> m.group(0) >>> 'ab' >>> py> m.group(1) >>> 'b' >> 0 isn't a group

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

2006-12-03 Thread Martin v. Löwis
Fredrik Lundh schrieb: >>> match groups are numbered 1..N, not 0..(N-1), in both the API and in the >>> RE syntax (and we don't have much control over the latter). >> py> m = re.match("a(b)","ab") >> py> m.group(0) >> 'ab' >> py> m.group(1) >> 'b' > > 0 isn't a group, it's an alias for the full m

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

2006-12-03 Thread Fredrik Lundh
Martin v. Löwis wrote: >> match groups are numbered 1..N, not 0..(N-1), in both the API and in the >> RE syntax (and we don't have much control over the latter). > > py> m = re.match("a(b)","ab") > py> m.group(0) > 'ab' > py> m.group(1) > 'b' 0 isn't a group, it's an alias for the full match.

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

2006-12-03 Thread Martin v. Löwis
Fredrik Lundh schrieb: >> 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)). > > match groups are numbered 1..N, not 0..(N-1), in both the API and in the > RE syntax (and we don't have

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

2006-12-03 Thread Martin v. Löwis
Aahz schrieb: >>> this one is fairly simple. if `m' is a match object, i'd like to be >>> able to write m[1] instead of m.group(1). (similarly, m[:] should return >>> the same as list(m.groups()).) this would remove some of the verbosity >>> of regexp code, with probably a net gain in readability;

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

2006-12-03 Thread Aahz
On Sun, Dec 03, 2006, "Martin v. L?wis" wrote: > Ben Wing schrieb: >> >> this one is fairly simple. if `m' is a match object, i'd like to be >> able to write m[1] instead of m.group(1). (similarly, m[:] should return >> the same as list(m.groups()).) this would remove some of the verbosity >> of r

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

2006-12-03 Thread Martin v. Löwis
Barry Warsaw schrieb: >> Several issues need to be taken into account: >> - documentation and test cases must be updated to integrate the new API >> - for slicing, you need to consider not only omitted indices, but also >> "true" slices (e.g. m[1:5]) >> - how should you deal with negative indices

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

2006-12-03 Thread Fredrik Lundh
Martin v. Löwis wrote: > 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)). match groups are numbered 1..N, not 0..(N-1), in both the API and in the RE syntax (and we don't have much con

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

2006-12-03 Thread Barry Warsaw
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Dec 3, 2006, at 9:22 AM, Martin v. Löwis wrote: > Ben Wing schrieb: >> this one is fairly simple. if `m' is a match object, i'd like to be >> able to write m[1] instead of m.group(1). (similarly, m[:] should >> return >> the same as list(m.group

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

2006-12-03 Thread Martin v. Löwis
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

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

2006-12-03 Thread Fredrik Lundh
Martin v. Löwis wrote: > Several issues need to be taken into account: 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

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

2006-12-03 Thread Martin v. Löwis
Ben Wing schrieb: > this one is fairly simple. if `m' is a match object, i'd like to be > able to write m[1] instead of m.group(1). (similarly, m[:] should return > the same as list(m.groups()).) this would remove some of the verbosity > of regexp code, with probably a net gain in readability; cer

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

2006-12-03 Thread Ben Wing
this one is fairly simple. if `m' is a match object, i'd like to be able to write m[1] instead of m.group(1). (similarly, m[:] should return the same as list(m.groups()).) this would remove some of the verbosity of regexp code, with probably a net gain in readability; certainly no loss. ben