Python装饰器基本框架
装饰器示例:
def auth(func): def inner(*args, **kwargs):
# 固定套路,在装饰的函数前做什么 func(*args, **kwargs) return inner @auth # 相当于login = auth(login) def login(): pass @auth # 相当于shopping = auth(shopping) def shopping(): pass @auth # 相当于pay = auth(pay) def pay(money, time): total_money = money + 1 pay_time = time print(total_money, pay_time)