[Python-ideas] Attribute-Getter Syntax Proposal
samuel.wgx at gmail.com
Fri Mar 8 11:55:58 EST 2019
Don't know if this has been suggested before. Instead of writing something
>>> map(lambda x: x.upper(), ['a', 'b', 'c'])
I suggest this syntax:
>>> map(.upper(), ['a', 'b', 'c'])
This would also work for attributes:
>>> map(.real, [1j, 2, 3+4j])
Internally, this would require translating
.attribute -> lambda x: x.attribute
.method(*args, **kwargs) -> lambda x: x.method(*args, **kwargs)
This translation should only take place where a "normal" attribute lookup
makes no sense (throws a SyntaxError); i.e. foo.bar works as before,
foo(.bar) would previously throw a SyntaxError, so the new syntax applies
and the .bar is interpreted as an attrgetter.
This is of course only a cosmetic improvement over operator.attrgetter and
operator.methodcaller, but I think it's nice enough to warrant
If you like this idea or think it's utter garbage, feel free to discuss.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas