win32com (python) error

2019-07-16 04:48发布

问题:

i am trying to automate a action in notepad for a program im working on and i cant figure out an error message i am getting.

import os
import win32com

object = win32com.client.Dispatch("Notepad.Application")

error

Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\win32com\client__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid class string', None, None) any help?

回答1:

Notepad has no COM interface that I can Find. Try using pywinauto. Check this video to see how it works.