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
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
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
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
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
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
_
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
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.
>
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
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
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
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
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
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.
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
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;
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
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
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
-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
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
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
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
23 matches
Mail list logo