码迷,mamicode.com
首页 > 其他好文 > 详细

装饰器

时间:2016-08-13 15:40:46      阅读:152      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!