Lesson 55 of 55
PythonBest‑Practices & Debugging
15 minutes
Course progress100%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 55 of 55
Python15 minutes
Keep these ideas in mind as you work through the lesson.
Even after you know how to write code, writing good code and fast debugging are what make a professional developer.
flake8.black .).isort .).pip install flake8 black isort
flake8 src/ # shows style warnings
black src/ # rewrites files in‑place
isort src/ # tidy import order
pdbInsert breakpoint() (Python 3.7+) anywhere:
def compute(x):
breakpoint() # drops you into the REPL
return x * 2
You can inspect variables, step (n), continue (c) or quit (q).
For a richer experience install ipdb:
pip install ipdb
Replace breakpoint() with import ipdb; ipdb.set_trace().
python -m cProfile -s cumulative myscript.py
pip install line_profiler
kernprof -l -v myscript.py
printimport logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
logging.debug('Debug details')
logging.info('Normal operation')
logging.warning('Something odd')
logging.error('Error occurred')
You can switch the level without editing code, pipe logs to a file, and add rotating file handlers for production.
mypy --strict).pytest --cov)..env files (python‑dotenv).Following this checklist will keep your code clean, maintainable, and easier to debug when things go wrong.