ipdb: IPython-enabled pdb

0.13.13 · active · verified Mon Apr 06

ipdb is an interactive debugger for Python that extends the functionality of the built-in `pdb` debugger. It integrates features from IPython, such as syntax highlighting, tab completion, better tracebacks, and an enhanced command set, making debugging more interactive and user-friendly. Currently at version 0.13.13, it maintains an active development pace with releases addressing compatibility and new features.

Warnings

Install

Imports

Quickstart

To use `ipdb.set_trace()`, simply place it where you want to pause execution. Run your script, and it will drop you into an interactive debugging session at that point. You can then inspect variables, step through code, and execute commands. Alternatively, run your script directly with `python -m ipdb your_script.py` to start debugging from the beginning or upon an exception.

import ipdb

def divide(a, b):
    try:
        # Set a breakpoint to inspect variables before the division
        ipdb.set_trace()
        result = a / b
        return result
    except ZeroDivisionError:
        print("Cannot divide by zero!")
        return None

print(divide(10, 2))
# To trigger the debugger on error, uncomment the line below and remove the try-except:
# divide(10, 0)

view raw JSON →