[Python-ideas] Shorthand syntax for get/set/delattr (was Re: Dict-like object with property access)

Eric Snow ericsnowcurrently at gmail.com
Sun Feb 5 08:40:30 CET 2012


On Sat, Feb 4, 2012 at 5:20 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Rather than throwing out random ideas in a popularity contest, it's
> important to carefully review what it is that people don't like about
> the current state of affairs.
>
[snipped]
>
> It would be a *lot* cleaner if we could just use a normal assignment
> statement instead of builtin functions to perform the name binding. As
> it turns out, for ordinary instances, we can already do exactly that:
>
>    for attr in "attr1 attr2 attr3".split():
>        vars(x)[attr] = vars(y)[attr]
>
> In short, I think proposals for dedicated syntax for dynamic attribute
> access are misguided - instead, such efforts should go into enhancing
> vars() to return objects that support *full* dict-style access to the
> underlying object's attribute namespace (with descriptor protocol
> support and all).

Good call on this, Nick.  :)

-eric



More information about the Python-ideas mailing list