Strange method signature via COM

R

Richard Jebb

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
99080980

However the set value fails (unsurprisingly)
SyntaxError: can't assign to function call

Does anyone have any idea how to use Python to address this type of method
signature? Would MakePy allow us to see how we should be calling it?

All suggestions welcome!
 
B

Bruno Desthuilliers

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.
99080980

However the set value fails (unsurprisingly)



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
 
R

Richard Jebb

After digging around in the group archives I've figured it out. It's not
been helped by my inability to identify the API's COM server/type library in
the list produced by the MakePy utility, so I've largely been flying blind.

Some posts on this same subject back in 1999 revealed the answer, namely
that when win32com encounters a method signature like the one we had, it
expects you to call it like this:

obj.Value("myfield", "newvalue")

If there already exists an interface to Value() with this signature, then it
prepends the original method name with "Set", so that in Python you would
call

obj.SetValue("myfield", "newvalue")

We still have some other issues with the API, but I'm hoping once the
application vendor has revealed what name it will appear under in MakePy we
will be able to sort those out as well.


Bruno Desthuilliers said:
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.
99080980

However the set value fails (unsurprisingly)



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top