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.
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 preview
Raising, custom exceptions and the hierarchy
Reading & Writing Files
Text files and the with-statement
Structured data — CSV and JSON
The Standard Library — Files, Paths & Time
Working with paths — os and pathlib
Dates, times and durations with datetime
The Standard Library — collections & Robust Programs
collections — Counter, defaultdict and friends
Bringing it together — robust file processing
Lab — 10 Programming Exercises & Solutions
Programming Exercises 1–5
Programming Exercises 6–10