How to use sys.exc_info()???
aleaxit at yahoo.com
Wed Oct 18 22:38:00 CEST 2000
"Roy Smith" <roy at panix.com> wrote in message
news:8sksit$mj1$1 at panix6.panix.com...
> open ('xxx')
> foo = sys.exc_info()
> What I end up with in foo is
> (<class exceptions.IOError at 80a7e20>, <exceptions.IOError instance at
80c82d0>, <traceback object at 80c92c8>)
> What I don't understand is how to go from the 3-tuple I get back from
> exc_info() to the string "No such file or directory"?
>>> try: open('xxx')
(<class exceptions.IOError at 00805E0C>, <exceptions.IOError instance at
00B303FC>, <traceback object at 00B35E80>)
<exceptions.IOError instance at 00B303FC>
['args', 'errno', 'filename', 'strerror']
(2, 'No such file or directory')
'No such file or directory'
So, specifically, what you want is foo.strerror, but there's other
info in the foo instance which you may want to access (and if
you're just testing to see if the specific error is such-and-such,
foo.errno may be handier).
More information about the Python-list