-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorators.py
79 lines (57 loc) · 1.38 KB
/
decorators.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
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
# # # Decorators are used to enhance the function's ability
# # def function1():
# # print("Hello World")
# # func2 = function1
# # del function1
# # func2()
# # # Function callng function as an argument
# # def funcret(num):
# # if num==0:
# # return print
# # if num==1:
# # return sum
# # a = funcret(0)
# # print(a)
# # a = funcret(1)
# # print(a)
# # also
# # def executor(func):
# # func("This is func")
# # executor(print)
# # # decorator concept
# # doing threw normal way
# # def dec1(func1):
# # def nowexe():
# # print("Executing Now")
# # func1()
# # print("Executed")
# # return nowexe
# # def who_is_nitesh():
# # print("Nitesh is a good boy")
# # who_is_nitesh = dec1(who_is_nitesh)
# # who_is_nitesh()
# # using decorators
# def dec1(func1):
# def nowexe():
# print("Executing Now")
# func1()
# print("Executed")
# return nowexe
# @dec1
# def who_is_nitesh():
# print("Nitesh is a good boy")
# who_is_nitesh()
############################## Seperator ################################
def decorator_function(any_function):
def wrapper():
print("This awesome function")
any_function()
print("ended")
return wrapper
@decorator_function
def func1():
print("This is func1")
def func2():
print("This is func2")
func1()
func2()