invoke method on many instances

Alan G Isaac alan.isaac at
Fri Jul 17 07:19:50 CEST 2009

As a recurrent situation, I need to invoke the same method
on many instances.  Speed matters, but the solution should
be pure Python.  Is the following convenience function
a reasonable approach?

def apply2(itr, methodname, *args, **kwargs):
    f = operator.methodcaller(methodname, *args, **kwargs)
    for item in itr:

(Comment: in the case at hand, the methods return None.)

Thank you,
Alan Isaac

More information about the Python-list mailing list