[python-win32] Need advice on iterator implementation in scripting host
Mark Hammond
skippy.hammond at gmail.com
Tue Apr 17 03:14:43 CEST 2012
On 13/04/2012 9:14 PM, Pulsonix Tech Support wrote:
> We have an ActiveX scripting host implementation in our application
> (written in C++), so that users can run scripts to access our data from
> inside the application.
>
> Current problem is that iterating from Python script doesn’t work right.
> You can iterate through a collection, but attempts to do this a second
> time cause application crashes or unexpected behaviour. Seems to work
> okay from VBscript though.
>
> This may be because we are not raising StopIteration exception when
> iterator.Next() has no items left. But I can’t find any information
> about how to do this from a C++ scripting host implementation.
win32com has some iterator support built in, but was done way before
Python itself had proper iterators so probably isn't ideal. The most
basic support is enabled when the object has a "Count" property and an
Item() method. Some support for IEnumVARIANT also exists, but it
requires you to wrap the object in win32com.client.util.Iterator - which
I should possibly revisit as we might be able to make that seamless.
How are you attempting to expose iteration?
Mark
More information about the python-win32
mailing list