Getting Code Formatted Correctly

Code should follow a consistent standard to help readability. For Python this standard is defined in the style-guide called PEP-8.

If you use PyCharm, you can use there hints. These appear as a yellow underline around the offending code, and on the right margin. You can also scan an entire prject with the Code…Inspect Code menu option.

To scan for PEP-8 compliance on the command-line, you can use the flake8 module.

The Black will fix many issues for you automatically, rather than just telling you about them.

Using the pre-commit module along with flake8 and Black will make sure that code meets standards before allowing it to be committed.

flake8 can also be added as part of the Continuous Integration and cause a broken build if standards aren’t met.