Python, from Zero, for AI · Chapter 04
An error message is the most useful output
1:41 · Narrated with a synthetic voice. Captions are available in the player.
Read the transcript
Nobody writes correct code first time. The difference between a beginner and somebody with twenty years of practice is almost entirely how quickly they read the failure. So module four teaches the traceback as a skill with an order: the last line first, because that is what went wrong; then the lowest block naming your own file, because that is where; then upwards through the chain of calls, because the value that broke the line often came from the caller above it. Anything printed before the traceback really did happen. And when you ask another person or an assistant for help, paste the whole traceback, not the last line of it. The expensive failures are the quiet ones. A clinic in Nashik sent no appointment reminders for nine days while its log said zero errors every night, because the send loop caught every exception and discarded it. The module is blunt about the fix: catch only the exceptions you have a plan for, and let the rest stop the program. Then it teaches logging with levels, so commentary can be switched on without editing code, and a first test with pytest. The highest value test you will ever write is the one that reproduces a bug you have just fixed. And no test should ever call the paid service.