最基本的装饰器,不带参数:

import time

def wrapper(func):

  def inner(*args,**kwargs):

    start=time.time()

    ret=func(*args,**kwargs)

    end=time.time()

    print(end-start)

    return ret

  return inner

@timmer

def wahaha():

  time.sleep(0.1)

  print("wahahahhahahahahah")

@timmer

def erguotou():

  time.sleep(0.1)

  print("erguotouerguotou")

但是该装饰器没有参数,我们想要带有参数:

 以下函数说明了多层装饰器的嵌套:

结果是