首页 > 其他 > 详细

装饰器

时间:2016-08-13 15:38:47      阅读:111      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Author:DCC

import time

def timer(func):
    def deco(*args,**kwargs):
        # def warpper(*args,**kwargs):
        start_time = time.time()
        func(*args,**kwargs)
        stop_time = time.time()
        print("the func run time is %s" % (stop_time-start_time) )
    return deco

@timer # test1 = timer(test1)
def test1():
    time.sleep(3)
    print("in the test1")
    
@timer # test2 = timer(test2) =deco
def test2(name,age):
    print(name,age)
    print("in the test2")
    
test1()
test2("dcc","25")

 

装饰器

原文:http://www.cnblogs.com/dcc001/p/5767993.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!