[issue14384] Add "default" kw argument to operator.itemgetter and operator.attrgetter

Miki Tebeka report at bugs.python.org
Thu Mar 22 17:46:27 CET 2012


Miki Tebeka <miki.tebeka at gmail.com> added the comment:

IMO in the case of multiple items/attrs then you return default in their place:
    attrgetter('x', 'y', default=7)(None) => (7, 7)

In case of dotted attribute again it'll return default value of any of the attributes is not found:
    attrgetter('x.y', default=7)(None) => 7

BTW: This is inspired from Clojure's get-in (http://bit.ly/GGzqjh) function.

I'll bring this up in python-ideas.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14384>
_______________________________________


More information about the Python-bugs-list mailing list