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

Collin Winter collinw at gmail.com
Tue Feb 13 22:46:41 CET 2007


On 2/13/07, Nick Coghlan <ncoghlan at gmail.com> wrote:
[snip]
> I've tried this out on Brett's urllib & urllib2 examples below. (calling
> the new builtin attrview() to emphasise the fact that it retains a
> reference to the original instance). I don't consider it any uglier than
> the proposed syntax changes, and it provides a few other benefits:
>
>    - the two-argument form is naturally available as the .get() method
> on the resulting dict-like object (e.g. "attrview(obj).get(some_attr,
> None)")
>
>    - hasattr() is naturally replaced by containment testing (e.g.
> "some_attr in attrview(obj)")
>
>    - keywords/builtins are easier to look up in the documentation than
> symbolic syntax
>
> With this approach, performance would be attained by arranging to create
> the view objects once, and then performing multiple dynamic attribute
> accesses using those view objects.

This changes my vote: +1 on including attrview(), -1 on the syntax proposal.

Collin Winter


More information about the Python-Dev mailing list