[Python-ideas] Attribute-Getter Syntax Proposal

Robert Vanden Eynde robertve92 at gmail.com
Sat Mar 9 15:49:10 EST 2019


You can do :

I suggest this syntax:
> >>> map(.upper(), ['a', 'b', 'c'])
>

map(dot('upper'), 'a b c'.split())
map(dot('replace', 'x', 'y'), 'xo do ox'.split())

def dot(name, *args, **kwargs):
    return lambda self: getattr(self, name)(*args, **kwargs)


> This would also work for attributes:
> >>> map(.real, [1j, 2, 3+4j])
>

from operator import itemgetter
map(itergetter('real'), [...])

from operator import itemgetter as gatt
map(itergetter('real'), [...])


Also, check out my package funcoperators on pip for neat functional
programming syntaxes

https://pypi.org/project/funcoperators/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190309/c17270f4/attachment-0001.html>


More information about the Python-ideas mailing list