Since Python’s development cycle is so fast, the most effective way to debug is often to edit your code so that it outputs relevant information at key points. Python has many ways to let your code explore its own state in order to extract information that may be relevant for debugging. The
traceback modules specifically support such exploration, which is also known as reflection or introspection.
Once you have obtained debugging-relevant information, the
logging module, covered in The logging module. As covered in
excepthook in The sys Module, rebinding attribute
excepthook of module
sys lets your program log detailed error information just before your program is terminated by a propagating exception.
Python also offers hooks that enable interactive debugging. Module
pdb supplies a simple text-mode interactive debugger. Other interactive debuggers for Python are part of integrated development ...