files and i/o — moving data in and out9 / 9
csv and jsonl — the two formats ai moves data in
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Convert a CSV into JSONL.
Write a function csv_to_jsonl(csv_path, jsonl_path) that:
- Opens
csv_pathwithcsv.DictReader(remembernewline=""). - For each row, converts the
scorecolumn from string to int. - Writes one JSON object per line to
jsonl_path. - Returns the number of rows written.
The starter writes a tiny CSV, calls your function, then reads the
JSONL back and prints each parsed record's name and score.
Expected output:
3
alex 82
sam 91
jordan 77
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _