Alex Martelli aleaxit at
Sun Sep 10 00:48:20 CEST 2000

<ramesh4954 at> wrote in message
news:8pe2u8$9sl$1 at
> How do I get the actual error message from a com_error? When I try to
> print the details I get the following :
> <pywintypes.com_error instance at 902e60>
> Any help would be appreciated. Thanks

Use the .args member of the error object.  Example:

>>> import pywintypes
>>> import win32com.client
>>> try: foo=win32com.client.Dispatch("Not.There")
... except pywintypes.com_error, erob: print 'caught'
>>> erob
<pywintypes.com_error instance at 14ca800>
>>> print erob
(-2147221005, 'Invalid class string', None, None)
>>> dir(erob)
>>> erob.args
(-2147221005, 'Invalid class string', None, None)
>>> erob.args[0]
>>> erob.args[1]
'Invalid class string'


More information about the Python-list mailing list