Lesson 5.1
Reading and Writing Files
A context manager opens a file and guarantees it is closed even if an error occurs partway through.
Where Python stops being an exercise and starts touching real data. The unit adds a new category of failure: the input may be missing, malformed, or unavailable, and correct code has to survive that.
Lesson 5.1
A context manager opens a file and guarantees it is closed even if an error occurs partway through.
Lesson 5.2
CSV and JSON carry structure that plain text does not. Parsing with the right module avoids hand-splitting that breaks on quoted fields.
Lesson 5.3
An API returns structured data over the network, and both the request and the response can fail independently of your code being correct.
Lesson 5.4
Exception handling separates the expected path from the recovery path. Catching everything hides the bugs you needed to see.
Work through questions with a tutor and get help with the steps you find difficult.
Get help with this topic