[Python-Dev] New syntax for 'dynamic' attribute access (original) (raw)

Delaney, Timothy (Tim) tdelaney at avaya.com
Tue Feb 13 00:08:26 CET 2007


Benji York wrote:

Collin Winter wrote:

On 2/12/07, Brett Cannon <brett at python.org> wrote:

I actually kind of like that. The connection to pointer indirection meshes well with the idea of indirectly figuring out what attribute to access at runtime.

There's a connection, but I'd say it's the wrong one. In C, "x->y" dereferences x, while in Python, "x->y" would dereference y. That's just begging for trouble. Then the syntax should obviously be "x<-y".

I'd actually gone through this process myself, and concluded that I wouldn't be happy with either.

"x->y: is currently invalid syntax, but has very strong connotations from C. Whilst I'm happy to consider things that deviate from other languages' use, this one is just too strong.

"x<-y" is currently valid syntax, and gives (to mee) the wrong impression that y is that thing that's going to be modified.

Of all the proposals I've seen, I think I like "x.{y}" best. The use of {} has connotations of interpolation and they're the only braces that currently don't have meaning as x{} (and probably never will).

I do worry that giving syntax to getattr/setattr/delattr will encourage the use of dynamic attributes, when they are a fairly advanced feature. OTOH, when you're using advanced features, you want the code to be as readable as possible, and I think this will improve readability over using getattr/setattr/delattr.

So I think I've changed to +0.5.

Tim Delaney



More information about the Python-Dev mailing list