Formatting and Styling Your Code Consistently

Using a program to automatically format code won’t necessarily prevent bugs, but it can improve the maintainability of your project over time by bringing consistency, readability, and reducing the number of “tabs versus spaces” style arguments your team has. Some languages include automatic code formatters as part of their implementation—go comes with gofmt, for example.

Python does not have a built-in mechanism for formatting code like go does, but a tool named black[34] is the Python Software Foundation’s “blessed” application for automatically formatting Python code.[35] black should be one of the tools in your tool box, and many popular Python projects and corporations (for example, Dropbox, Facebook, ...

Get Intuitive Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.