Defensive Programming with Python

It’s pretty obvious that if we want to be sure our programs are right, we need to put in some effort. What isn’t so obvious is that focusing on quality is also the best way—in fact, the only way—to improve productivity as well. Getting something wrong and then fixing it almost always takes longer than getting it right in the first place. Practicing defensive programming and thinking about what the right answer is supposed to be all help get us answers faster, as well as ones that are more likely to be correct.

Prerequisites

You need to understand the concepts of files and directories and how to start a Python interpreter before tackling this lesson. This lesson sometimes references Jupyter Notebook although you can use any Python interpreter mentioned in the Setup.

The commands in this lesson pertain to Python 3.

Getting Started

To get started, follow the directions on the “Setup” page to download data and install a Python interpreter.

Schedule

Setup Download files required for the lesson
10:15 1. Errors and Exceptions How does Python report errors?
How can I handle errors in Python programs?
10:45 2. Defensive Programming How can I make my programs more reliable?
11:15 3. Debugging How can I debug my program?
11:45 Survey

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.