python - Pylint:通过脚本获取输出,类似于 pylint 可执行文件

标签 python python-3.x pylint

我使用Python 3.3,Windows,通过pip工具安装pylint。
我可以通过“Scripts\pylint.exe”工具运行这样的命令 (参数很重要,我需要特殊的明文输出)

pylint --msg-template="{line}:{column}:{msg_id}: {msg}" --module-rgx=.* --reports=n --persistent=n "D:\TestLint\sample_plugin.py"

这会检查我的文件并给出这样的输出

************* Module sample_plugin
1:0:C0111: Missing module docstring
1:0:F0401: Unable to import 'tst'
3:0:W0232: Class has no __init__ method
3:0:C0111: Missing class docstring
3:0:C1001: Old-style class defined.
4:4:C0111: Missing method docstring

现在我想通过Python代码使用pylint,而不是使用任何EXE工具。并希望有类似/相同的输出 我的测试文件。所以提问。我可以编写什么 Py 脚本来调用 pylint 并获得相同的输出(字符串或列表)?

最佳答案

有几种方法可以做到这一点。最简单的是:

from pylint.lint import Run
Run([file_or_module, '--message-template', '...'])

如果您想在子进程中运行 pylint(建议多次运行),请尝试:

from pylint.epylint import lint
lint(file_or_module, [--message-template', '...']

关于python - Pylint:通过脚本获取输出,类似于 pylint 可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22239968/

相关文章:

python - Cython setup.py 找不到已安装的 Visual C++ 构建工具

python - 如何处理 Pylint 的 "too-many-instance-attributes"消息?

python - pylint 提示 py.test : "Module ' pytest' has no 'raises' member"

cython - 在 cython 代码上运行 pep8 或 pylint

Python 日期时间添加

python - 安装 scipy 版本 1.1.0

python-3.x - Elasticsearch 搜索字段

python - python中文件的权限更改

python - django "Exception Value: No module named urls"用于管理站点

python - 一个比较特殊的txt文件解析