windows 如何使用 Python 编写 OLE 组件的脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/279094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:35:26  来源:igfitidea点击:

How do I script an OLE component using Python?

pythonwindowsscriptingactivexole

提问by joeforker

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

我想使用 Python 编写一个应用程序的脚本,该应用程序将自己宣传为提供 OLE 组件。我应该如何开始?

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?

我还不知道我需要在我将访问的组件上调用什么方法。我应该使用 win32com 加载这些组件,然后在 IPython 中开始按“tab”吗?

采纳答案by Brian Lyttle

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?

你可以在这个网站上找到一个例子。OLE 并且与 COM 和 ActiveX 相关,因此您应该注意这些术语。您可以从 O'Reilly - Python Programming on Win32访问这本书吗?

There is also a Python Win32mailing list.

还有一个Python Win32邮件列表。

回答by Ali Afshar

You need the win32compackage. Some examples:

您需要win32com包。一些例子:

from win32com.client.dynamic import Dispatch

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

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

And then call whatever you like on them.

然后随意调用它们。

回答by ZebZiggle

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.

如果你想使用 IDispatch 接口来控制你的对象(慢),win32com 是一个很好的包。comtypes 是一个更好的原生 Python 包,它使用原始 COM 方法与您的控件对话。WxPython 使用 comtypes 为您提供一个来自 Python 的 ActiveX 容器窗口......甜蜜。

回答by Martin v. L?wis

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

请查看python-win32包,特别是它的 win32com API。

回答by joeforker

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

PythonWin ( http://sourceforge.net/projects/pywin32/) 与 python-win32 捆绑在一起,带有自己的 COM 浏览器作为其外壳和调试环境的一部分。