Miki Tebeka
2012-03-22 01:09:19 UTC
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>
_______________________________________
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>
_______________________________________