.. -*- mode: rst -*-
.. include:: ../definitions.txt
.. include:: regexp-defns.txt

=======================
15. Appendix: Debugging
=======================

This task is known as *debugging*, since the problems are usually
small relative to their impact, hard-to-find, and seem to take on a
life of their own as the programmer tries to hunt them down.

The first step is to isolate the problem.  If there was a run-time
error, the Python interpreter will exit, providing a *stack-trace*
which lists the most recently called functions with their line numbers.
The simplest way to deal with such errors is to add print statements
to the program just before the offending line, permitting you to inspect
the values of variables (sometimes they are different to what you expected).

Python also provides an interactive debugger called ``pdb``, which stands
for Python debugger.  If your program is saved in a file ``myscript.py``,
then you can access the debugger with ``python -m pdb myscript.py``.

