When you start your first Python project, the code that you or your team members are going to write should be consistent with the standards defined so that your code is readable. This will make it easier for anyone who comes after you, to develop the application, to understand the code.
pycodestyle
moduleWe are going to use pycodestyle
to check whether our not our code follows the coding standards. Earlier our module was named as pep8, but to avoid confusion, it was renamed to pycodestyle
.
This is a very easy module to use. First, install the module by running the following command:
pip install pycodestyle
After this, you can run the command below to check any Python file for standard checking:
pycodestyle <python_file_name>.py
Run the below code to see where this module identified the standard violation. When you click the “Run” button, the command is run internally:
pycodestyle main.py
Below is a simple code that prints the current working directory:
import os, sysdef printDirectory():print(os.getcwd())printDirectory()
Explanation:
After running the code, you can see that we have not incorporated all the Python coding standards; so, we should make changes to our code accordingly to make it more readable.