operator.methodcaller(name[, args...])
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:
- After
f = methodcaller('name'), the callf(b)returnsb.name(). - After
f = methodcaller('name', 'foo', bar=1), the callf(b)returnsb.name('foo', bar=1).
Equivalent to:
def methodcaller(name, *args, **kwargs):
def caller(obj):
return getattr(obj, name)(*args, **kwargs)
return caller
Please login to continue.