- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个场景,当我想使用 Python 文件运行 pylint
命令时。使用我正在使用的命令提示符
python3 -m pylint test.py
除此之外,我想格式化我的消息,以便以后可以使用 split 方法来分隔参数并像 Excel 一样输入报告。还要将 C0103 等代码替换为更有意义的名称。我在命令提示符下尝试了以下命令,但无法得到正确的答案
python3 -m pylint --msg-template="{module}{obj}{line}{column}{msg}" init.py
代码
# all of the following are equivalent
my_string = 'Hello'
print(my_string)
my_string = "Hello"
print(my_string)
my_string = '''Hello'''
print(my_string)
# triple quotes string can extend multiple lines
my_string = """Hello, welcome to
the world of Python"""
print(my_string)
输出
python3 -m pylint init.py
************* Module init
init.py:14:0: C0304: Final newline missing (missing-final-newline)
init.py:1:0: C0114: Missing module docstring (missing-module-docstring)
init.py:2:0: C0103: Constant name "my_string" doesn't conform to UPPER_CASE naming style (invalid-name)
init.py:5:0: C0103: Constant name "my_string" doesn't conform to UPPER_CASE naming style (invalid-name)
init.py:8:0: C0103: Constant name "my_string" doesn't conform to UPPER_CASE naming style (invalid-name)
init.py:12:0: C0103: Constant name "my_string" doesn't conform to UPPER_CASE naming style (invalid-name)
-------------------------------------------------------------------
Your code has been rated at 2.50/10 (previous run: -1.39/10, +3.89)
最佳答案
Apart from this i want to format my message such that i can later use split method to separate the arguments and feed in report like excel.
python3 -m pylint --msg-template="{module}{obj}{line}{column}{msg}" init.py
您是否考虑过在消息模板中添加分隔符?
因为在这里您只是将所有项目混在一起,这似乎不是很有帮助或有用,但也不难修复:
$ python3 -m pylint --msg-template="{module}{obj}{line}{column}{msg}" test.py
************* Module test
test10Missing module docstring
test20Constant name "my_string" doesn't conform to UPPER_CASE naming style
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
$ python3 -m pylint --msg-template="{module}|{obj}|{line}|{column}|{msg}" test.py
************* Module test
test||1|0|Missing module docstring
test||2|0|Constant name "my_string" doesn't conform to UPPER_CASE naming style
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
尽管如果您想以编程方式使用输出,-f
参数可能更有用。 pylint -f json
会将所有诊断转储为 json 对象数组,例如具有良好命名属性的数组。
Also replace code's like C0103 with more meaningful name. I tried below command from command prompt but could not get proper answer
从文档中,您想要的模板项是symbol
,即“消息的符号名称”:
$ pylint test.py
************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:2:0: C0103: Constant name "my_string" doesn't conform to UPPER_CASE naming style (invalid-name)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 4.29/10, -4.29)
$ pylint --msg-template='{msg_id}' test.py
************* Module test
C0114
C0103
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
$ pylint --msg-template='{symbol}' test.py
************* Module test
missing-module-docstring
invalid-name
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
I have a scenario when i want to run the pylint command using a Python file.
使用子进程运行 pylint 可能是最简单且支持最好的方法。你可以手动配置和运行pylint.lint.PyLinter
,但据我所知,它没有文档记录,不受支持,绝对是一个痛苦的事情,而且很容易摔倒(就像 pylint 中的崩溃一样) - 遗憾的是,这很常见 --- 将删除整个脚本)。我们曾经在 $dayjob 中这样做过,然后又回到在子进程中运行 CLI,它更加可靠。
关于python - 如何从 python 代码执行 pylint 命令。另外 pylint 中的哪些参数可以根据我的需要生成日志消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60202640/
以 pylint-1.0.0 开头--include-ids不再允许争论。 如何得到: ************* Module foo.bar E:199,11: Module 'yaml' has
Pylint 在 Linux 运行中退出,代码为 28。这个错误代码是什么意思? 我知道这并不意味着空间不足,因为我在空 VM 上尝试了相同的命令。 最佳答案 Linux 上的 Pyline 退出代码
第 4.1 节中的文档明确指出: https://pylint.readthedocs.io/en/latest/faq.html#message-control 4.1 Is it possible
我正在寻找类似的东西 [BASIC] good-names=X, y 如在 pylintrc 中,但我想将这些名称限制为仅在单个 python 文件中有效。 我考虑过在文件顶部使
给定以下 python 代码: import git try: raise git.exc.GitCommandError("dummy", "foo") except git.exc.Git
为了识别臭代码,我想运行 pylint好像没有# pylint: disable=*说明(例如 pylint: disable=broad-except )。 是否可以禁用 disable自己在命令行
在 python 文件上运行 pylint 时,它默认显示有关 TODO 注释的警告。例如: ************* Module foo W:200, 0: TODO(SE): fix this
这个问题已经有答案了: Invoking Pylint programmatically (10 个回答) 已关闭 9 年前。 我使用Python 3.3,Windows,通过pip工具安装pylin
我已经在我在 Ubuntu 18.04 上使用的 VM 上正确安装了所有上述模块。在特定脚本或文件夹上运行它们中的任何一个时,它们会正确识别样式错误并将其输出到控制台中。例如。: (venv) ...
我正在尝试将模块添加到我的 Pylint 路径,以便可以使用 seen in this question 的解决方案导入它们.不幸的是,我期望在使用此解决方案后应该可以导入的模块似乎仍然不存在。我想检
我的 Pylint 安装导入 flask 就好了。并且使用相同的 flask 安装,我的应用程序中运行良好的 wtforms。但是,当我在导入 wtforms 的文件上运行 Pylint 时: fro
我正在使用 pylint 1.6.4和 git-pylint-commit-hook 2.1.1在预提交时对我的文件进行 lint。我也用 alembic为了生成我的迁移,它们存储在 /migrati
我正在尝试让 Eclipse 识别我在 Jenkins 中使用的 PyLint 配置文件。目前,Eclipse pylint 充斥着无用的错误。我尝试过传入 rcfile 参数。所以... Windo
在python linting docs对于 VS Code,它有这个用于将插件添加到 pylint 的示例: "python.linting.pylintArgs": ["--load-plugin
为什么 pylint 提示这个代码块?R1705: Unnecessary "elif" after "return" (no-else-return) def f(a): if a == 1
我有一个场景,当我想使用 Python 文件运行 pylint 命令时。使用我正在使用的命令提示符 python3 -m pylint test.py 除此之外,我想格式化我的消息,以便以后可以使用
$ pylint --reports=n main.py 输出: No config file found, using default configuration 最佳答案 如果您没有 No con
如何在 Pylint 中禁用“关键字参数分配周围不允许有空格”? 我找到了为什么它会检查空格( PEP 8, why no spaces around '=' in keyword argument
我正在使用带有包控制的 Sublime Text 3 前几天我通过Package Control安装了Pylint 但是不行,只要打开Sublime Text 3就跳出这个提示框 我该如何解决? 最佳
我正在使用pytorch并且pylint无法识别例如torch.stack的几个函数,但是,如果我导入torch._C as torch 似乎工作正常。 如果我执行上述操作,torch 包中存在的实际
我是一名优秀的程序员,十分优秀!