forked from Shwetha-Kalavara/Python_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasics (6).py
More file actions
47 lines (24 loc) · 794 Bytes
/
Copy pathbasics (6).py
File metadata and controls
47 lines (24 loc) · 794 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# def display(x): # monkey patching add function's address with x
# print("Executing display")
# return x # returning function address from a function
#
#
# def add(a, b):
# print(a + b)
# add = display(add) # passing function as argument
# add(1, 2)
#############################################################################
def display(x):
def wrapper(*args, **kwargs):
print("executing display")
return x(*args, **kwargs)
return wrapper # add -> wrapper
@display # add = display(add)
def add(a, b):
return a + b
# add = display(add) # x --> add
print(add(1, 2))
@ display # sub = display(sub)
def sub(a, b, c):
print(a - b - c)
sub(1, 2, 3)