This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan, rhettinger
Date 2012-08-29.04:45:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
We actually use a variant of this idea in the test suite (

It would be pretty easy to combine the two concepts by defaulting the redirection to a new StringIO instance if no other destination is given:

print('This goes to stdout')
with redirect_stdout(sys.stderr):
     print('This goes to stderr')
     print('So does this')
print('This goes to stdout')
with redirect_stdout() as s:
     print('This goes to the io.StringIO instance "s"')
     print('So does this')
print('This goes to stdout')
Date User Action Args
2012-08-29 04:45:45ncoghlansetrecipients: + ncoghlan, rhettinger
2012-08-29 04:45:45ncoghlansetmessageid: <>
2012-08-29 04:45:45ncoghlanlinkissue15805 messages
2012-08-29 04:45:44ncoghlancreate