m0_70680242 2022-07-24 08:58 采纳率: 82.2%
浏览 14
已结题

python装饰器写法


import time
def timeit(f):#f = myfunc(8)
    def wapper(x):
        start = time.time()
        f(x)
        ret = (time.time()-start)
        return ret
    return wapper
@timeit
def myfunc(x):
    time.sleep(x)

print(myfunc(8))

提问:wapper的x是怎么传进来的

  • 写回答

1条回答 默认 最新

  • 快乐小土狗 2022-07-24 16:30
    关注

    看看这个,慢慢瞅,一步一步的理解
    https://www.runoob.com/w3cnote/python-func-decorators.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月24日
  • 已采纳回答 7月24日
  • 创建了问题 7月24日