ID EN
Operators

methodcaller

Python 3.11

Return a callable object that calls the method name on its operand. If additional arguments and/or keyword arguments are given, they will be given to the method as well. For example:

Syntax

PYTHON
operator.methodcaller(name, /, *args, **kwargs)

Examples

Example 1
PYTHON
def methodcaller(name, /, *args, **kwargs):
    def caller(obj):
        return getattr(obj, name)(*args, **kwargs)
    return caller