Python COM iterator

Larry Bates larry.bates at
Tue Apr 17 23:54:50 CEST 2007

Does anyone know if there is a way to make a Python COM object
act like a proper iterator in VB/Delphi?


Python COM object

class foo:

    def __init__(self):
    def next(self):
        try: return self.numbers.pop(0)
        except IndexError:
            # Normally in Python I would do this, but that raises a
            # COMexception when used in a COM object.
            raise StopIteration

    def __iter__(self):
        return self

I want to be able to write something like (VB):

    for each n in oFOO
        ' Do something with n

Seems like there should be a way.  Hope explanation is clear enough.

Regards, Larry

More information about the Python-list mailing list