Files and formats
The shapes data arrives in — CSV rows, log lines, JSON payloads, file paths. None of these exercises touch a disk: the content is handed to you as text, because the interesting part was never the reading, it was what you do with what you read.
—Exercises
10 exercises
Swap a file’s extension
pathlib without touching disk, with_suffix
~15 min
Three fields and everything else
maxsplit, fixed fields plus a free-text tail
~18 min
Directory, name, stem, suffix
rpartition, the last dot, not the first
~18 min
The last few lines
splitlines, negative slicing
~15 min
Turn CSV rows into records
zip, header rows
~20 min
The metadata block at the top of the file
a fence is only a fence in the right place, returning a pair
~22 min
Make two JSON payloads comparable
json.loads and dumps, objects unordered, arrays ordered
~20 min
Sections, settings and the lines that are neither
line-oriented parsing, state across lines
~24 min
Back out to rows and columns
a header is a decision, missing versus empty
~20 min
A file too big to hold
iterables you can only read once, single pass
~26 min