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

Calvin Spealman ironfroggy at gmail.com
Sun Feb 5 04:00:10 CET 2012

On Sat, Feb 4, 2012 at 7:20 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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).

I love the idea, and I think such a solution is much more straight forward than
any syntax change. While it would be great to extend the functionality
of vars(),
it would be easier to add a new builtin that returns some kind of
proxy. If vars()
was changed to return this proxy, it could potentially break a lot of
existing code
mutating the dict returned by vars.

The question is: Is yet another builtin or the messy compatibility change the
worse option?

Read my blog! I depend on your acceptance of my opinion! I am interesting!
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

More information about the Python-ideas mailing list