You could use the time machine: https://docs.python.org/3/library/operator.html
On Fri, Mar 8, 2019, 11:57 AM Samuel Li <samuel....@gmail.com> wrote: > Don't know if this has been suggested before. Instead of writing something > like > > >>> 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 > > and > > .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 > consideration. > > If you like this idea or think it's utter garbage, feel free to discuss. > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/