Reading and writing real files: text, CSV, JSON, Excel, and the encodings that break them.
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.
| 1 | Pathspathlib, absolute against relative, and why the file was not found | Open in ColabReadSolutions |
| 2 | Reading and Writing Textopen, modes, and the context manager that closes it for you | Open in ColabReadSolutions |
| 3 | EncodingsUTF-8, what mojibake actually is, and the errors argument | Open in ColabReadSolutions |
| 4 | CSVThe csv module, DictReader, and the quoting nobody expects | Open in ColabReadSolutions |
| 5 | JSON on Diskdump and load, and what does not survive a round trip | Open in ColabReadSolutions |
| 6 | Excel Filesopenpyxl, sheets, and why your date arrived as a number | Open in ColabReadSolutions |
| 7 | DirectoriesWalking a tree, globbing, and building a manifest of what you found | Open in ColabReadSolutions |
| 8 | Compression and Archiveszip and gzip, and reading without extracting first | Open in ColabReadSolutions |
| 9 | Writing Safelytempfile, atomic replace, and not corrupting your own data | Open in ColabReadSolutions |
| 10 | A Small PipelineRead many files, clean them, write one. The shape of most real work | Open in ColabReadSolutions |