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