装饰器-3

[root@node110 decorator]# cat temp_decorator.py

#!/usr/bin/env python

import time

def time_counter(func):

  def wrapper():

    start =time.time()

    func()

    end =time.time()

    print 'Thisfunction costs:',end-start

  return wrapper

 

 

#sayhi=time_counter(sayhi)

#sayhi()

@time_counter   

#相当于sayhi=time_counter(sayhi)

#sayhi()

 

def sayhi():

  print 'hi yoursister...'

  time.sleep(0.1)

 

@time_counter

def tellyoursalary():

  print 'Allenmakes 25k per month...'

 

sayhi()

tellyoursalary()

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS