我使用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/