-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheloworld.py
More file actions
100 lines (46 loc) · 1.57 KB
/
heloworld.py
File metadata and controls
100 lines (46 loc) · 1.57 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#decorators
def decorated_function(original_function):
#allow us to accept any arbitrary number of arguments
def wrapper_funtion(*args, **kwargs):
print("wrapper executed here, before {} funtion".format(original_function.__name__))
return original_function(*args, **kwargs)
return wrapper_funtion
#@decorated_function
def display_info(name, age):
print(" {} is of {} years old, and this run with arguments".format(name, age))
#display_info("ali", 19)
#class decorators
#@decorated_class
def display_info(name, age):
print(" {} is of {} years old, and this run with arguments".format(name, age))
#display_info("ali", 19)
def logging_funtion(original_function):
import logging
logging.basicConfig(filename='{}.log'.format(original_function.__name__), level=logging.INFO)
def wrapper_funtion(*args,**kwargs):
logging.info(
"ran with arguments {}, and Kwargs {}".format(*args,**kwargs))
return original_function(*args, **kwargs)
return wrapper_funtion
@logging_funtion
def display_info(name, age):
print(" {} is of {} years old, and this run with arguments".format(name, age))
def time_funtion(original_function):
import time
def wrapper_funtion(*args, **kwargs):
t1 = time.time()
result= original_function(*args, **kwargs)
t2 = time.time() - t1
print ('{} ran in this much {} sec'.format(original_function.__name__, t2))
return result
return wrapper_funtion
import time
@time_funtion
def demo_funtion(a,b):
time.sleep(0)
sum1=a+b
m1=a*b
return sum1, m1
ahm=demo_funtion(9,8)
print(ahm)
print(demo_funtion.__name__)