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

Miki Tebeka report at bugs.python.org
Thu Mar 22 02:09:19 CET 2012


New submission from Miki Tebeka <miki.tebeka at gmail.com>:

This way they will behave more like getattr and the dictionary get.

If default is not specified, then if the item/attr not found, an execption will be raised, which is the current behavior.

However if default is specified, then return it in case when item/attr not found - default value will be returned.

I wanted this when trying to get configuration from a list of objects. I'd like to do
    get = attrgetter('foo', None)
    return get(args) or get(config) or get(env)

----------
components: Library (Lib)
messages: 156531
nosy: tebeka
priority: normal
severity: normal
status: open
title: Add "default" kw argument to operator.itemgetter and operator.attrgetter
versions: Python 3.3, Python 3.4

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


More information about the Python-bugs-list mailing list