def debug(func):
def wr(*args, **kwargs):
# *:代指元组,长度不限
# **:代表键值对,个数不限
# args[0]值为Shawn, args[1]值为111
instance, selector = args[0], args[1]
print(instance)
print(selector)
print('[DEBUG]: enter {}()'.format(func.__name__))
return func(*args, **kwargs)
return wr
@debug
def say_hello(name, something):
print('hello!{}{}'.format(name, something))
if __name__ == '__main__':
say_hello('Shawn', '111')
可变参数的装饰器函数
于 2022-04-22 15:05:09 首次发布