Is there a way to take exception handling output from an imported module and process it from the calling program? For example, I have an imported module that writes an HTTP exception
except urllib2.HTTPError, e:
sys.stderr.write(str(e) + '\n')
If a 404 occurs, then the calling programing only sees the following:
HTTP Error 404: not found
Can this be taken as input without modifying the imported module? I would need to perform different tasks depending on the HTTP Error that is returned.
sys.stderris just a file-like object, so before calling the module code you could record the position in the stream and after calling that piece of code just read it from that position to the end.