contexttools.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:kur 作者: deepgram 项目源码 文件源码
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)

###############################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号