-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
43 lines (31 loc) · 805 Bytes
/
decorators.py
File metadata and controls
43 lines (31 loc) · 805 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
# -*- coding: utf-8 -*-
"""
simple study of decorators
"""
# First example
def outerfunction(outer):
print("test")
def innerfunction(inner):
return outer(inner) + 1
return innerfunction
@outerfunction
def addone(x):
return x + 1
# Second Example
def wrapfunction(fn):
print("Executing wrapfunction")
def wrappedfunction():
print("Calling %s inside wrappedfunction" % fn.__name__)
# calling fn
fn()
print("Executed %s inside wrappedfunction" % fn.__name__)
return wrappedfunction
@wrapfunction
def tobedecorated():
print("Executing tobedecorated function")
if __name__ == "__main__":
# pass
# first example
# print(addone(5))
# second example
tobedecorated()