import time
def DecoUserPrint(UserFunc):#定义一个DecoUserPrint接收参数的多重方法
    def DecoPrint():
        StartTime = time.time()
        UserFunc()#执行DecoPrint接收的方法
        OverTime = time.time()
        print(OverTime-StartTime)
    return DecoPrint
@DecoUserPrint#为下方的,方法调用装饰器,UserPrint = DecoUserPrint(UserPrint)
def UserPrint():
    time.sleep(1)
    print("egon")
UserPrint()#执行被修饰的UserPrint方法

 

相关文章:

  • 2021-07-01
  • 2021-06-16
  • 2021-12-11
  • 2021-12-29
  • 2021-04-22
  • 2021-10-15
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2021-10-02
  • 2022-01-12
  • 2021-12-17
  • 2022-12-23
  • 2021-06-16
  • 2021-11-17
相关资源
相似解决方案