How to validate a script in PEP8?

4

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

So the question has arisen, is there any way to know if the code is appropriate and which line may not be in compliance?

It can be online or a library

    
asked by anonymous 03.12.2017 / 23:05

1 answer

3

There is the link , 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 output will look something like:

  

script_com_problems.py:69:11: E401 multiple imports on one line

     

script_com_problems.py:77:1: E302 expected 2 blank lines, found 1

     

script_com_problems.py:88:51: E301 expected 1 blank line, found 0

     

script_with_problems.py:222:34: W602 deprecated form of raising exception

     

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

     

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

     

script_com_problems.py:472:29: E221 multiple spaces before operator

     

script_with_problems.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: package pep8 ( link ) is actually the same as pycodestyle , but has been renamed, do not install pepe8 package, will issue a warning message to remove and install pycodestyle

Alternative:

PyLint

To install run:

pip install pylint

To check your script:

pylint script_com_problemas.py

Validating PEP8 online

If you are on a machine that prevents you from installing something, you can use the following online service to validate your script:

  

If you find more services like this I will add later

    
03.12.2017 / 23:05