@@ -11,7 +11,7 @@ Using built-in decorators
1111-------------------------
1212
1313Most of the time, you will use built-in decorators. One example is
14- ``functools.lru_cache `` that memorizes the output of a function to save
14+ ``functools.lru_cache `` that memoizes the output of a function to save
1515time later. Let's decorate a function with it:
1616
1717.. code :: python3
@@ -42,7 +42,7 @@ Writing your own decorators
4242---------------------------
4343
4444If want to add functionality for which no decorator exists,
45- e.g. printing a timestamp for every addition , you could define a new function:
45+ e.g. printing a timestamp for every call of `` fibonacci() `` , you could define a new function:
4646
4747.. code :: python3
4848
@@ -59,11 +59,11 @@ using a decorator:
5959
6060 def print_timestamp(func):
6161 def wrapper(*args):
62- print(time.asctime()) # done before addition
63- result = func(*args) # calls the addition function
64- ... # actions after addition
62+ print(time.asctime()) # done before function call
63+ result = func(*args) # calls the function
64+ ... # actions after function call
6565 return result
66- return wrapper
66+ return wrapper
6767
6868
6969 @print_timestamp
@@ -74,7 +74,7 @@ using a decorator:
7474 return fibonacci(n-1) + fibonacci(n-2)
7575
7676 You can argue that this does not simplify the code.
77- Decorators pays off in bigger programs, when they are used often .
77+ Decorators pay off in bigger programs, when they are used several times .
7878Logging function calls is a good example for using a decorator.
7979
8080
@@ -94,11 +94,11 @@ original one. It is useful when writing your own decorators.
9494 def print_timestamp(func):
9595 @functools.wraps(func)
9696 def wrapper(*args):
97- print(time.asctime()) # done before addition
98- result = func(*args) # calls the addition function
99- ... # actions after addition
97+ print(time.asctime())
98+ result = func(*args)
99+ ...
100100 return result
101- return wrapper
101+ return wrapper
102102
103103 @print_timestamp
104104 def fibonacci(n):
@@ -109,4 +109,4 @@ original one. It is useful when writing your own decorators.
109109
110110
111111 # check docstring - would not work without @wraps
112- print(help(addition ))
112+ print(help(fibonacci ))
0 commit comments