Python COM iterator

Carsten Haese carsten at uniqsys.com
Thu Apr 19 14:28:26 EDT 2007


On Thu, 2007-04-19 at 12:49 -0400, Steve Holden wrote:
> Larry Bates wrote:
> > Carsten Haese wrote:
> [iterative acess to COM objects]
> > I tested in VB and by golly it works!  What is odd is that this looks
> > NOTHING like what we got from the docs earlier.  No GetEnumerator
> > method, no MoveNext method.  I'm glad it works, but I'm a little
> > puzzled as to why it works.

I'm glad, too.

> Presumably the magic of mark Hammond's wrapper classes providing 
> adaptation between Python iteration and COM enumerable collection 
> objects. win32all is *very* Pythonic.

There is some magic, but it appears to be on the client side only. This
magic is what allows you to stick the win32com.client.Dispatcher object
into a for-loop.

If there were magic on the server side, it shouldn't be necessary to
declare that IID_IEnumVARIANT is exposed, and it shouldn't be necessary
to implement the _NewEnum and Next methods; it should be enough to have
__iter__ present and let the magic take care of the rest.

It appears that the reason why my first completely uninformed guess
didn't work and my second somewhat less uninformed guess did work is
that there are two different enumeration protocols in the wonderfully
confusing world of Win32. I'm guessing that GetEnumerator/MoveNext is
the .NET enumeration protocol and IID_IEnumVARIANT/Next is the COM
enumeration protocol.

-Carsten





More information about the Python-list mailing list