Most real programs read or write files: a CSV of training data, a JSON config, a log file. This section covers how to do that the modern way — using pathlib for paths and with blocks for safe access.
What’s in this section
- Reading text files — open, read line by line, read all at once
- Writing text files — create, overwrite, append
- Working with CSV — the most common spreadsheet format
- Working with JSON — the most common API and config format
- File paths with
pathlib— the right way to join, build, and inspect paths
After this section, you can move data in and out of your programs with confidence.