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 census2023.txt captures US census data.
- The file census.py reads in and prints out the census.txt file.
Active Learning
- Modify the census.py so that it calculates and prints the total 2023 U.S. population. (If your program is correct, the number will match the Census Bureau total.)
- Work Exercise 2