Guide 2 · Foundations

Files, Paths and Formats

Reading and writing real files: text, CSV, JSON, Excel, and the encodings that break them.

Complete 10 notebooks 10 written

Before this guide: Python from the Start.

The notebooks

Open in Colab runs a notebook in your browser, and Read shows it on GitHub without running it. Every notebook runs on its own, and the answers to its exercises are in a separate notebook, linked as Solutions.

1Pathspathlib, absolute against relative, and why the file was not foundOpen in ColabReadSolutions
2Reading and Writing Textopen, modes, and the context manager that closes it for youOpen in ColabReadSolutions
3EncodingsUTF-8, what mojibake actually is, and the errors argumentOpen in ColabReadSolutions
4CSVThe csv module, DictReader, and the quoting nobody expectsOpen in ColabReadSolutions
5JSON on Diskdump and load, and what does not survive a round tripOpen in ColabReadSolutions
6Excel Filesopenpyxl, sheets, and why your date arrived as a numberOpen in ColabReadSolutions
7DirectoriesWalking a tree, globbing, and building a manifest of what you foundOpen in ColabReadSolutions
8Compression and Archiveszip and gzip, and reading without extracting firstOpen in ColabReadSolutions
9Writing Safelytempfile, atomic replace, and not corrupting your own dataOpen in ColabReadSolutions
10A Small PipelineRead many files, clean them, write one. The shape of most real workOpen in ColabReadSolutions