invoke method on many instances

Alan G Isaac alan.isaac at gmail.com
Sat Jul 18 11:31:46 EDT 2009


> On Fri, 17 Jul 2009 05:19:50 +0000, Alan G Isaac wrote:
>> def apply2(itr, methodname, *args, **kwargs):
>>     f = operator.methodcaller(methodname, *args, **kwargs)
>>     for item in itr:
>>         f(item)


On 7/17/2009 3:45 AM Steven D'Aprano apparently wrote:
> for obj in objects:
>     getattr(obj, methodname)(*args, **kwargs)


Are there any obvious considerations in choosing
between those two?



> See also these recipes from the "Python Cookbook": 
> http://code.activestate.com/recipes/52289/
> http://code.activestate.com/recipes/87370/

Interesting.

Thanks,
Alan



More information about the Python-list mailing list