问题
What is the difference between pywintypes and pythoncom? I am really new to COM handling using python so a simplified description will be helpful. also I am using a com wrapper to fixed the com error "call is rejected by callee". however the com error is not capture by the exception.
so should I be importing com_error from pywintypes or pythoncom?
from pywintypes import com_error
import win32com.client
class ComWrapper:
@staticmethod
def wrap(func, *func_args):
try:
print('running the function')
return func(*func_args)
except com_error as e:
print('checking the error')
if e.strerror == 'Call was rejected by callee.':
print('com_error retrying ', e)
time.sleep(5)
wrap(func, *func_args)
raise
回答1:
They appear to be the same, and both come from the win32com module. You can see in the sourcecode that pythoncom
imports pywintypes
.
I believe the two names only exist for legacy reasons. This Sourceforge message from 2003 by the win32com
developers seems to shows they were merged to avoid duplicated code.
来源:https://stackoverflow.com/questions/62516209/difference-between-pywintypes-and-pythoncom-for-com-error