CSV is delimited text arranged as rows and fields. A comma separates values, the first line commonly names columns, and later lines represent records. section 19.0
A practical Python workflow treats CSV data as structured records:
- Parse records manually with open(), rstrip(), split(), zip(), and dict(), or use csv.DictReader() for shorter, reusable code. section 19.1.2 section 19.1.3
- Convert numeric-looking text explicitly, such as splitting a reps range at '-' and applying int() to both bounds. section 19.1.4 section 19.5
- Use tests with in-memory input, then decide how to handle empty files, missing rows, changed headers, alternate delimiters, and malformed values. section 19.1.4 section 19.1.7
- Format parsed records with tabulate, and inspect arbitrary delimited files with csvkit tools. section 19.1.1 section 19.1.8
Workout generator
Given exercise,reps rows such as Burpees,20-50, read each record, split the range, choose a random integer, select exercises, and print a text table. A reusable read_csv() function can return tuples such as ('Burpees', 20, 50). section 19.1.4 section 19.1.8
$ csvlook --max-rows 3 inputs/exercises.csv | exercise | reps | | -------- | ------ | | Burpees | 20-50 | | Situps | 40-100 | | Pushups | 25-75 | | ... | ... |
Inspecting a CSV as a table makes column names, row values, and delimiter-based structure immediately visible. section 19.1.1
For data analysis, pandas.read_csv() loads delimited data into a two-dimensional data frame, though its broader use is outside this treatment. section 19.3.3














