RANIARANIA Academy

Exceptions, Files & the Standard Library

Write Python that survives contact with the real world: handle errors with try/except/else/finally, raise and design your own exceptions, and read and write text, CSV and JSON files safely with the with-statement. You will also tour the standard-library workhorses — pathlib, datetime and collections — building the robustness the Python Institute PCAP exam expects.

Watch the free preview

The try/except/else/finally workflow — free to watch, no account needed.

Python: Foundations INTERMEDIATE · 150 min · Certificate on completion · 3 CPD points

What you'll learn

  • Handle runtime errors using try, except, else and finally with the right level of specificity
  • Raise built-in exceptions and design custom exception classes within the exception hierarchy
  • Read and write text, CSV and JSON files safely using the with-statement
  • Use pathlib and os to work with files and directories portably
  • Apply datetime and collections utilities to process real-world data robustly

Syllabus

Exceptions — Handling and Raising Errors
The try/except/else/finally workflowFree preview15 min
Raising, custom exceptions and the hierarchy15 min
Reading & Writing Files
Text files and the with-statement15 min
Structured data — CSV and JSON15 min
The Standard Library — Files, Paths & Time
Working with paths — os and pathlib15 min
Dates, times and durations with datetime15 min
The Standard Library — collections & Robust Programs
collections — Counter, defaultdict and friends15 min
Bringing it together — robust file processing15 min
Lab — 10 Programming Exercises & Solutions
Programming Exercises 1–515 min
Programming Exercises 6–1015 min