pep8 (original) (raw)

pep8 - Python style guide checker

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

Features

Installation

You can install, upgrade, uninstall pep8.py with these commands:

$ pip install pep8 $ pip install --upgrade pep8 $ pip uninstall pep8

There’s also a package for Debian/Ubuntu, but it’s not always the latest version.

Example usage and output

$ pep8 --first optparse.py optparse.py:69:11: E401 multiple imports on one line optparse.py:77:1: E302 expected 2 blank lines, found 1 optparse.py:88:5: E301 expected 1 blank line, found 0 optparse.py:222:34: W602 deprecated form of raising exception optparse.py:347:31: E211 whitespace before '(' optparse.py:357:17: E201 whitespace after '{' optparse.py:472:29: E221 multiple spaces before operator optparse.py:544:21: W601 .has_key() is deprecated, use 'in'

You can also make pep8.py show the source code for each error, and even the relevant text from PEP 8:

$ pep8 --show-source --show-pep8 testsuite/E40.py testsuite/E40.py:2:10: E401 multiple imports on one line import os, sys ^ Imports should usually be on separate lines.

Okay: import os\nimport sys
E401: import sys, os

Or you can display how often each error was found:

$ pep8 --statistics -qq Python-2.5/Lib 232 E201 whitespace after '[' 599 E202 whitespace before ')' 631 E203 whitespace before ',' 842 E211 whitespace before '(' 2531 E221 multiple spaces before operator 4473 E301 expected 1 blank line, found 0 4006 E302 expected 2 blank lines, found 1 165 E303 too many blank lines (4) 325 E401 multiple imports on one line 3615 E501 line too long (82 characters) 612 W601 .has_key() is deprecated, use 'in' 1188 W602 deprecated form of raising exception

Build status Wheel Status

Changelog

1.7.1 (2017-10-22)

Changes:

1.7.0 (2016-01-12)

Announcements:

Changes:

Bugs:

1.6.2 (2015-02-15)

Changes:

Bugs:

1.6.1 (2015-02-08)

Changes:

Bugs:

1.6.0 (2015-02-06)

News:

Changes:

Bug fixes:

1.5.7 (2014-05-29)

Bug fixes:

1.5.6 (2014-04-14)

Bug fixes:

1.5.5 (2014-04-10)

Bug fixes:

1.5.4 (2014-04-07)

Bug fixes:

1.5.3 (2014-04-04)

Bug fixes:

1.5.2 (2014-04-04)

Changes:

Bug fixes:

1.5.1 (2014-03-27)

Bug fixes:

1.5 (2014-03-26)

Changes:

Bug fixes:

1.4.6 (2013-07-02)

Changes:

Bug fixes:

1.4.5 (2013-03-06)

1.4.4 (2013-02-24)

1.4.3 (2013-02-22)

1.4.2 (2013-02-10)

1.4.1 (2013-01-18)

1.4 (2012-12-22)

1.3.4 (2012-12-18)

1.3.3 (2012-06-27)

1.3.2 (2012-06-26)

1.3.1 (2012-06-18)

1.3 (2012-06-15)

1.2 (2012-06-01)

1.1 (2012-05-24)

1.0.1 (2012-04-06)

1.0 (2012-04-04)

0.7.0 (2012-03-26)

0.6.1 (2010-10-03)

0.6.0 (2010-09-19)

0.5.0 (2010-02-17)

0.4.2 (2009-10-22)

0.4 (2009-10-20)

0.3.1 (2009-09-14)

0.2 (2007-10-16)

0.1 (2006-10-01)