PEP 8 and code formatters (Black, isort)
corebeginnerPEP 8 is Python's official style guide — spacing, naming, line length. Black and isort are tools that automatically reformat code to follow style rules, so a team never has to debate spacing or import order by hand.
Think of it as
PEP 8 is a style guide someone has to remember and apply by hand. Black and isort are that same guide, enforced automatically — a formatter never has an opinion to argue with, it just rewrites the file the same way every time.
What we're doing: Run black on a real, deliberately messy file and see exactly what it rewrites.
- 1
- One command rewrites the whole file — spacing around parentheses, operators, and quote style all normalized at once.
reformatted messy.py
All done! ✨ 🍰 ✨
1 file reformatted.Why this works: black applies its own fixed style — single quotes become double, extra whitespace inside parentheses is removed, spacing around operators is normalized — deterministically, the same way every time, on any file, with almost no configuration to disagree about.
Manually formatting code that a formatter already owns
Wrong
Better
What you see: Code review time gets spent debating spacing and quote style — a fully automatable, zero-judgment decision — instead of actual logic.
Why: A formatter removes style from the set of things a human ever needs to think about or argue over — running it as a required pre-commit or CI step means every file always matches the same style, with zero manual effort or debate.
- messy.py — unsorted imports, ragged spacing
- isort — sorts & groups imports only
- black — spacing, quotes, line breaks
Formatters — what each one rewrites
Together
Remember: PEP 8 is the style guide; black and isort enforce it automatically — run them before every commit so style is never a manual decision or a review debate.
See also: ruff and flake8 · pre commit hooks

