Python for a Coding Assessment
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
I can read and write text, CSV and JSON files in Python using paths that work on any machine, and choose the format that fits what the data is for.
Getting data in and out of a program: the part of almost every real task that is not the interesting part, and the part that breaks on someone else’s machine.
In scope: text, CSV and JSON; pathlib for paths; with for handles; encoding; and failing sensibly
on a missing file or a bad row. Out of scope: databases, Excel formats, and dataframes.
withwith open(path) as f: closes the file when the block ends, including when an exception leaves the
block early. Without it, a handle stays open until the interpreter happens to collect it, which on
Windows means the next process cannot touch the file, and on a long run means hitting the open-file
limit.
"data/" + name breaks the first time it meets Windows, a space, or a name that already ends in a
separator. Path("data") / name is correct everywhere, and carries the useful questions with it:
.exists(), .suffix, .stem, .parent, .read_text().
Use csv.DictReader rather than indexing by column number: a file whose columns move should not
silently change what your program means.
A file is bytes; text is bytes plus an encoding. Passing encoding="utf-8" explicitly makes your
program behave the same on every machine, rather than inheriting whatever the operating system
prefers. Most “it works on my laptop” bugs in file handling are this.
json.load produces dicts and lists; tuples,
sets and dates do not survive the round trip.Give a CSV with a missing value, a number stored as text and a row with too many fields, and ask for a program that reports what it skipped and why. The report is the evidence: it forces every decision about bad data to be made deliberately rather than by crash.
| Resource | Kind | Cost | Provider |
|---|---|---|---|
| The Python Tutorial: input and output, including reading and writing files | reading | free | Python Software Foundation |
| pathlib: object-oriented filesystem paths | reference | free | Python Software Foundation |
| csv: CSV file reading and writing | reference | free | Python Software Foundation |
| json: JSON encoder and decoder | reference | free | Python Software Foundation |
| Automate the Boring Stuff, chapter 9: reading and writing files | reading | free | Al Sweigart |
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
A timed take-home in the shape real hiring uses: read messy data, compute a result, test it, and hand over a repository someone else can run.
The holder can take an unfamiliar problem, write a tested Python solution someone else can run, and explain what it costs.
Nothing to show yet. The publisher last published on 2026-09-20, and no aggregate for this outcome has reached the 50 learners a number needs. Open Degree does not track learners. About learner evidence.