小册名称:Python合辑14-面向对象编程案例(下)
def my_decorator(func): def wrapper(): print("Step - 1") func() print("Step - 3") return wrapper@my_decoratordef start_steps(): print("Step - 2")start_steps()
def my_decorator(func):
def wrapper():
print("Step - 1")
func()
print("Step - 3")
return wrapper
@my_decorator
def start_steps():
print("Step - 2")
start_steps()
Output:
Step - 1Step - 2Step - 3
Step - 1
Step - 2
Step - 3