New submission from Miki Tebeka <miki.teb...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue14384>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to