4
我正在使用pylint
來格式化Python代碼,並獲取一些不需要的警告消息,如下所示。使用Python獲取無效的函數名稱警告
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)
我在下面解釋我的代碼與上面的消息有關。
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 = settings.EMAIL
gmail_pwd = settings.PASSWORD
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + \
gmail_user + '\n' + 'Subject:password \n'
msg = header + '\n Your password is\n\n' + password
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()
這是一個[PyLint](http://pylint-messages.wikidot.com/messages:c0103)消息。 「*當名稱不符合與其類型相關的命名約定(常量,變量,類...)*」時使用。 – Maroun
檢查:https://stackoverflow.com/a/25184336/2955375 – chinglun
sendPasswordViaEmail是一個無效的名稱。正確的名稱是send_password_via_email – Rahul