difference between pywintypes and pythoncom for com_error

谁都会走 提交于 2020-07-22 05:21:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!