• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python语言规范之Pylint的详细用法

python 搞代码 4年前 (2022-01-07) 75次浏览 已收录 0个评论
文章目录[隐藏]

Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint 默认使用的代码风格是 PEP 8)和有潜在问题的代码,接下来通过本文给大家介绍Python Pylint的使用,感兴趣的朋友一起看看吧

1、Pylint是什么

pylint是一个Python源代码中查找bug的工具,能找出错误,和代码规范的运行。也就是你的代码有Error错误的时候能找出来错误,没有错误的时候,能根据Python代码规范给你建议修改代码,让代码变更美观。

2、安装pylint

 p<a style="color:transparent">来源gao($daima.com搞@代@#码网</a>ip3 install pylint

3、查找pylint的安装地址

 $ which pylint /Library/Frameworks/Python.framework/Versions/3.9/bin/pylint

4、Pycharm使用Pylint工具

1)Pycharm –> Preferences –> Tools –> External Tools –> +

Program:pylint的地址,可以通过which pylint找到地址Arguments:pylint运行的参数2)使用

3)得到的结果

 ************* Module 704 leetcode/704.py:28:0: C0305: Trailing newlines (trailing-newlines)         #文尾有多余的行 leetcode/704.py:1:0: C0114: Missing module docstring (missing-module-docstring)  # 脚本首行没有添加注释 leetcode/704.py:4:11: W0621: Redefining name 'nums' from outer scope (line 23) (redefined-outer-name)  #变量名字与函数参数名字不能一样 leetcode/704.py:4:28: W0621: Redefining name 'target' from outer scope (line 24) (redefined-outer-name) #变量名字与函数参数名字不能一样 leetcode/704.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)  #函数缺少注释,注释要放在函数的第一行而不是def的上面

5、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 无法进行进一步处理。

6、更多的pylint信息

1)可以通过命令行获取

 pylint --list-msgs

2)官网

http://pylint.pycqa.org/en/latest/#

以上就是Python语言规范之Pylint的使用的详细内容,更多关于Python Pylint的使用的资料请关注gaodaima搞代码网其它相关文章!

以上就是Python语言规范之Pylint的详细用法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python语言规范之Pylint的详细用法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址