Autopep8簡介html
官方解釋: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.python
官網地址:https://pypi.org/project/autopep8/#installationide
Python語言的編碼聽從PEP8規範,Autopep8工具可以依據PEP8規範,快速對代碼文件進行規範檢查並自動排版。對於變量名,類名,函數名等,會給出提示信息,須要工程師手動修改。函數
Autopep8的安裝。有了pip工具,能夠用命令輕鬆安裝:工具
$ pip install autopep8ui
Autopep8的命令行格式運行:編碼
$ autopep8 --in-place --aggressive --aggressive <filename>命令行
在Pycharm中集成Autopep8:3d
Step1:code
File -> Settings… ->Tools -> External Tools -> 點擊「+」號添加
Step2:
在添加界面,有5處須要添加
Name:autopep8
Program:C:\Python27\Scripts\autopep8.exe(在python的Scripts目錄下)
Arguments:--in-place --aggressive --aggressive $FilePath$
Working directory:$ProjectFileDir$
Output filters:$FILE_PATH$\:$LINE$\:$COLUMN$\:.*
配置完成後,點擊OK結束。
Step3:
右鍵點擊須要規範的文件,在菜單中找到External Tools -> autopep8。完成!
規範完了以後,文件中存在一些波浪線的代碼,就是須要手動修改的地方。
上面是徹底按照標準的PEP8規範進行代碼格式化的。可是有一些規範,能夠忽略,此時能夠在Parameters中加入—ignore參數。如:
Parameters:--in-place --aggressive --ignore=E123,E133,E50 $FilePath$
--ignore後面的E123等就是PEP8的規範代號,具體所指的規則,能夠在這裏查看到:
https://pep8.readthedocs.io/en/latest/intro.html#configuration
用戶能夠根據須要,添加須要忽略的規則。