How to validate a script in PEP8?

Asked

Viewed 243 times

3

I noticed some questions that asked about PEP8, something like "in this way is correct?", recent example:

Then I wondered, is there any way to know if the code is suitable and which line might not be in accordance?

It can be online or a library

1 answer

3


There is the https://github.com/PyCQA/pycodestyle, to install via pip use the following command:

pip install pycodestyle

Example of use in a file with "problems":

pycodestyle --first script_com_problemas.py

The way out will be something like:

script_com_problems.py:69:11: E401 Multiple Imports on one line

script_com_problemas.py:77:1: E302 expected 2 Blank Lines, found 1

script_com_problemas.py:88:5: E301 expected 1 Blank line, found 0

script_com_problemas.py:222:34: W602 deprecated form of Raising Exception

script_com_problemas.py:347:31: E211 whitespace before '('

script_com_problemas.py:357:17: E201 whitespace after '{'

script_com_troubles.py:472:29: E221 Multiple Spaces before Operator

script_com_problemas.py:544:21: W601 . has_key() is deprecated, use 'in'


If you need to update the package pycodestyle execute:

pip install --upgrade pycodestyle

If you want to uninstall run:

pip uninstall pycodestyle

Note: the package pep8 (https://pypi.python.org/pypi/pep8) is actually the same as the pycodestyle, but was renamed, do not install the package pepe8, will send a message warning to remove and install the pycodestyle


Alternative:

Pylint

To install run:

pip install pylint

To check your script:

pylint script_com_problemas.py

Validating the PEP8 online

If you are on a machine that makes it impossible for you to install something, you can use the following online service to validate your script:

If you find more services like this I will add later

  • You were able to validate the code of quoted question with this script [pep8.py]? I couldn’t get :(

  • @vnbrs tested now, both validated, could be some bug, I will test the installed tools, however I do not master PEP8, maybe there is a remote possibility of both being valid. Not that I disagree with your answer.

  • 1

    @strangely vnbrs when used inside [...] validation is ignored as follows: https://gist.github.com/brcontainer/b549a7e6149cb913bf6d3db9b7362fa4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.