[Python-ideas] Function caller in operator module

Mike Graham mikegraham at gmail.com
Wed Mar 3 20:48:18 CET 2010


Most operations that are available using operators in Python are
provided by the operator module, but calling functions is noticeably
absent is calling functions. A user can slightly abuse
operator.methodcaller('__call__', ...) to perform this operation, but
that is far from ideal.

Should operator grow a new function caller, such that
operator.caller(*args, **kwargs)(f) returns f(*args, **kwargs)?

I have never personally needed this exact operation; it would be
somewhat odd but not altogether unthinkable to sort a list of
callables by their return values. The closes thing to this I have seen
in the wild is map(apply, fs), which is limited to the no-arguments
case. It is also possibly uglier than [f() for f in fs]. In any event,
it's not even an option in Python 3.x.



More information about the Python-ideas mailing list