Python Debugging
Tracebacks, breakpoints, and profiling to fix bugs fast.
- python debug
- breakpoint pdb
- traceback
- cprofile
- logging
Python Debugging
Tracebacks, breakpoints, and profiling to fix bugs fast.
Commands
| Command | What it does |
|---|---|
python -X dev app.py | Dev mode: extra warnings |
breakpoint() | Built-in debugger (pdb) |
python -m pdb app.py | Debugger from the start |
cProfile cumulative run | Find hot functions |
traceback.print_exc() | Log full stack in except blocks |
Example
try:
main()
except Exception:
import traceback; traceback.print_exc()
breakpoint()
FAQ
How do I inspect a crashing prod process?
Log tracebacks with structlog/logging plus request IDs; reproduce locally under pdb from the logged input.
print vs logging?
logging with levels and handlers; print debugging never survives to production.
よくある質問
How do I inspect a crashing prod process?
Log tracebacks with structlog/logging plus request IDs; reproduce locally under pdb from the logged input.
print vs logging?
logging with levels and handlers; print debugging never survives to production.
Python
Python Venv and Environments
Isolate dependencies per project with venv and pinned requirements.
Python Pip Essentials
Install, upgrade, and audit packages with pip like a pro.
Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
Python Strings
Slice, split, join, and format text efficiently.