[Python-Dev] New syntax for 'dynamic' attribute access
Brett Cannon
brett at python.org
Mon Feb 12 04:59:14 CET 2007
On 2/11/07, Ben North <ben at redfrontdoor.org> wrote:
[SNIP]
> * The draft currently allows a two-argument form, to supply a default
> value if the object has no attribute of that name. This mimics the
> behaviour of the three-argument form of getattr, but looks a bit wrong:
>
> s = obj.(attr_name, 'default string')
>
> I agree that it looks odd, but perhaps the extra expressive power
> gained might be worth the oddness.
I don't think it is. getattr can just be kept around if need be in
order to support this use case. It just makes it look like too much
of a function call at that point to me, especially if someone ends up
writing some expression that is so long that they put in a newline
between the two values:
s = obj.(attr_name,
'default_string')
So -1 on the two-item version, +0 on the one-item version.
-Brett
More information about the Python-Dev
mailing list