Python COM problem - accessing properties with optional parameters

Dave Kirby dkirby at orchestream.com
Fri Jun 28 12:45:37 EDT 2002


I am using Python to access the Microsoft Accessibility interface.  I have
got as far as getting an IAccessible object, but am having problems calling
some of its methods.

The problem is that some of the methods are declared as properties with
[propget] or [propput] in the IDL, but also have optional parmeters.  For
example:

  [hidden, propget, id(DISPID_ACC_NAME)] HRESULT accName([in, optional]
VARIANT varChild,[out, retval] BSTR* pszName);

if I have a an object called obj I can access the property accName like
this:

>>> obj.accName
u'Some Object Name'
>>>

which is all fine and good.  However there are times when I need to call the
accName method with an int parameter, e.g.

>>> obj.accName(0)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: object of type 'unicode' is not callable
>>>

this obviously doesnt work, since it treating it as a property and returning
a string, then trying to call that string as a function.

Is there any way to access the function without it being treated as a
property?  I tried calling the IDispatch functions directly, but that didn't
work:

>>> obj.GetIDsOfNames('accName')
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<COMObject AccessibleObjectFromWindow>", line 2, in GetIDsOfNames
com_error: (-2147352573, 'Member not found.', None, None)

I am stumped on this, so any pointers would be appreciated.

I am using ActivePython build 2.1.212, by the way.

Also, are there any mailing lists or discussion groups specifically for
COM/Windows Python programming anywhere?

Regards,


                Dave Kirby






More information about the Python-list mailing list