-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.py
More file actions
45 lines (36 loc) · 838 Bytes
/
Copy pathdecorator.py
File metadata and controls
45 lines (36 loc) · 838 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
import functools
def log(func):
@functools.wraps(func)
def wrapper(*args,**kw):
print("call %s():" % func.__name__)
return func(*args, **kw)
return wrapper
@log
def now():
print("2015-3-25")
now()
print(now.__name__)
def logger(text):
def decorator(func):
@functools.wraps(func)
def wrapper(*args,**kw):
print("%s %s():" % (text, func.__name__))
return func(*args,**kw)
return wrapper
return decorator
@logger("DEBUG")
def today():
print("2015-3-25")
today()
print(today.__name__)
def beginend(func):
def wrapper(*args,**kw):
print("call %s():" % func.__name__)
func(*args,**kw)
print("end %s():" % func.__name__)
return
return wrapper
@beginend
def printdate():
print("2015-7-3")
printdate()