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 some outdated
census data from 2022.
- The file census.py reads and prints the
census.txt file.
Active Learning
- Solve the Binarize It problem on this
programming contest problem set.
Read the input from a file named binarize.in and
send the output to the Python shell.
- Modify census.py so that it calculates and prints
the total U.S. population contained in the census.txt file above.
- Work Exercise 2