forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wrap.py
More file actions
47 lines (36 loc) · 923 Bytes
/
test_wrap.py
File metadata and controls
47 lines (36 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# encoding: utf-8
"""
@author: zhanghe
@software: PyCharm
@file: test_wrap.py
@time: 2017/7/28 下午2:14
"""
from functools import wraps
def singleton(func):
@wraps(func)
def getinstance(*args, **kw):
back_func = func(*args, **kw)
return back_func
@singleton
class MyClass(object):
a = 1
def time_log(func):
"""
装饰器
:param func:
:return:
"""
def wrapper(*args, **kw):
func_name = func.__name__
start_time = time.time()
print '方法%s开始时间:%s' % (func_name, time.ctime())
back_func = func(*args, **kw)
end_time = time.time()
run_time = end_time - start_time
print '方法%s结束时间:%s' % (func_name, time.ctime())
print '方法%s运行时间:%0.2fS' % (func_name, run_time)
return back_func
return wrapper
if __name__ == '__main__':
pass