Nick Coghlan added the comment: We actually use a variant of this idea in the test suite (http://docs.python.org/dev/library/test#test.support.captured_stdout)
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') ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15805> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com