def redirect_stderr(x):
""" Redirects stderr to another file-like object.
This is some compatibility code to support Python 3.4.
"""
if hasattr(contextlib, 'redirect_stderr'):
result = contextlib.redirect_stderr
else:
@contextlib.contextmanager
def result(x):
""" Stand-in for Python 3.5's `redirect_stderr`.
Notes: Non-reentrant, non-threadsafe
"""
old_stderr = sys.stderr
sys.stderr = x
yield
sys.stder = old_stderr
return result(x)
###############################################################################
评论列表
文章目录