-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorators-3.py
35 lines (25 loc) · 804 Bytes
/
decorators-3.py
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
# This is an updated version of decorators-2.py.
# Here, the `decorated()` function takes an argument
# and prints it back on terminal.
# When the decorator `@my_decorator` is called, it
# takes the function `decorated()` as its argument, and
# the argument of `decorated()` as the argument of `inner_decorator()`.
# Hence the arg `number` is passed to `num_copy`.
import datetime
def my_decorator(inner):
def inner_decorator(num_copy):
print(datetime.datetime.utcnow())
inner(int(num_copy) + 1)
print(datetime.datetime.utcnow())
return inner_decorator
@my_decorator
def decorated(number):
print("This happened : " + str(number))
if __name__ == "__main__":
decorated(5)
'''
O/P-
2022-07-16 12:26:14.060603
This happened : 6
2022-07-16 12:26:14.060603
'''