Using Pep8 and autopep8

PEP 8:

Pep8 is a tool to check your Python code against some of the style conventions in PEP 8.

For more info check this out:

https://www.python.org/dev/peps/pep-0008/

Installation:

1)

You can install pep8 using pip

$ pip install pep8

Usage:

1)

Here you are checking the file optparse.py to see if it has any errors. This will only give you the pep8 error and the line on which the error occurs. The ‘–first’ will only show you the first occurrence of each error.

$ pep8 –first optparse.py

2)

If you also want to see the code which has the error along with the pep8 error. The file E40.py is being checked.

$ pep8 –show-source –show-pep8 testsuite/E40.py

 

AutoPep8:

Autopep8 automatically formats Python code to conform to the PEP 8 style guide. Autopep8 is capable of fixing most of the formatting issues that can be reported by pep8. Also autoppep8 is awesome (USE IT!!!!!)

Installation:

$ pip install autopep8

Usage:

$autopep8 –in-place –aggressive –aggressive <filename>

(

-i, --in-place        make changes to files in place
-a, --aggressive      enable non-whitespace changes; multiple -a result in
                      more aggressive changes

)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s