之前在flask里面写路由用的比较多...后来发现挺好用的套路,比如:打印程序片段运行时间什么的

  1. 定义装饰器
import time
def printTimer(func):
    def my_timer():
        start = time.time()
        func()
        end = time.time()
        print(f'[+]{func.__name__}程序用时:{(end - start):.3f}秒')
    return my_timer
  1. 使用装饰器
@printTimer
def process():
    main.process(para)