我正在尝试创建一个具有多个参数的装饰器。但是,它似乎并不总是在接收解包函数。
def wait(*args, **kwargs):
print("args == ", args)
str_kwargs = "\n".join(str(x) for x in kwargs.keys())
print("kwargs: " + str_kwargs if len(str_kwargs) > 1 else "no kwargs")
return args[0]
#######################################################
print("begin test 1")
@wait
def print_something_else(something):
print (something)
#######################################################
print("begin test 2")
def print_something_else(something):
print(something)
print_something_else = wait(print_something_else, delay=0.2)
#######################################################
print("begin test 3")
@wait(delay=0.2)
def really_print_something_else(something):
print (something)
对于测试3,args
为空。我们仅收到delay
。就像我们写了:
really_print_something_else = wait(delay=0.2)