[Python-Dev] Missing operator.call

Andrew Bennetts andrew-pythondev at puzzling.org
Wed Feb 4 14:28:21 CET 2009


Hrvoje Niksic wrote:
> Is there a reason why the operator module doesn't have an operator.call  
> function?

Python 2.6 adds operator.methodcaller.  So you could use
operator.methodcaller('__call__'), but that's not really any better than
lambda x: x().

A patch to add operator.caller(*args, **kwargs) may be a good idea.  Your
example would then be:

    map(operator.caller(), lst)

That reads ok to me.  I think this reads better though:

    [callable() for callable in lst]

<wink>

-Andrew.



More information about the Python-Dev mailing list