python——装饰器例子一个

      1 ##装饰器
      2 #!/usr/bin/env  python
      3 
      4 from time import ctime , sleep
      5 
      6 def tsfunc(func):
      7     def wrappedFunc():
      8         print '[%s] %s called' %(ctime(), func.__name__)
      9         return func() 
     10     return wrappedFunc
     11 
     12 
     13 @tsfunc
     14 def foo():
     15     pass
     16 
     17 foo()
     18 sleep(4)
     19 
     20 for i in range(2):
     21     sleep(1)
     22     foo()
~                    
原文地址:https://www.cnblogs.com/xupeizhi/p/2610096.html