如何将函数输出传递给装饰器

时间:2018-03-30 08:41:59

标签: python python-3.x python-decorators

我是Python装饰者的新手。我能够在不传递任何参数的情况下运行装饰器。并且工作正常。

我有兴趣将to_decorator值传递给装饰器函数,如下所示。

这可能吗?

 def test(self, *args):
    return "from test"


def decorate(function):
    def wrap_function(*args, **kwargs):
        print(*args)
        return function(*args, **kwargs)

    return wrap_function


class Sample():
    @decorate
    def message(*args, **kwargs):
        to_decorator = test(*args)
        print(to_decorator)


Sample.message("Hello123")

提前致谢。

0 个答案:

没有答案
相关问题