Understanding how to use COM in Python

I am trying to implement the equivalent of a VB program in python using COM. Here are the relevant lines from the VB program:

eConCall = New Microsoft.Dynamics.GP.eConnect.eConnectMethods
eConCall.eConnect_EntryPoint(sConnectionString, EnumTypes.ConnectionStringType.SqlClient, myXmlDocument, EnumTypes.SchemaValidationType.None)

In Python, I do:

import win32com.client
eConCall = win32com.client.Dispatch("Microsoft.Dynamics.GP.eConnect.eConnectMethods")

but eConCallhas no method eConnect_EntryPoint. In fact, it has no methods:

eConCall = win32com.client.gencache.EnsureDispatch("Microsoft.Dynamics.GP.eConnect.eConnectMethods")
dir(eConCall)

Print

['CLSID', '_ApplyTypes_', '__doc__', '__eq__', '__getattr__', 
'__init__', '__module__', '__ne__', '__repr__', '__setattr__', 
'_get_good_object_', '_get_good_single_object_', '_oleobj_', 
'_prop_map_get_', '_prop_map_put_', 'coclass_clsid']

I am sure I don’t understand how Dispatch should be used and how I should access eConnectMethodsPython. Can a good soul help me? How do I get an instance of eConnectMethods so I can call it eConnect_EntryPoint?

+3
source share
3 answers

, , , , , , COM IDispatch / - . , VBScript.

, , , - - http://oreilly.com/catalog/pythonwin32/chapter/ch12.html.

COM, IDispatch Python, Excel Word, .

, , . makepy.py(- \Lib\site-packages\win32com\gen_py \.py) IDL COM-. , - , - .

+1

You must consider comtypes that provide low level COM access.

0
source

Source: https://habr.com/ru/post/1794586/


All Articles