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

Collin Winter collinw at gmail.com
Mon Feb 12 23:42:07 CET 2007


On 2/12/07, Brett Cannon <brett at python.org> wrote:
> On 2/12/07, Raymond Hettinger <python at rcn.com> wrote:
> > [Jack Jansen]
> > > I like the functionality, but I don't like the syntax, to me it looks
> > > too much like a method call.
> > >
> > > To me self.[method_name] = self.metadata.[method_name] looks better:
> > > what we're doing here is more like dictionary lookup than calling
> > > functions.
> >
> > I also like the functionality.
> >
> > Rather than munge existing syntaxes, an altogether new one would be more clear:
> >
> >    self->name = self.metadata->name
> >
> > I like the arrow syntax because is the lookup process can be more involved
> > than a simple dictionary lookup (perhaps traveling up to base classes).
> > IOW, getattr(a,n) is not always the same as a.__dict__[n].
> > The a.__getattribute__(n) process can be more complex than that
> > and a bracketed dictionary-like syntax would misleadingly mask the lookup
> > process.
> >
>
> 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.

Collin Winter


More information about the Python-Dev mailing list