装饰者接受任何论点
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了装饰者接受任何论点相关的知识,希望对你有一定的参考价值。
def decorator_with_args(decorator_to_enhance) : """ This function is supposed to be used as a decorator. It must decorate an other function, that is intended to be used as a decorator. Take a cup of coffee. It will allow any decorator to accept an arbitrary number of arguments, saving you the headache to remember how to do that every time. """ # We use the same trick we did to pass arguments def decorator_maker(*args, **kwargs) : # We create on the fly a decorator that accepts only a function # but keeps the passed arguments from the maker . def decorator_wrapper(func) : # We return the result of the original decorator, which, after all, # IS JUST AN ORDINARY FUNCTION (which returns a function). # Only pitfall : the decorator must have this specific signature or it won't work : return decorator_to_enhance(func, *args, **kwargs) return decorator_wrapper return decorator_maker
以上是关于装饰者接受任何论点的主要内容,如果未能解决你的问题,请参考以下文章