Sequences/lists/enumerations in COM, Python 2.1, Windows 2000
Paul Boddie
paul at boddie.net
Fri Jun 1 07:58:13 EDT 2001
Mark Hammond <MarkH at ActiveState.com> wrote in message news:<3B163C9A.8020500 at ActiveState.com>...
> Paul Boddie wrote:
>
> > # Now, pay attention!
> >
> > third_sub_folder = second_folder.GetNext()
> >
> > # This will be the *same* object as the second_sub_folder!
>
>
> I have no idea what this is all about. Hopefully someone with
> experience in the object model will speak up here.
Who knows. The Visual Basic examples that I have seen (everyone seems
to explain it in VB) just iterate over the items collection, hence my
iterator question later.
> > first_folder = top_level[0] # Yields an exception - there is
> > # no folder 0!
> > first_folder = top_level[1] # Works - it's the first folder
> > # alright!
> >
> > # This breaks all known Python idioms, surely...
>
>
> It does. However, the Python COM extensions only know that we have an
> "indexable" object. It knows nothing about the valid indexes. Some
> applications index from zero, some from one.
Blimey! I bet it's hard to make something sensible happen with this
kind of behaviour. Just as it's necessary to indoctrinate beginners
with the nastiness of floating point, so should there be a caveat on
sequences having any involvement with COM. ;-)
> > Given that the index notation can be used, I don't really care about
> > the dubious GetFirst, GetNext methods, but what I would like to know
> > is: why don't sequence indexes behave "normally" for Python? Is it a
> > Python 2.1 issue, a win32com issue, or just something strange with
> > Outlook and the Exchange server I'm using?
>
>
> As above.
Right.
> > Also, would iteration over
> > sequences be supported once iterator support is built in to Python?
>
>
> If it can be done cleanly, then yes. Note that you can theoretically
> iterate over these objects now, but that same problem will bite in this
> case. I haven't checked out iterators in any detail, but I expect that
> it will be simpler and cleaner.
Great! Still, after much experimentation, things actually work in my
dastardly scheme. Thanks for the help (and the COM stuff)! How about a
code snippet library just for COM? (Or is there such a library with
lots of COM examples in that I don't know about?)
Regards,
Paul
More information about the Python-list
mailing list