-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDecorators_.py
88 lines (61 loc) · 1.32 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
80
81
82
83
84
85
86
87
88
# def function1():
# print("Hello World")
#
# func2 = function1
# del function1
# func2()
# def funcret(num):
# if num==0:
# return print
# if num==1:
# return sum
#
# a = funcret(1)
# print(a)
# def executor(func):
# func("this")
#
#
# executor(print)
def dec1(func1):
def nowexec():
print("Executing now")
func1()
print("Executed")
return nowexec
@dec1
def who_is_arnav():
print("Arnav is a good boy")
# who_is_arnav = dec1(who_is_arnav)
who_is_arnav()
"""//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"""
#ANOTHER COMPLEX PROGRAM
def star(func):
def inner(*args, **kwargs):
print("*" * 30)
func(*args, **kwargs)
print("*" * 30)
return inner
def percent(func):
def inner(*args, **kwargs):
print("%" * 30)
func(*args, **kwargs)
print("%" * 30)
return inner
@star
@percent
def printer(msg):
print(msg)
printer("Hello")
#HERE'S ANOTHER
def smart_divide(func):
def inner(a, b):
print("I am going to divide", a, "and", b)
if b == 0:
print("Whoops! cannot divide")
return
return func(a, b)
return inner
@smart_divide
def divide(a, b):
print(a/b)