How code linting will make you awesome at Python In Python code reviews I’ve seen over and over that it can be tough for developers to format their Python code in a consistent way: extra whitespace, irregular indentation, and other “sloppiness” then often leads to actual bugs in the program.

Luckily automated tools can help with this common problem. Code linters make sure your Python code is always formatted consistently—and their benefits go way beyond that.

What code linters can do for you A code linter is a program that analyses your source code for potential errors. The kinds of errors a linter can detect include: syntax errors;

structural problems like the use of undefined variables;

best practice or code style guideline violations. I find code linting to be an indispensable productivity tool for writing Python. It’s possible to integrate linting into your editing environment. This gives you immediate feedback on your code right when you type it: For some classes of errors, linting can shorten the usual write code, run code, catch error, fix error loop to write code, see and fix error. This difference might not seem much—but in the course of a day these time savings add up quickly and can have a huge impact on your productivity. In short, code linters are great!

Which Python linter should I use? Python has several good options for code linters. The ones I’m listing here are available for free and are open-source software: Flake8 is my personal favorite these days. It’s fast and has a low rate of false positives. Flake8 is actually a combination of several other tools, mainly the Pyflakes static analysis tool and the Pycodestyle (former pep8) code style checker.

Pylint is another good choice. It takes a little more effort to set up than Flake8 and also triggers more false positives. On the other hand it provides a more comprehensive analysis. Definitely not a bad choice—but I’d stick with Flake8 if you’re just starting out.