Module 09 of 11

Files, Exceptions & Errors

Lessons

About This Module

Real programs don't just live in memory — they read and write files, and they inevitably run into things going wrong. This module covers how to work with files safely and how to handle errors gracefully instead of letting them crash your program.

It starts with file objects: opening files for reading, writing, and appending, and working with text and binary data. From there it covers context managers and the with statement, which make sure resources like files get cleaned up properly even when something goes wrong. It closes with exception handling using try, except, else, and finally, so your code can respond to errors instead of stopping dead.

Watch the lessons in order, then continue on to Standard Library & Third-Party Packages.

Lessons

3 videos
01

File Objects - Reading and Writing to Files

Opening files for reading, writing, and appending; working with simple text files, multiple open files, and binary data.

02

Context Managers - Efficiently Managing Resources

Using the with statement and __enter__/__exit__ methods so resources like files get set up and cleaned up automatically.

03

Using Try/Except Blocks for Error Handling

Handling errors and exceptions with try, except, else, and finally, and controlling program flow when things go wrong.