Skip to content

How to make your code shine with isort, Black, Flake8, and Pylint. Guidelines and best practice suggestions on how to write Python code.

Notifications You must be signed in to change notification settings

mafda/python_best_practices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Best Practices

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

In this repository, 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 Pylint, 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

(base)$: git clone [email protected]:mafda/python_best_practices.git
(base)$: cd python_best_practices 

Configure environment

  • Create the conda environment
(base)$: conda env create -f environment.yml
  • Activate the environment
(base)$: conda activate linear-regression
  • And run
(linear-regression)$: sh pep8.sh

Use these tools in your project and clean your code!

(base)$: conda env create -f environment-dev.yml
(base)$: conda activate best-practices
(best-practices)$: cd your-project

isort

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

isort

Black

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

black

Flake8

You could use flake8 .

flake8

Fix errors:

flake8

PyLint

You could use find . -type f -name "*.py" | xargs pylint


made with 💙 by mafda