一个典型的装饰器

时间:2020-06-19 10:36:19   收藏:0   阅读:45
import time


def count_time(func):
    def wrapper(*args, **kwargs):
        start_time = time.time()
        count = func(*args, **kwargs)
        print(程序共计%s秒 % (time.time() - start_time))
        return count

    return wrapper


@count_time
def main(count):
    for i in range(1, count):
        for j in range(i):
            print(j)
    return count


if __name__ == __main__:
    print(main(100))

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!