[python-win32] Problem after running MakePy

Rudy Schockaert rudy.schockaert at gmail.com
Fri Dec 9 15:31:20 CET 2005


This does indeed work.

Is there a way to modify the generated code such tat it works with 1-based
iterators instead of 0-based ones?

I tried to modify the _getitem_ method by incrementing item before it
executes

return self._get_good_object_....

and then I get the correct list of Infostores, but directly after that I get
another 'invalid index' error.


On 12/9/05, Tim Golden <tim.golden at viacom-outdoor.co.uk> wrote:
>
> [Rudy Schockaert]
>
> > I have a python program that does some things on
> > Exchange mailboxes. I use the MAPI.Session object
> > for this and create it like this:
>
> > import win32com.client
> > MAPISession = win32com.client.Dispatch("MAPI.Session")
> > MAPISession.Logon()
> > for infostores in MAPISession.InfoStores:
> >   print infostores.Name
>
> > If I now use makepy to create a genpy for the CDO 1.21
> > library (MAPI.Session) I get the following result:
>
> [... snip ...]
>
> > Traceback (most recent call last):
> >   File "<interactive input>", line 1, in ?
> >   File
> "C:\Python24\lib\site-packages\win32com\gen_py\3FA7DEA7-6438-101B-ACC1-0
> 0AA00423326x0x1x21.py ", line 3039, in > __getitem__
> >     return self._get_good_object_(self._oleobj_.Invoke(*(21, LCID, 2,
> 1, item)), "Item")
> > com_error: (-2147352565, 'Invalid index.', None, None)
>
> OK, this is the quick get-you-working answer. For the longer answer,
> I'd have to look at the makepy-generated module and at the code
> for the DispatchBaseClass. It's almost certainly down to the fact
> that COM objects generally use 1-based indexing, while Python
> ones use 0-based.
>
> Do it this way:
>
> <code>
> import win32com.client.gencache import EnsureDispatch
>
> MAPISession = EnsureDispatch ("MAPI.Session")
> MAPISession.Logon ()
> for n in range (len (MAPISession.InfoStores)):
>   # n will be 0, 1, 2, 3... while
>   #  InfoStores items are 1, 2, 3...
>   #  so add 1 to make up the difference
>   store = MAPISession.InfoStores[1 + n]
>   print store.Name
>
> </code>
>
> TJG
>
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>



--
"You don't stop laughing because you grow old. You grow old because you stop
laughing."  -- Michael Pritchard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051209/8421cce1/attachment.html


More information about the Python-win32 mailing list