This does indeed work. <br><br>Is there a way to modify the generated code such tat it works with 1-based iterators instead of 0-based ones?<br><br>I tried to modify the _getitem_ method by incrementing item before it executes
<br><br>return self._get_good_object_....<br><br>and then I get the correct list of Infostores, but directly after that I get another 'invalid index' error.<br><br><br><div><span class="gmail_quote">On 12/9/05, <b class="gmail_sendername">
Tim Golden</b> <<a href="mailto:tim.golden@viacom-outdoor.co.uk">tim.golden@viacom-outdoor.co.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
[Rudy Schockaert]<br><br>> I have a python program that does some things on<br>> Exchange mailboxes. I use the MAPI.Session object<br>> for this and create it like this:<br><br>> import win32com.client<br>> MAPISession =
win32com.client.Dispatch("MAPI.Session")<br>> MAPISession.Logon()<br>> for infostores in MAPISession.InfoStores:<br>> print infostores.Name<br><br>> If I now use makepy to create a genpy for the CDO
1.21<br>> library (MAPI.Session) I get the following result:<br><br>[... snip ...]<br><br>> Traceback (most recent call last):<br>> File "<interactive input>", line 1, in ?<br>> File<br>"C:\Python24\lib\site-packages\win32com\gen_py\3FA7DEA7-6438-101B-ACC1-0
<br>0AA00423326x0x1x21.py ", line 3039, in > __getitem__<br>> return self._get_good_object_(self._oleobj_.Invoke(*(21, LCID, 2,<br>1, item)), "Item")<br>> com_error: (-2147352565, 'Invalid index.', None, None)
<br><br>OK, this is the quick get-you-working answer. For the longer answer,<br>I'd have to look at the makepy-generated module and at the code<br>for the DispatchBaseClass. It's almost certainly down to the fact<br>that COM objects generally use 1-based indexing, while Python
<br>ones use 0-based.<br><br>Do it this way:<br><br><code><br>import win32com.client.gencache import EnsureDispatch<br><br>MAPISession = EnsureDispatch ("MAPI.Session")<br>MAPISession.Logon ()<br>for n in range (len (
MAPISession.InfoStores)):<br> # n will be 0, 1, 2, 3... while<br> # InfoStores items are 1, 2, 3...<br> # so add 1 to make up the difference<br> store = MAPISession.InfoStores[1 + n]<br> print store.Name<br><br></code>
<br><br>TJG<br><br>________________________________________________________________________<br>This e-mail has been scanned for all viruses by Star. The<br>service is powered by MessageLabs. For more information on a proactive
<br>anti-virus service working around the clock, around the globe, visit:<br><a href="http://www.star.net.uk">http://www.star.net.uk</a><br>________________________________________________________________________<br>_______________________________________________
<br>Python-win32 mailing list<br><a href="mailto:Python-win32@python.org">Python-win32@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/python-win32">http://mail.python.org/mailman/listinfo/python-win32</a>
<br></blockquote></div><br><br clear="all"><br>-- <br>"You don't stop laughing because you grow old. You grow old because you stop laughing." -- Michael Pritchard