decorators.py 文件源码

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

项目:builder 作者: elifesciences 项目源码 文件源码
def echo_output(func):
    """if the wrapped function is the sole task being run, then it's output is
    printed to stdout. this wrapper first attempts to pass the keyword
    'verbose' to the function and, if it fails, calls it without.
    """
    @wraps(func)
    def _wrapper(*args, **kwargs):
        if _sole_task(func.__name__):
            res = func(*args, **kwargs)
            errcho('output:') # printing to stderr avoids corrupting structured data
            if isinstance(res, str) or isinstance(res, unicode):
                print res
            else:
                print pformat(remove_ordereddict(res))
            return res
        return func(*args, **kwargs)
    return _wrapper


# avoid circular dependencies.
# TODO: this is a design smell. refactor.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号