How do I script an OLE component using Python?

主宰稳场 提交于 2019-11-27 18:11:01

问题


I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?

I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?


回答1:


You can find an example on this website. OLE and is related to COM and ActiveX so you should look out for those terms. Do you have access this book from O'Reilly - Python Programming on Win32?

There is also a Python Win32 mailing list.




回答2:


You need the win32com package. Some examples:

from win32com.client.dynamic import Dispatch

# Excel
excel = Dispatch('Excel.Application')

# Vim
vim = Dispatch('Vim.Application')

And then call whatever you like on them.




回答3:


win32com is a good package to use if you want to use the IDispatch interface to control your objects (slow). comtypes is a better, native python, package that uses the raw COM approach to talking to your controls. WxPython uses comtypes to give you an ActiveX container window from Python ... sweet.




回答4:


Please take a look at the python-win32 package, and, in particular, at its win32com API.




回答5:


PythonWin (http://sourceforge.net/projects/pywin32/), bundled with python-win32, comes with its own COM browser as part of its shell and debugging environment.



来源:https://stackoverflow.com/questions/279094/how-do-i-script-an-ole-component-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!