ITPub博客

首页 > IT职业 > IT生活 > python装饰器 运行时间

python装饰器 运行时间

IT生活 作者:petterchx 时间:2021-09-09 09:27:03 0 删除 编辑

#/usr/bin/env python3


import time

def outer(key):

    def timer(func):

        def wrapper(*args,**kwargs):

            print(key)

            s=time.time()

            res=func(*args,**kwargs)

            e=time.time()

            print(e-s)

            return res

        return wrapper

    return timer


@outer('dec info')

def do(a):

    time.sleep(1)

    print(a)

    return a+1

图片描述

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4606/viewspace-2809954/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-24

  • 博文量
    131
  • 访问量
    30135