PythonWin and collections

barryhart at my-deja.com barryhart at my-deja.com
Sat Jun 10 23:29:43 EDT 2000


I'm trying to port the following fairly simple code to Python. It uses
ADSI to get a list of members in an NT group.

    For Each member In GetObject("WinNT://usa/Developers").Members
        Debug.Print member.ADsPath
    Next

I'm a fairly new Python user, and so far I've never figured out how to
enumerate a COM collection object properly. In previous cases, I've
been able to work around this by using the "Count" and "Item" methods
to index over the collection, but this particular collection doesn't
expose Count and Item methods.

Here's my Python attempt at the above code:

    from win32com.client import GetObject

    for member in GetObject("WinNT://usa/Developers").Members:
        print member.ADsPath

The "for" loop fails with "TypeError: loop over non-sequence". I also
tried adding "._NewEnum()" after the ".Members", but this fails
with "AttributeError: _NewEnum".

Help!

-----------------------------
Barry Hart
Velant, Inc.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list