python中一层装饰器的函数可以带参数吗

(分钟前 更新) 401 7513

最新回答

可以的,

装饰器分为可带参数和不可带参数的两种;但是如果带参数,回则带参数装答饰器的“参数”及“return”必须也是一个装饰器

具体可以参考一下下面的例子:

def deco1(func):
def w(x,*args,**kw):
print "this is deco1"
return x + " decorator"
return w

def deco2(deco):
print "this is deco2"
return deco

@deco2(deco1)
def func(x):
return x

print func("Hello")
不锈冰theresa 2024-05-16

扩展回答

热门问答

装修专题

首页 >  python中一层装饰器的函数可以带参数吗

其他人还看了

页面运行时间: 0.046451091766357 秒