invoke method on many instances
gagsl-py2 at yahoo.com.ar
Wed Jul 22 20:10:54 EDT 2009
En Wed, 22 Jul 2009 10:14:12 -0300, Alan G Isaac <alan.isaac at gmail.com>
>>>> 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:
>>> On 7/17/2009 3:45 AM Steven D'Aprano apparently wrote:
>>>> for obj in objects:
>>>> getattr(obj, methodname)(*args, **kwargs)
>> En Sat, 18 Jul 2009 12:31:46 -0300, Alan G Isaac:
>>> Are there any obvious considerations in choosing
>>> between those two?
> On 7/20/2009 3:29 AM Gabriel Genellina apparently wrote:
>> The operator.methodcaller version is faster in my tests for large
>> collections, but slightly slower when you have very few elements.
> So it seems. Is this easily explained?
More information about the Python-list