# Python Debugging

> Python Debugging with pdb

- Skill: `amirreza-km/python-debugging` (Agent Skill)
- Install (CLI): `npx skillmds@latest add amirreza-km/python-debugging`
- Raw SKILL.md: https://api.skillmd.com/api/skills/amirreza-km/python-debugging/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: amirreza-km (https://skillmd.com/u/amirreza-km)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/amirreza-km/python-debugging

---

# Python Debugging with pdb

## Description
A standard procedure for debugging Python code using the built-in `pdb` module.

## When to use
When you need to step through Python code execution to inspect variables and control flow.

## Requirements
- Python installed.

## Procedure
1. Import `pdb`.
2. Insert `pdb.set_trace()` where you want execution to pause.
3. Run the script.
4. Use commands like `n` (next), `s` (step), `c` (continue), and `p <var>` (print variable).

## Examples
```python
import pdb

def buggy_function():
    x = 10
    pdb.set_trace()
    y = x / 0
    return y
```

## Common mistakes / Pitfalls
Do not leave `pdb.set_trace()` calls in production code. Use conditional breakpoints or `logging` for production.

