@@ -30,7 +30,7 @@ First of all let's understand functions in python:
30
30
# We are not using parentheses here because we are not calling the function hi
31
31
# instead we are just putting it into the greet variable. Let's try to run this
32
32
33
- print greet()
33
+ print ( greet() )
34
34
# output: 'hi yasoob'
35
35
36
36
# Let's see what happens if we delete the old hi function!
@@ -51,7 +51,7 @@ other functions:
51
51
.. code :: python
52
52
53
53
def hi (name = " yasoob" ):
54
- print " now you are inside the hi() function"
54
+ print ( " now you are inside the hi() function" )
55
55
56
56
def greet ():
57
57
return " now you are in the greet() function"
@@ -131,11 +131,11 @@ Giving a function as an argument to another function:
131
131
return " hi yasoob!"
132
132
133
133
def doSomethingBeforeHi (func ):
134
- print (" I am doing some boring work before executing hi()" )
134
+ print (" I am doing some boring work before executing hi()" )
135
135
print (func())
136
136
137
137
doSomethingBeforeHi(hi)
138
- # outputs:I am doing some boring work before executing hi()
138
+ # outputs:I am doing some boring work before executing hi()
139
139
# hi yasoob!
140
140
141
141
Now you have all the required knowledge to learn what decorators really
@@ -152,7 +152,7 @@ previous decorator and make a little bit more usable program:
152
152
def a_new_decorator (a_func ):
153
153
154
154
def wrapTheFunction ():
155
- print " I am doing some boring work before executing a_func()"
155
+ print ( " I am doing some boring work before executing a_func()" )
156
156
157
157
a_func()
158
158
@@ -170,7 +170,7 @@ previous decorator and make a little bit more usable program:
170
170
# now a_function_requiring_decoration is wrapped by wrapTheFunction()
171
171
172
172
a_function_requiring_decoration()
173
- # outputs:I am doing some boring work before executing a_function_requiring_decoration()
173
+ # outputs:I am doing some boring work before executing a_function_requiring_decoration()
174
174
# I am the function which needs some decoration to remove my foul smell
175
175
# I am doing some boring work after executing a_function_requiring_decoration()
176
176
@@ -185,12 +185,12 @@ run the previous code sample using @.
185
185
186
186
@a_new_decorator
187
187
def a_function_requiring_decoration ():
188
- """ Hey yo ! Decorate me!"""
188
+ """ Hey you ! Decorate me!"""
189
189
print (" I am the function which needs some decoration to "
190
- " remove my foul smell" )
190
+ " remove my foul smell" )
191
191
192
192
a_function_requiring_decoration()
193
- # outputs: I am doing some boring work before executing a_function_requiring_decoration()
193
+ # outputs: I am doing some boring work before executing a_function_requiring_decoration()
194
194
# I am the function which needs some decoration to remove my foul smell
195
195
# I am doing some boring work after executing a_function_requiring_decoration()
196
196
@@ -219,7 +219,7 @@ that is ``functools.wraps``. Let's modify our previous example to use
219
219
def a_new_decorator (a_func ):
220
220
@wraps (a_func)
221
221
def wrapTheFunction ():
222
- print (" I am doing some boring work before executing a_func()" )
222
+ print (" I am doing some boring work before executing a_func()" )
223
223
a_func()
224
224
print (" I am doing some boring work after executing a_func()" )
225
225
return wrapTheFunction
@@ -236,7 +236,7 @@ that is ``functools.wraps``. Let's modify our previous example to use
236
236
Now that is much better. Let's move on and learn some use-cases of
237
237
decorators.
238
238
239
- **Blueprint : **
239
+ **Blueprint: **
240
240
241
241
.. code :: python
242
242
@@ -313,7 +313,7 @@ Logging is another area where the decorators shine. Here is an example:
313
313
314
314
@logit
315
315
def addition_func (x ):
316
- """ does some math"""
316
+ """ Do some math. """
317
317
return x + x
318
318
319
319
0 commit comments