[issue15805] Add stdout redirection tool to contextlib
Barry A. Warsaw
report at bugs.python.org
Tue Jul 23 14:53:35 CEST 2013
Barry A. Warsaw added the comment:
On Jul 23, 2013, at 04:24 AM, Alexander Belopolsky wrote:
>@contextlib.contextmanager
>def redirect_stdout(stream):
> old_stdout = sys.stdout
> sys.stdout = stream
> yield
> sys.stdout = old_stdout
Make that:
@contextlib.contextmanager
def redirect_stdout(stream):
old_stdout = sys.stdout
sys.stdout = stream
try:
yield
finally:
sys.stdout = old_stdout
and I'll be able to remove those 8 lines of code from all my other code bases
:)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15805>
_______________________________________
More information about the Python-bugs-list
mailing list