问题
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.
来源:https://stackoverflow.com/questions/9446844/win32com-python-error