我正在使用格式化Python代码pylint并获取一些不需要的警告消息,如下所示.
C:204, 0: Invalid function name "sendPasswordViaEmail" (invalid-name)
C:207, 4: Invalid variable name "to" (invalid-name)
W:213, 4: Statement seems to have no effect (pointless-statement)
Run Code Online (Sandbox Code Playgroud)
我正在解释与以下消息相关的代码.
if request.method == 'POST':
name = request.POST.get('uname')
email = request.POST.get('uemail')
range_start = 10 ** (4 - 1)
range_end = (10 ** 4) - 1
password = randint(range_start, range_end)
passw = User(
uname=name,
password=password,
raw_password=password,
)
passw.save()
sendPasswordViaEmail(str(password), email)
return render(request, 'bookingservice/login.html')
def sendPasswordViaEmail(password, email):
""" Send email to user"""
to = email
gmail_user …Run Code Online (Sandbox Code Playgroud) 为什么 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 循环是否被视为一次性函数,从而改变了约定,例如在这个问题中?