How to script an OLE component using Python

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?

Asked by: Brooke958 | Posted: 28-01-2022

Answer 1

"Python and COM" contains an example. OLE is related to COM and ActiveX so you should look for those terms.

"Python Programming on Win32" is a useful book. There is also a "Python Win32" mailing list.

Answered by: Tess452 | Posted: 01-03-2022

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

Answered by: Aston296 | Posted: 01-03-2022

Answer 3

win32com is a good package to use if you want to use the IDispatch interface to control your objects, but it's slow.

comtypes is a better, native Python, package that uses the raw COM approach to talk to your controls.

WxPython uses comtypes to give you an ActiveX container window from Python.

Answered by: Brad514 | Posted: 01-03-2022

Answer 4

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

Answered by: Catherine574 | Posted: 01-03-2022

Answer 5

PythonWin (, bundled with python-win32, comes with its own COM browser as part of its shell and debugging environment.

Answered by: Grace220 | Posted: 01-03-2022

Similar questions

java - A server side component for tracking a large number of RSS & Atom feeds

I am looking for an open source component that can help me track a large number of RSS feeds (>> 10K RSS sources). I don't care about the programming language, but it should be something with a simple API where I can add or remove RSS feeds and asynchronously receive notifications every time an RSS is updated. Preferably in Java or Pyt...

Python: reload component Y imported with 'from X import Y'?

In Python, once I have imported a module X in an interpreter session using import X, and the module changes on the outside, I can reload the module with reload(X). The changes then become available in my interpreter session. I am wondering if this also possible when I import a component Y from module X using from X import Y. The statement reload Y does not...

python - Separate image of text into component character images

I'd like to separate an image of text into it's component characters, also as images. For example, using the sample below I'd end up with 14 images. I'm only going to be using text on a single line, so the y-height is unimportant - what I need to find is the beginning and end of each letter and crop to those coordinates. That way I would also avoid problems with 'i','j', etc. I'm new to image processing, a...

python - Remove Last Path Component In a String

I have a path: myPath = "C:\Users\myFile.txt" I would like to remove the end path so that the string only contains: "C:\Users" So far I am using split, but it just gives me a list, and im stuck at this point. myPath = myPath.split(os.sep)

python - How to best organize the rules component of a Django system?

I'm designing (and ultimately writing) a system in Django that consists of two major components: A Game Manager: this is essentially a data-entry piece. Trusted (non-public) users will enter information on a gaming system, such as options that a player may have. The interface for this is solely the Django admin console, and it doesn't "do" anything except hold the information. A Character Manager: ...

python com component does not register when using libxml2 on win7

i've built a com component which utilizes libxml2 python bindings , the build is successfull but when i try to register the component i get "specified module could not be found , unable to load python dll" this is the error i get when the component is built using the bundle files option set as 1 if i build the component with bundle files set as 3 ,then i get a different er...

Fast component labelling in python and opencv

I'm implementing the component labelling algorithm as in this paper using python and opencv. It requires checking the input image pixel-by-pixel and perform the so-called contour tracing subroutine to assign label to the blobs of a binary image. I manage to have it running, but it seems very slow. Profiling the code shows that the f...

python - Validate email local component

I'm writing a registration form that only needs to accept the local component of a desired email address. The domain component is fixed to the site. I am attempting to validate it by selectively copying from validators.validate_email which Django provides for EmailField: email_re = re.compile( r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-ato...

python - A way to replace actual component with a stub

I'm having issue with arranging code to make it easily testable. I have 2 major modules in my code: cache generator and modifier builder, both have approximately the same level of complexity. Modifier builder is used in one of the methods of child objects of cache generator. I already have full test suite which covers functionality of modifier builder. I want to add tests which cover all functionality of cache gene...

python - How do you find out if the string is a component of the preceding string

I am trying to write a function that will look at a list of strings and determine if the next string in the list is a sub-string of the preceding string. So if I had a list of ['Ryan', 'Rya', 'Ry', 'Testing', 'Test'] I will get back ['Ryan', 'Rya', 'Ry', 'Test']. I'm not really sure where to even start here.

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python