Fix Broken Links
This commit is contained in:
@@ -7,11 +7,11 @@ and introduces modules. By the end you should be able to write programs
|
||||
that are subdivided into functions across multiple files. We'll also give
|
||||
some useful code templates for writing more useful scripts.
|
||||
|
||||
* [3.1 Functions and Script Writing](01_Script)
|
||||
* [3.2 More Detail on Functions](02_More_functions)
|
||||
* [3.3 Exception Handling](03_Error_checking)
|
||||
* [3.4 Modules](04_Modules)
|
||||
* [3.5 Main module](05_Main_module)
|
||||
* [3.6 Design Discussion about Embracing Flexibilty](06_Design_discussion)
|
||||
* [3.1 Functions and Script Writing](01_Script.md)
|
||||
* [3.2 More Detail on Functions](02_More_functions.md)
|
||||
* [3.3 Exception Handling](03_Error_checking.md)
|
||||
* [3.4 Modules](04_Modules.md)
|
||||
* [3.5 Main module](05_Main_module.md)
|
||||
* [3.6 Design Discussion about Embracing Flexibilty](06_Design_discussion.md)
|
||||
|
||||
[Contents](../Contents)
|
||||
[Contents](../Contents.md)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (2.7 Object Model)](../02_Working_with_data/07_Objects) \| [Next (3.2 More on Functions)](02_More_functions)
|
||||
[Contents](../Contents.md) \| [Previous (2.7 Object Model)](../02_Working_with_data/07_Objects) \| [Next (3.2 More on Functions)](02_More_functions)
|
||||
|
||||
# 3.1 Scripting
|
||||
|
||||
@@ -143,7 +143,7 @@ spam(42) # Code that uses the functions appears at the end
|
||||
|
||||
Later functions build upon earlier functions. Again, this is only
|
||||
a point of style. The only thing that matters in the above program
|
||||
is that the call to `spam(42)` go last.
|
||||
is that the call to `spam(42)` go last.
|
||||
|
||||
### Function Design
|
||||
|
||||
@@ -153,7 +153,7 @@ and mysterious side-effects. Your main goals: *Modularity* and *Predictability*
|
||||
|
||||
### Doc Strings
|
||||
|
||||
It's good practice to include documentation in the form of a
|
||||
It's good practice to include documentation in the form of a
|
||||
doc-string. Doc-strings are strings written immediately after the
|
||||
name of the function. They feed `help()`, IDEs and other tools.
|
||||
|
||||
@@ -194,7 +194,7 @@ def read_prices(filename: str) -> dict:
|
||||
|
||||
The hints do nothing operationally. They are purely informational.
|
||||
However, they may be used by IDEs, code checkers, and other tools
|
||||
to do more.
|
||||
to do more.
|
||||
|
||||
## Exercises
|
||||
|
||||
@@ -299,4 +299,4 @@ you can. At some point, that script is going to grow and you'll wish
|
||||
you had a bit more organization. Also, a little known fact is that Python
|
||||
runs a bit faster if you use functions.
|
||||
|
||||
[Contents](../Contents) \| [Previous (2.7 Object Model)](../02_Working_with_data/07_Objects) \| [Next (3.2 More on Functions)](02_More_functions)
|
||||
[Contents](../Contents.md) \| [Previous (2.7 Object Model)](../02_Working_with_data/07_Objects) \| [Next (3.2 More on Functions)](02_More_functions)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (3.1 Scripting)](01_Script) \| [Next (3.3 Error Checking)](03_Error_checking)
|
||||
[Contents](../Contents.md) \| [Previous (3.1 Scripting)](01_Script) \| [Next (3.3 Error Checking)](03_Error_checking)
|
||||
|
||||
# 3.2 More on Functions
|
||||
|
||||
@@ -273,7 +273,7 @@ Start this exercise by creating a new file called
|
||||
### Exercise 3.3: Reading CSV Files
|
||||
|
||||
To start, let’s just focus on the problem of reading a CSV file into a
|
||||
list of dictionaries. In the file `fileparse.py`, define a
|
||||
list of dictionaries. In the file `fileparse.py`, define a
|
||||
function that looks like this:
|
||||
|
||||
```python
|
||||
@@ -338,7 +338,7 @@ follows:
|
||||
>>>
|
||||
```
|
||||
|
||||
An example of a column selector was given in [Exercise 2.23](../02_Working_with_data/06_List_comprehension).
|
||||
An example of a column selector was given in [Exercise 2.23](../02_Working_with_data/06_List_comprehension).
|
||||
However, here’s one way to do it:
|
||||
|
||||
```python
|
||||
@@ -431,7 +431,7 @@ type-conversions to be applied to the returned data. For example:
|
||||
>>>
|
||||
```
|
||||
|
||||
You already explored this in [Exercise 2.24](../02_Working_with_data/07_Objects).
|
||||
You already explored this in [Exercise 2.24](../02_Working_with_data/07_Objects).
|
||||
You'll need to insert the following fragment of code into your solution:
|
||||
|
||||
```python
|
||||
@@ -513,4 +513,4 @@ select out columns of interest, perform type conversions, without
|
||||
having to worry too much about the inner workings of files or the
|
||||
`csv` module.
|
||||
|
||||
[Contents](../Contents) \| [Previous (3.1 Scripting)](01_Script) \| [Next (3.3 Error Checking)](03_Error_checking)
|
||||
[Contents](../Contents.md) \| [Previous (3.1 Scripting)](01_Script) \| [Next (3.3 Error Checking)](03_Error_checking)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (3.2 More on Functions)](02_More_functions) \| [Next (3.4 Modules)](04_Modules)
|
||||
[Contents](../Contents.md) \| [Previous (3.2 More on Functions)](02_More_functions) \| [Next (3.4 Modules)](04_Modules)
|
||||
|
||||
# 3.3 Error Checking
|
||||
|
||||
@@ -241,7 +241,7 @@ except Exception as e:
|
||||
|
||||
It reports a specific reason for failure. It is almost always a good
|
||||
idea to have some mechanism for viewing/reporting errors when you
|
||||
write code that catches all possible exceptions.
|
||||
write code that catches all possible exceptions.
|
||||
|
||||
In general though, it's better to catch the error as narrowly as is
|
||||
reasonable. Only catch the errors you can actually handle. Let
|
||||
@@ -402,4 +402,4 @@ most programs. As a general rule, you shouldn’t silently ignore
|
||||
errors. Instead, it’s better to report problems and to give the user
|
||||
an option to the silence the error message if they choose to do so.
|
||||
|
||||
[Contents](../Contents) \| [Previous (3.2 More on Functions)](02_More_functions) \| [Next (3.4 Modules)](04_Modules)
|
||||
[Contents](../Contents.md) \| [Previous (3.2 More on Functions)](02_More_functions) \| [Next (3.4 Modules)](04_Modules)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[Contents](../Contents) \| [Previous (3.3 Error Checking)](03_Error_checking) \| [Next (3.5 Main Module)](05_Main_module)
|
||||
[Contents](../Contents.md) \| [Previous (3.3 Error Checking)](03_Error_checking) \| [Next (3.5 Main Module)](05_Main_module)
|
||||
|
||||
# 3.4 Modules
|
||||
|
||||
This section introduces the concept of modules and working with functions that span
|
||||
multiple files.
|
||||
This section introduces the concept of modules and working with functions that span
|
||||
multiple files.
|
||||
|
||||
### Modules and import
|
||||
|
||||
@@ -164,7 +164,7 @@ Each module loads and executes only *once*.
|
||||
changing the source code for a module. Because of the module cache `sys.modules`,
|
||||
repeated imports always return the previously loaded module--even if a change
|
||||
was made. The safest way to load modified code into Python is to quit and restart
|
||||
the interpreter.
|
||||
the interpreter.
|
||||
|
||||
### Locating Modules
|
||||
|
||||
@@ -214,7 +214,7 @@ not readily accessible from the current working directory.
|
||||
For this exercise involving modules, it is critically important to
|
||||
make sure you are running Python in a proper environment. Modules are
|
||||
usually when programmers encounter problems with the current working
|
||||
directory or with Python's path settings. For this course, it is
|
||||
directory or with Python's path settings. For this course, it is
|
||||
assumed that you're writing all of your code in the `Work/` directory.
|
||||
For best results, you should make sure you're also in that directory
|
||||
when you launch the interpreter. If not, you need to make sure
|
||||
@@ -338,4 +338,4 @@ also contains `read_portfolio()` and `read_prices()` functions. And
|
||||
finally, `pcost.py` which computes the portfolio cost, but makes use
|
||||
of the `read_portfolio()` function written for the `report.py` program.
|
||||
|
||||
[Contents](../Contents) \| [Previous (3.3 Error Checking)](03_Error_checking) \| [Next (3.5 Main Module)](05_Main_module)
|
||||
[Contents](../Contents.md) \| [Previous (3.3 Error Checking)](03_Error_checking) \| [Next (3.5 Main Module)](05_Main_module)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (3.4 Modules)](04_Modules) \| [Next (3.6 Design Discussion)](06_Design_discussion)
|
||||
[Contents](../Contents.md) \| [Previous (3.4 Modules)](04_Modules) \| [Next (3.6 Design Discussion)](06_Design_discussion)
|
||||
|
||||
# 3.5 Main Module
|
||||
|
||||
@@ -303,4 +303,4 @@ bash $ python3 pcost.py Data/portfolio.csv
|
||||
Total cost: 44671.15
|
||||
```
|
||||
|
||||
[Contents](../Contents) \| [Previous (3.4 Modules)](04_Modules) \| [Next (3.6 Design Discussion)](06_Design_discussion)
|
||||
[Contents](../Contents.md) \| [Previous (3.4 Modules)](04_Modules) \| [Next (3.6 Design Discussion)](06_Design_discussion)
|
||||
@@ -1,4 +1,4 @@
|
||||
[Contents](../Contents) \| [Previous (3.5 Main module)](05_Main_module) \| [Next (4 Classes)](../04_Classes_objects/00_Overview)
|
||||
[Contents](../Contents.md) \| [Previous (3.5 Main module)](05_Main_module) \| [Next (4 Classes)](../04_Classes_objects/00_Overview)
|
||||
|
||||
# 3.6 Design Discussion
|
||||
|
||||
@@ -91,7 +91,7 @@ Don't restrict your options. With great flexibility comes great power.
|
||||
|
||||
### Exercise 3.17: From filenames to file-like objects
|
||||
|
||||
You've now created a file `fileparse.py` that contained a
|
||||
You've now created a file `fileparse.py` that contained a
|
||||
function `parse_csv()`. The function worked like this:
|
||||
|
||||
```python
|
||||
@@ -100,7 +100,7 @@ function `parse_csv()`. The function worked like this:
|
||||
>>>
|
||||
```
|
||||
|
||||
Right now, the function expects to be passed a filename. However, you
|
||||
Right now, the function expects to be passed a filename. However, you
|
||||
can make the code more flexible. Modify the function so that it works
|
||||
with any file-like/iterable object. For example:
|
||||
|
||||
@@ -134,4 +134,4 @@ Fix the `read_portfolio()` and `read_prices()` functions in the
|
||||
Afterwards, your `report.py` and `pcost.py` programs should work
|
||||
the same way they always did.
|
||||
|
||||
[Contents](../Contents) \| [Previous (3.5 Main module)](05_Main_module) \| [Next (4 Classes)](../04_Classes_objects/00_Overview)
|
||||
[Contents](../Contents.md) \| [Previous (3.5 Main module)](05_Main_module) \| [Next (4 Classes)](../04_Classes_objects/00_Overview)
|
||||
Reference in New Issue
Block a user