In Python, if I open a binary file that doesn\'t exist, the program exits with an error and prints:
Traceback (most recent call last):
File \"C:\\Python_te
If you want to capture the exception object passed by the Exception, it's best to start using the NEW format introduced in Python 2.6 (which currently supports both) because it will be the only way to do it into Python 3.
And that is:
try:
...
except IOError as e:
...
Example:
try:
pkfile = open('monitor.dat', 'rb')
except IOError as e:
print 'Exception error is: %s' % e
A detailed overview can be found at the What's New in Python 2.6 documentation.