Python Reading
- Read the chapter entitled Files
from section "Working with Data Files" through section "Iterating
over Lines in a File".
Key Ideas
- Opening a File
- To read from it: open(filename, "r")
- To write to it: open(filename, "w")
- To close it: filevariable.close()
- Absolute File Paths vs. Relative File Paths
- The file census.txt captures this
2013 census data.
- The file census.py reads and prints the
census.txt file.
Active Learning
- Modify the census.py so that it calculates and prints
the total 2013 U.S. population. (If your program is correct,
the number will match the number on the web page above.)
- Work Exercise 2