Tips6 min read

10 Python Debugging Tips That Will Save You Hours

10 practical Python debugging techniques most developers skip — from pdb to better print debugging, breakpoints, and AI-powered root cause analysis.

PythondebuggingpdbVS Codeproductivitydeveloper tips

Most Python Debugging Is Slower Than It Needs to Be

The average developer spends 30-50% of their time debugging. These 10 techniques cut that time down.


1. Use `breakpoint()` Instead of `print()`

def process_order(order_id):
    order = fetch_order(order_id)
    breakpoint()   # execution pauses here
    return order

In pdb: p order to print, n for next, c to continue, q to quit.


2. `pp` in pdb for Readable Output

(Pdb) pp order.__dict__
{'id': 42, 'user_id': 7, 'items': [...], 'status': 'pending'}

3. `locals()` and `vars()` to Dump Current Scope

except Exception as e:
    print(f"Error: {e}")
    print(f"Local vars: {vars()}")
    raise

4. Trace Errors With `traceback`

import traceback
try:
    risky_operation()
except Exception:
    traceback.print_exc()

5. Use `assert` as Inline Sanity Checks

def calculate_discount(price, pct):
    assert 0 <= pct <= 100, f"Invalid discount: {pct}"
    return price * (1 - pct/100)

6. `logging` Instead of `print()` in Long-Running Code

import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
logging.debug(f"Processing order {order_id}")

7. `time.perf_counter()` for Performance Debugging

import time
start = time.perf_counter()
result = expensive_operation()
print(f"Took {time.perf_counter() - start:.3f}s")

8. Read Stack Traces Bottom-Up

The crash is the last frame before the error message. Start there, not at the top.


9. Use Type Hints + mypy to Catch Bugs Before Runtime

from typing import Optional
def get_user(user_id: int) -> Optional[User]:
    return db.query(User).filter_by(id=user_id).first()

Run mypy your_file.py to catch type errors statically.


10. When Manual Debugging Isn't Enough

Press Ctrl+Shift+P in VS Code with DebugAI — it reads your full stack trace, queries your local codebase, and returns 3 ranked fixes in under 10 seconds.

Install DebugAI

Debug faster starting today.

Free VS Code extension. 10 sessions/day. No credit card.

Install Free →

Related Posts

Tips

12 Best VS Code Extensions for Developers in 2026

6 min read

Tips

7 VS Code Debugging Tips That Most Developers Skip

6 min read

← All posts