decorators.py 文件源码

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

项目:CartoonPy 作者: bxtkezhan 项目源码 文件源码
def preprocess_args(fun, varnames):
    """ Applies fun to variables in varnames before launching the function """

    def wrapper(f, *a, **kw):
        """ MPOCode.
        if hasattr(f, "func_code"):
            func_code = f.func_code  # Python 2
        else:
            func_code = f.__code__  # Python 3
        """
        func_code = f.__code__ 

        names = func_code.co_varnames
        new_a = [
            fun(arg) if (name in varnames) else arg
            for (arg, name) in zip(a, names)
        ]
        new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
        return f(*new_a, **new_kw)

    return decorator.decorator(wrapper)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号