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

Aahz aahz at pythoncraft.com
Thu Dec 7 20:16:38 CET 2006


On Thu, Dec 07, 2006, Alastair Houghton wrote:
>
> An example where it might be useful:
> 
>   m = re.match('(?:([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) (?P<rect>rect)'
>                '|([0-9]+) ([0-9]+) ([0-9]+) (?P<circle>circle))',
>                lineFromFile)
> 
>   if m['rect']:
>       drawRectangle(m[1:5])
>   elif m['circle']:
>       drawCircle(m[1:3], m[3])
> 
> Is that really so outlandish?  

Likely; normally I would expect that drawRectangle would break on string
arguments instead of ints.  I think that the amount of usefulness
compared to problems doesn't really make this worth it.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Member of the Groucho Marx Fan Club  


More information about the Python-Dev mailing list