Search code examples
pylintflake8autopep8pycodestyle

How to make pylint, flake8 or pycodestyle to automatically correct errors?


I have properly installed all of the aforementioned modules on a VM I use on Ubuntu 18.04. When running either of them on a specific script or folder, they do correctly identify style errors and output them in the console. E.g.:

(venv) .../src$ python3.6 -m flake8
./free_prediction.py:8:1: E303 too many blank lines (5)
./free_prediction.py:8:28: E231 missing whitespace after ','
./free_prediction.py:10:5: E225 missing whitespace around operator
./free_prediction.py:12:3: E225 missing whitespace around operator
./free_prediction.py:15:13: E225 missing whitespace around operator

However, the same style errors persist in the code. How can I make them to be automatically corrected?


Solution

  • AFAIK, none of those linting tools will fix the style issues they identify. However, there are several code formatting tools that will automatically fix many of the style errors that were flagged.

    Some of the more popular Python code formatting tools worth checking out are: black, autopep8, and yapf. (all of them are on PyPI and installable via pip)

    More info: