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
用户能够根据须要,添加须要忽略的规则。