invoke method on many instances
Alan G Isaac
alan.isaac at gmail.com
Fri Jul 17 01:19:50 EDT 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:
f(item)
(Comment: in the case at hand, the methods return None.)
Thank you,
Alan Isaac
More information about the Python-list
mailing list