-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator_class.py
More file actions
33 lines (23 loc) · 988 Bytes
/
Copy pathdecorator_class.py
File metadata and controls
33 lines (23 loc) · 988 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
""" Decorator Class Sample """
import time
class Timing():
def __init__(self, param_decorator=time.ctime()):
self.param_class = param_decorator
def __call__(self, decorated_function):
""" Called by the system each time we call the decorated_function """
def add_timing(*args_decorated_function,**kwargs_decorated_function):
return f"{self.param_class} : {decorated_function(*args_decorated_function)}"
return add_timing
@Timing()
def addition(a, b):
return f"{a} + {b} = {a + b}"
@Timing(time.ctime())
@Timing("Pacific Standard Time")
def soustraction(a, b):
return f"{a} - {b} = {a - b}"
@Timing(time.ctime())
def multiplication(a, b):
return f"{a} * {b} = {a * b}"
print(addition(20, 10)) # Thu May 18 13:18:47 2023 : 20 + 10 = 30
print(soustraction(20, 10)) # Thu May 18 13:18:47 2023 : Pacific Standard Time : 20 - 10 = 10
print(multiplication(20, 10)) # Thu May 18 13:18:47 2023 : 20 * 10 = 200