Skip to main content

mattrgetter

Get attributes, ignoring attribute errors.

Like :func:`operator.itemgetter` but return :const:`None` on missing
attributes instead of raising :exc:`AttributeError`.
def mattrgetter(
*attrs: string
) - > function

Get attributes, ignoring attribute errors. Like :func:operator.itemgetter but return :const:None on missing attributes instead of raising :exc:AttributeError.

Parameters

NameTypeDescription
*attrsstringA variable number of attribute names to be retrieved from the target object.

Returns

TypeDescription
functionA lambda function that, when called with an object, returns a dictionary mapping each requested attribute name to its value or None if the attribute is missing.