The trouble with "dynamic attributes".

James Mills prologic at shortcircuit.net.au
Thu Sep 16 19:36:15 EDT 2010


On Fri, Sep 17, 2010 at 9:27 AM, MRAB <python at mrabarnett.plus.com> wrote:
> For the work on updating the re module there was a discussion about
> whether named capture groups should be available as attributes of the
> match object or via subscripting (or both?). Subscripting seemed
> preferable to me because:
>
> 1. Adding attributes looks too much like 'magic'.
>
> 2. What should happen if a group name conflicts with a normal attribute?
>
> 3. What should happen if a group name conflicts with a reserved word?
>
> For those reasons the new regex module uses subscripting. It's more
> Pythonic, IMHO.

I agree with 2) and 3) and in general this is probably a
"good approach".

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"



More information about the Python-list mailing list