[Python-Dev] New syntax for 'dynamic' attribute access

Georg Brandl g.brandl at gmx.net
Mon Feb 12 08:58:17 CET 2007


Collin Winter schrieb:
> I like the general idea, but the syntax looks like dirt on my monitor.
> The period is too easy to lose visually and without it, there's
> nothing to distinguish this from a function call. Also, like Anthony
> Baxter said, someone coming across this for the first time will think
> it's a syntax error, allusions to MATLAB and assembly indirection
> syntax not withstanding.
> 
> Ignoring the syntax, I'm -1 on the 2-argument form, especially since
> it can only be used in an expression context; getattr() can be kept
> around for this.
> 
> I'm +0 on the idea, -1 on the means.

-1 here too. I fear that this gets too indistinguishable from normal
calling syntax, leading to confusion.

(Of course, one could propose other syntax, such as obj->(attr) or whatnot,
but I doubt an ideal and Pythonic syntax can be found here...)

To me, dynamic attribute access is something "special", and it justifies
a different way of doing it, namely getattr and setattr.

For the speed argument -- there were quite a few proposals to take builtins as
constants under certain conditions, in which case getattr() usage could be
optimized just as well as new syntax.

Georg



More information about the Python-Dev mailing list