Strange method signature via COM

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Mar 2 15:08:32 EST 2007


Richard Jebb a écrit :
> We are trying to use the API of a Win32 app which presents the API as a COM
> interface. The sample VB code for getting and setting the values of custom
> data fields on an object shows a method named Value():
> 
> getter        obj.Value("myfield")
> setter        obj.Value("myfield") = newvalue
> 
> Using Python 2.5 and PythonWin we can get data from data fields using the
> identical syntax

I have no experience with Python/COM, but IIRC, in VB (at least in VB6), 
the parens are also used for array subscript.

> 
>>>>print comp.Value("Phone1")
> 99080980
> 
> However the set value fails (unsurprisingly)
> 
> 
>>>>comp.value("Phone1") = "6876876876"
> 
> SyntaxError: can't assign to function call
> 
> Does anyone have any idea how to use Python to address this type of method
> signature? 

Have you tried inspecting your COM object in an interactive Python 
shell, using dir(), help() and the inspect module ?

And FWIW, disd you try the following syntaxes:
comp.value['Phone1'] = "xxx"
comp['Phone1'] = "xxx"

My 2 cents



More information about the Python-list mailing list