To ensure that your code is well-formatted, from now we will use the pycodestyle style guide checker.
Why is it important? Because otherwise you won’t be able to work as a team, sharing your source code. If you always have to correct annoying formatting issues, you cannot work on the real stuff. If you want more insight on why is it important, you may want to read this article.
First please read about the style guide, what’s inside:
https://www.python.org/dev/peps/pep-0008/
Pep8 standards are implemented as a python package that you can install. To do that, first you need to install pip , a package manager for python:
sudo apt-get install python3-pip
Yes, you read it right, you use apt, ubuntu’s package manager to install a package manager for python. Please note that it’s python3, and that’s because python3 has its own version of pip, called pip3. In practice it means you should install all python packages with pip3 if you want to use them with your python3.
Please also note that ubuntu depends heavily on python, and you don’t want to mess with it. Please install the packages only for your user by using the –user option.
The packages to install are called pycodestyle and autopep8. Here is how you install them:
pip3 install --user pycodestyle
pip3 install --user autopep8
After this, you should have a pycodestyle and autopep8 command installed, however they are installed into the folder /home/
export PATH="$(systemd-path user-binaries):$PATH"
Now you can test how does it check your python files:
pycodestyle my_code.py
And with the autopep8 you can automatically reformat your code in the PEP 8 style:
autopep8 --in-place --aggressive my_code.py