from functools import wraps class remarkable: """类装饰器""" def __init__(self, blanklines=0, ps="这是一个带参数示例的装饰器"): self.blanklines = blanklines self.ps = ps def __call__(self, func): @wraps(func) def inner(*args, **kwargs): print("\n" * self.blanklines) func(*args, **kwargs) print("\n" * self.blanklines) print(self.ps) return inner @remarkable(blanklines=2, ps="这是一个带参数示例的装饰器") def sayHello(name, *args, boss=None, **kwargs): print("{}:HELLO WORLD.{}-{}-{}".format(name, args, boss, kwargs)) sayHello("张三", "李四", "王麻子", boss="洪七公", father="鱼")