Redirect stderr using the ‘with’-statement:
>>> from __future__ import with_statement
>>> from redirect_io import *
>>> with hidden_stderr():
... print >> sys.stderr, 'Divide By Cucumber Error'
>>>
Redirect stderr to stout:
>>> with hidden_stderr(sys.stdout):
... print >> sys.stderr, 'Where am I ?'
Where am I ?
>>>
Optinal usage without ‘with’-statement:
>>> _redirect_err()
>>> try:
... print >> sys.stderr, " +++ Divide by Cucumber Error, "\
... "Please ReInstall Universe And Reboot +++"
... finally:
... _return_err()
>>>
Fetch previous error messages:
>>> print _tmp_err.getvalue()
Divide By Cucumber Error
+++ Divide by Cucumber Error, Please ReInstall Universe And Reboot +++
>>>