一个典型的装饰器

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))

 

posted @ 2020-06-19 10:12  John-Python  阅读(131)  评论(0编辑  收藏  举报