Kelie schrieb:
> Thomas Heller <[EMAIL PROTECTED]> writes:
>> It might be faster to use this code; you sabe one COM call in the loop:
>> 
>> item = ms.Item
>> for i in xrange(ms.Count):
>>     item(i).Color = 3
>> 
> 
> Thomas, Thanks for your advice. I tried your suggestion and it does not appear
> to make a difference in speed compared with the 1st testing method. Btw, I 
> also
> tested with another scripting language called AutoIt and it is slightly faster
> than using the 1st testing method. 

Kelie,
It just occurred to me that there is one additional 'feature' in comtypes that
may slow down accessing COM properties or calling COM methods: the case 
insensitivity.

Retriving COM properties or methods with the 'incorrect' casing will probably 
be slower
than using the correct casing of the attribute:

  c = item(i).Color # this should be faster (if 'Color' is the correct spelling)
  c = item(i).color # this should be slower than the above

The reason is that comtypes creates a Python property with the correct name in
the instance which can be accessed directly and will be fast.  Using the wrong
casing will also work but first __getattr__(...) will be called, this will
in turn map the property name to the correct spelling and then access the 
property.

Setting the property will ALWAYS go through __setattr__() so will always be 
slow.

All this is determined for each interface by the '    _case_insensitive_ = True'
code that the codegenerator by default inserts into the modules in comtypes\gen.
You can manually replace all these lines with '    _case_insensitive_ = False'.
This will disable the case-insensitivity and access should be faster.

-- 
Thanks,
Thomas


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to