-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorator Define Functions Python Program Examples.py
More file actions
202 lines (165 loc) · 7.66 KB
/
Decorator Define Functions Python Program Examples.py
File metadata and controls
202 lines (165 loc) · 7.66 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Decorator Define Functions Python Program Examples:
# Created by JCR, GitHub.com
# Decorator define functions extend the base define function,
# without modifying or changing the base define function.
# Decorators make base define functions more powerful; they
# can be called into the base define function, when you want
# to extend the capabilities of the base define function, via
# invoking the @ symbol along with the name of the decorator
# define function's name, such as @add_define_function_one,
# for example.
# Create as many decorator define functions as you wish.
# Decorator define functions without *args and **kwargs
def add_define_function_one(funct):
def inner_define_function():
print('Add a decorator define function to the base define function.')
funct()
return inner_define_function
def add_define_function_two(funct):
def inner_define_function():
print('Add another decorator define function to the base define function.')
funct()
return inner_define_function
def add_define_function_three(funct):
def inner_define_function():
print('Add a third decorator define function to the base define function.')
funct()
return inner_define_function
def add_define_function_four(funct):
def inner_define_function():
print('Add a fourth decorator define function to the base define function.')
funct()
return inner_define_function
def add_define_function_five(funct):
def inner_define_function():
print('Add a fifth decorator define function to the base define function.')
funct()
return inner_define_function
@add_define_function_one
@add_define_function_two
@add_define_function_three
@add_define_function_four
@add_define_function_five
def base_define_function():
print('Add other decorator define functions to the base define \
function,\nwithout modifying or changing the base define function.')
base_define_function()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Decorator define functions with *args and **kwargs
def add_define_function_one(funct):
def inner_define_function(*args,**kwargs):
print('Add a decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_two(funct):
def inner_define_function(*args,**kwargs):
print('Add another decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_three(funct):
def inner_define_function(*args,**kwargs):
print('Add a third decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_four(funct):
def inner_define_function(*args,**kwargs):
print('Add a fourth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_five(funct):
def inner_define_function(*args,**kwargs):
print('Add a fifth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
@add_define_function_one
@add_define_function_two
@add_define_function_three
@add_define_function_four
@add_define_function_five
def base_define_function():
print('Add other decorator define functions to the base define \
function,\nwithout modifying or changing the base define function.')
base_define_function()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's create the same decorator define function Python program
# example as above. However, let's also give the base define function
# some argument variables of its own.
def add_define_function_one(funct):
def inner_define_function(*args,**kwargs):
print('Add a decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_two(funct):
def inner_define_function(*args,**kwargs):
print('Add another decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_three(funct):
def inner_define_function(*args,**kwargs):
print('Add a third decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_four(funct):
def inner_define_function(*args,**kwargs):
print('Add a fourth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_five(funct):
def inner_define_function(*args,**kwargs):
print('Add a fifth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
@add_define_function_one
@add_define_function_two
@add_define_function_three
@add_define_function_four
@add_define_function_five
def base_define_function(text1,text2,text3):
print(f'Add other {text1} define functions to the {text2} define \
{text3},\nwithout modifying or changing the {text2} define {text3}.')
base_define_function('decorator','base','function')
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's create the same decorator define function Python program
# example as above. However, let's also give the base define function
# only one argument variable of its own, via invoking the *args prefix
# to satisfy as many argument placeholder values as we wish. We
# have to use index brackets with index numbers [n] to call up each
# argument placeholder value: 'decorator','base','function', via invoking
# args[n] to do the job. Note: you can call *args any name you wish, but
# the argument variable name 'args' is the standard for the *args prefix.
def add_define_function_one(funct):
def inner_define_function(*args,**kwargs):
print('Add a decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_two(funct):
def inner_define_function(*args,**kwargs):
print('Add another decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_three(funct):
def inner_define_function(*args,**kwargs):
print('Add a third decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_four(funct):
def inner_define_function(*args,**kwargs):
print('Add a fourth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
def add_define_function_five(funct):
def inner_define_function(*args,**kwargs):
print('Add a fifth decorator define function to the base define function.')
funct(*args,**kwargs)
return inner_define_function
@add_define_function_one
@add_define_function_two
@add_define_function_three
@add_define_function_four
@add_define_function_five
def base_define_function(*args):
print(f'Add other {args[0]} define functions to the {args[1]} define \
{args[2]},\nwithout modifying or changing the {args[1]} define {args[2]}.')
base_define_function('decorator','base','function')
# I am almost a complete Walking Human Computer Science Research
# Laboratory Machine on Two Legs... 😁