Python自动格式化插件autopep8

# NOTE: 安装autopep8
$ pip install --upgrade autopep8

# NOTE: 对文件进行格式化
$ autopep8 --in-place --aggressive --aggressive 

扩展阅读

autopep8 1.3.2
https://pypi.python.org/pypi/autopep8/1.3.2
简介:

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pycodestyle utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pycodestyle.

autopep8 fixes the following issues reported by pycodestyle:

E101 - Reindent all lines.
E11  - Fix indentation. (not include E112 and E113)
E121 - Fix indentation to be a multiple of four.
E122 - Add absent indentation for hanging indentation.
E123 - Align closing bracket to match opening bracket.
E124 - Align closing bracket to match visual indentation.
E125 - Indent to distinguish line from next logical line.
E126 - Fix over-indented hanging indentation.
E127 - Fix visual indentation.
E128 - Fix visual indentation.
E20  - Remove extraneous whitespace.
E211 - Remove extraneous whitespace.
E22  - Fix extraneous whitespace around keywords.
E224 - Remove extraneous whitespace around operator.
E226 - Fix missing whitespace around arithmetic operator.
E227 - Fix missing whitespace around bitwise/shift operator.
E228 - Fix missing whitespace around modulo operator.
E231 - Add missing whitespace.
E241 - Fix extraneous whitespace around keywords.
E242 - Remove extraneous whitespace around operator.
E251 - Remove whitespace around parameter '=' sign.
E26  - Fix spacing after comment hash for inline comments.
E265 - Fix spacing after comment hash for block comments.
E27  - Fix extraneous whitespace around keywords.
E301 - Add missing blank line.
E302 - Add missing 2 blank lines.
E303 - Remove extra blank lines.
E304 - Remove blank line following function decorator.
E306 - Expected 1 blank line before a nested definition
E401 - Put imports on separate lines.
E501 - Try to make lines fit within --max-line-length characters.
E502 - Remove extraneous escape of newline.
E701 - Put colon-separated compound statement on separate lines.
E70  - Put semicolon-separated compound statement on separate lines.
E711 - Fix comparison with None.
E712 - Fix comparison with boolean.
E721 - Use "isinstance()" instead of comparing types directly.
E722 - Fix bare except.
W291 - Remove trailing whitespace.
W292 - Add a single newline at the end of the file.
W293 - Remove trailing whitespace on blank line.
W391 - Remove trailing blank lines.
W601 - Use "in" rather than "has_key()".
W602 - Fix deprecated form of raising exception.
W603 - Use "!=" instead of "<>"
W604 - Use "repr()" instead of backticks.
W690 - Fix various deprecated code (via lib2to3).
autopep8 also fixes some issues not found by pycodestyle.

Correct deprecated or non-idiomatic Python code (via lib2to3). Use this for making Python 2.6 and 2.7 code more compatible with Python 3. (This is triggered if W690 is enabled.)
Normalize files with mixed line endings.
Put a blank line between a class docstring and its first method declaration. (Enabled with E301.)
Remove blank lines between a function declaration and its docstring. (Enabled with E303.)
autopep8 avoids fixing some issues found by pycodestyle.

E112/E113 for non comments are reports of bad indentation that break syntax rules. These should not be modified at all.
E265, which refers to spacing after comment hash, is ignored if the comment looks like code. autopep8 avoids modifying these since they are not real comments. If you really want to get rid of the pycodestyle warning, consider just removing the commented-out code. (This can be automated via eradicate.)

你可能感兴趣的:(Python自动格式化插件autopep8)