相关疑难解决方法(0)

PyLint 希望将变量命名为常量 [C0103]

为什么 PyLint 要求变量具有 UPPER_CASE 命名,就好像它是常量一样?

"""Stack reproducible example."""

some_list = ['foo', 'bar']
for i in some_list:
    counter = 3
    while counter != 0:
        print("Value of 'counter': " + str(counter))
        counter -= 1
Run Code Online (Sandbox Code Playgroud)

这给出了以下 linting 错误:

# C0103: Constant name "counter" doesn't conform to UPPER_CASE naming style (invalid-name)
Run Code Online (Sandbox Code Playgroud)

然而,与阿伏加德罗的常数、圆周率或真空中的声速不同, counter变化的值肯定必须使其成为“变量”?

我已阅读有关C0103 的页面,但我显然不明白某些内容。

for 循环是否被视为一次性函数,从而改变了约定,例如在这个问题中?

python pylint

1
推荐指数
1
解决办法
1704
查看次数

标签 统计

pylint ×1

python ×1