Week 04 / CSV · JSON · requests · missing data
Work with files and APIs.
The idea
CSV stores rows and columns in a text file; JSON stores nested values. An API request can supply fresh data. Treat all outside data as uncertain: files can be missing, fields can be blank, and requests can fail.
Read CSV rows safely
import csv
with open("games.csv", newline="") as file:
for row in csv.DictReader(file):
home = row.get("home_team", "Unknown")
score = row.get("home_score") or "Not played"
print(home, score)Build it
Work through these steps in your own project. Check them off as you go; your checklist stays in this browser.
Which values came from outside your program, and how did you validate them?
Notes save in this browser.