Fix Broken Links
This commit is contained in:
@@ -10,10 +10,10 @@ It should be emphasized that the topics in this section are only meant
|
||||
to serve as a very basic introduction to these ideas. You will need
|
||||
to seek more advanced material to fill out details.
|
||||
|
||||
* [7.1 Variable argument functions](01_Variable_arguments)
|
||||
* [7.2 Anonymous functions and lambda](02_Anonymous_function)
|
||||
* [7.3 Returning function and closures](03_Returning_functions)
|
||||
* [7.4 Function decorators](04_Function_decorators)
|
||||
* [7.5 Static and class methods](05_Decorated_methods)
|
||||
* [7.1 Variable argument functions](01_Variable_arguments.md)
|
||||
* [7.2 Anonymous functions and lambda](02_Anonymous_function.md)
|
||||
* [7.3 Returning function and closures](03_Returning_functions.md)
|
||||
* [7.4 Function decorators](04_Function_decorators.md)
|
||||
* [7.5 Static and class methods](05_Decorated_methods.md)
|
||||
|
||||
[Contents](../Contents)
|
||||
[Contents](../Contents.md)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
[Contents](../Contents) \| [Previous (6.4 Generator Expressions)](../06_Generators/04_More_generators) \| [Next (7.2 Anonymous Functions)](02_Anonymous_function)
|
||||
[Contents](../Contents.md) \| [Previous (6.4 Generator Expressions)](../06_Generators/04_More_generators) \| [Next (7.2 Anonymous Functions)](02_Anonymous_function)
|
||||
|
||||
# 7.1 Variable Arguments
|
||||
|
||||
@@ -144,7 +144,7 @@ data. If you try to pass `data` directly, it doesn't work:
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: __init__() takes exactly 4 arguments (2 given)
|
||||
>>>
|
||||
>>>
|
||||
```
|
||||
|
||||
This is easily fixed using `*data` instead. Try this:
|
||||
@@ -177,11 +177,11 @@ def read_portfolio(filename):
|
||||
name, shares, and price.
|
||||
'''
|
||||
with open(filename) as lines:
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
types=[str,int,float])
|
||||
|
||||
portfolio = [ Stock(d['name'], d['shares'], d['price'])
|
||||
portfolio = [ Stock(d['name'], d['shares'], d['price'])
|
||||
for d in portdicts ]
|
||||
return Portfolio(portfolio)
|
||||
```
|
||||
@@ -201,8 +201,8 @@ def read_portfolio(filename, **opts):
|
||||
name, shares, and price.
|
||||
'''
|
||||
with open(filename) as lines:
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
types=[str,int,float],
|
||||
**opts)
|
||||
|
||||
@@ -230,4 +230,4 @@ Now, try silencing the errors:
|
||||
>>>
|
||||
```
|
||||
|
||||
[Contents](../Contents) \| [Previous (6.4 Generator Expressions)](../06_Generators/04_More_generators) \| [Next (7.2 Anonymous Functions)](02_Anonymous_function)
|
||||
[Contents](../Contents.md) \| [Previous (6.4 Generator Expressions)](../06_Generators/04_More_generators) \| [Next (7.2 Anonymous Functions)](02_Anonymous_function)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (7.1 Variable Arguments)](01_Variable_arguments) \| [Next (7.3 Returning Functions)](03_Returning_functions)
|
||||
[Contents](../Contents.md) \| [Previous (7.1 Variable Arguments)](01_Variable_arguments) \| [Next (7.3 Returning Functions)](03_Returning_functions)
|
||||
|
||||
# 7.2 Anonymous Functions and Lambda
|
||||
|
||||
@@ -165,4 +165,4 @@ Note: `lambda` is a useful shortcut because it allows you to
|
||||
define a special processing function directly in the call to `sort()` as
|
||||
opposed to having to define a separate function first.
|
||||
|
||||
[Contents](../Contents) \| [Previous (7.1 Variable Arguments)](01_Variable_arguments) \| [Next (7.3 Returning Functions)](03_Returning_functions)
|
||||
[Contents](../Contents.md) \| [Previous (7.1 Variable Arguments)](01_Variable_arguments) \| [Next (7.3 Returning Functions)](03_Returning_functions)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[Contents](../Contents) \| [Previous (7.2 Anonymous Functions)](02_Anonymous_function) \| [Next (7.4 Decorators)](04_Function_decorators)
|
||||
[Contents](../Contents.md) \| [Previous (7.2 Anonymous Functions)](02_Anonymous_function) \| [Next (7.4 Decorators)](04_Function_decorators)
|
||||
|
||||
# 7.3 Returning Functions
|
||||
|
||||
This section introduces the idea of using functions to create other functions.
|
||||
This section introduces the idea of using functions to create other functions.
|
||||
|
||||
### Introduction
|
||||
|
||||
@@ -237,4 +237,4 @@ is often good.
|
||||
Rewrite the `Stock` class in the file `stock.py` so that it uses typed properties
|
||||
as shown.
|
||||
|
||||
[Contents](../Contents) \| [Previous (7.2 Anonymous Functions)](02_Anonymous_function) \| [Next (7.4 Decorators)](04_Function_decorators)
|
||||
[Contents](../Contents.md) \| [Previous (7.2 Anonymous Functions)](02_Anonymous_function) \| [Next (7.4 Decorators)](04_Function_decorators)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (7.3 Returning Functions)](03_Returning_functions) \| [Next (7.5 Decorated Methods)](05_Decorated_methods)
|
||||
[Contents](../Contents.md) \| [Previous (7.3 Returning Functions)](03_Returning_functions) \| [Next (7.5 Decorated Methods)](05_Decorated_methods)
|
||||
|
||||
# 7.4 Function Decorators
|
||||
|
||||
@@ -106,7 +106,7 @@ It is said to *decorate* the function.
|
||||
There are many more subtle details to decorators than what has been presented here.
|
||||
For example, using them in classes. Or using multiple decorators with a function.
|
||||
However, the previous example is a good illustration of how their use tends to arise.
|
||||
Usually, it's in response to repetitive code appearing across a wide range of
|
||||
Usually, it's in response to repetitive code appearing across a wide range of
|
||||
function definitions. A decorator can move that code to a central definition.
|
||||
|
||||
## Exercises
|
||||
@@ -154,7 +154,7 @@ __main__.countdown : 0.076562
|
||||
```
|
||||
|
||||
Discussion: This `@timethis` decorator can be placed in front of any
|
||||
function definition. Thus, you might use it as a diagnostic tool for
|
||||
function definition. Thus, you might use it as a diagnostic tool for
|
||||
performance tuning.
|
||||
|
||||
[Contents](../Contents) \| [Previous (7.3 Returning Functions)](03_Returning_functions) \| [Next (7.5 Decorated Methods)](05_Decorated_methods)
|
||||
[Contents](../Contents.md) \| [Previous (7.3 Returning Functions)](03_Returning_functions) \| [Next (7.5 Decorated Methods)](05_Decorated_methods)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (7.4 Decorators)](04_Function_decorators) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview)
|
||||
[Contents](../Contents.md) \| [Previous (7.4 Decorators)](04_Function_decorators) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview)
|
||||
|
||||
# 7.5 Decorated Methods
|
||||
|
||||
@@ -123,8 +123,8 @@ def read_portfolio(filename, **opts):
|
||||
name, shares, and price.
|
||||
'''
|
||||
with open(filename) as lines:
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
types=[str,int,float],
|
||||
**opts)
|
||||
|
||||
@@ -163,7 +163,7 @@ class Portfolio:
|
||||
...
|
||||
```
|
||||
|
||||
If you want to read a portfolio from a CSV file, maybe you should make a
|
||||
If you want to read a portfolio from a CSV file, maybe you should make a
|
||||
class method for it:
|
||||
|
||||
```python
|
||||
@@ -184,8 +184,8 @@ class Portfolio:
|
||||
@classmethod
|
||||
def from_csv(cls, lines, **opts):
|
||||
self = cls()
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
portdicts = fileparse.parse_csv(lines,
|
||||
select=['name','shares','price'],
|
||||
types=[str,int,float],
|
||||
**opts)
|
||||
|
||||
@@ -208,4 +208,4 @@ To use this new Portfolio class, you can now write code like this:
|
||||
Make these changes to the `Portfolio` class and modify the `report.py`
|
||||
code to use the class method.
|
||||
|
||||
[Contents](../Contents) \| [Previous (7.4 Decorators)](04_Function_decorators) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview)
|
||||
[Contents](../Contents.md) \| [Previous (7.4 Decorators)](04_Function_decorators) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview)
|
||||
|
||||
Reference in New Issue
Block a user