Python Best Practices

fernanda rodríguez
2 min readFeb 23, 2023

--

How can you make your code shine with isort, Black, and Flake8?

Photo by Emile Perron on Unsplash

In this post, I would like to show some guidelines and best practice tips on how to write Python code.

We can use a simple deck of programs to get our code styling done. We can use isort for sorting the library imports (yes, imports have a suggested order), we can check the existence of undesired artifacts using Flake8, and we can keep the code within the same style using Black.

Those tools can be configured to be PEP8 compliant. PEP8 — Python Enhancement Proposal, is a style guide that provides guidelines and best practices suggestions on how to write Python code.

Python Tools

Project Setup

Clone this repository and follow the steps:

How does it works?

isort

You could use isort . or isort . --check-only

Importing sorting with isort

Black

You could use black --line-length 79 . or black --line-length 79 --check .

Formatting with Black

Flake8

You could use flake8 .

Linting with Flake8
Fix errors

made with 💙 by mafda.

--

--

fernanda rodríguez
fernanda rodríguez

Written by fernanda rodríguez

hi, i’m maría fernanda rodríguez r. multimedia engineer. data scientist. front-end dev. phd candidate: augmented reality + machine learning.