Python装饰器
1 #!/usr/bin/env python
2 #coding:utf8
3 import time
4 def timeit(func):
5 print "start at: ",time.ctime()
6 newlist = func()
7 print "stop at: ",time.ctime()
8 return newlist
9
10
11 def loop(n = 10):
12 time.sleep(1)
13 mylist = []
14
15 for i in range(n):
16 if i % 2:#%2 有余数
17 mylist.append(i)
18
19 return mylist
20
21 print timeit(loop)
~
~