pylint和autopep8配置流程
1、pylint
- 安装
pip install pylint
- 查看版本信息
pylint --version
- 使用
#pylint + 目标项目或者文件
pylint verify_paddle_install.py
- 输出
------------------------------------
Your code has been rated at 10.00/10
-
输出阐述
-
使用pylint有如下几种提示级别Error(错误)、Warning(警告)、Refactor(重构)、Convention(规范)
-
输出的结果包括:与规范冲突的位置(行列)、违反的规范编号以及具体的内容提示,还有一个有趣的地方,就是会给检查项目打分,满分10分,大家可以试试自己的项目,看看编码规范评分是多少
-
从检查信息可以看到,上述代码缺少模块注释(Missing module docstring)以及函数注释(Missing function docstring),函数名不符合蛇形命名规范(全由小写字母和下划线组成,在两个单词之间用下滑线连接)
-
-
pylint的5种信息类型
Output:
Using the default text output, the message format is :
MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
There are 5 kind of message types :
* (C) convention, for programming standard violation
* (R) refactor, for bad code smell
* (W) warning, for python specific problems
* (E) error, for probable bugs in the code
* (F) fatal, if an error occurred which prevented pylint from doing further processing.
* (C) 约定,用于违反编程标准
* (R) 重构,针对糟糕的代码味道
* (W) 警告,针对 python 特定问题
* (E) 错误,用于代码中可能的错误
* (F) 致命的,如果发生错误导致 pylint 无法进行进一步处理。
- pylint官网
- https://pylint.readthedocs.io/en/latest/
2、autopep8
- 作用:建议代码书写格式
- 代码自动格式化
- ctrl + s 即可实现