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

Barry Warsaw barry at python.org
Sun Dec 3 17:07:05 CET 2006


-----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.groups()).) this would remove some of the  
>> verbosity
>> of regexp code, with probably a net gain in readability; certainly  
>> no loss.
>
> Please post a patch to sf.net/projects/python (or its successor).
>
> 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?
> - should len(m) be supported?

what about m['named_group_1'] etc?

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRXL2LnEjvBPtnXfVAQILTwP/SRfvOXXhUXIBK52ByqwuhCwF+K/HfEYu
0+j/L3WQXFE4sZ1CHT6TaMT/K6tbhE7zuGamKmk1+CtSPQAKluwJ8d2/y6Ubp4KE
S24sP8NOzKgDg/aTn5zFS/Up7HDfhMIWGCLbg5rY+/Bl48skEkqeo4w07XKwJzky
CvxsrJb4wQY=
=OPjI
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list