[Python-ideas] Shorthand syntax for get/set/delattr (was Re: Dict-like object with property access)
storchaka at gmail.com
Sun Feb 5 13:46:00 CET 2012
05.02.12 02:20, Nick Coghlan написав(ла):
> 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).
One-liner "def vars(v): return v.__dict__"?
More information about the Python-ideas