私はPython 3.6.3を使用しています。Python-3.6 - "Not In List"エラー
私はcsvファイルからユーザー名とパスワードを検証しようとしています。ユーザ名とそれに続くパスワードはテキストファイルの新しい行にあるので、空の配列に追加すると "up"と呼ばれ、2d配列になり、各行は "up"内のリストになります。ユーザーにユーザー名とパスワードを尋ねます。だから、私はのxのために、)を使用して、up [up.index(x)]を経由して各リストをループし、.index(username)を直後に使用しようとしました。 j(j = up [up.index(x)]と呼ばれる変数index(username))。コードが表示され、セクションの強調表示に問題があります。 これらは、csvファイルの内容は以下のとおりです。私はそれがリストにないでユーザ名を言って、エラーを返すコードを実行するとText File
。私は答えを探しましたが、何も見つかりませんでした。私が見落としたことはありますか?
ご協力いただきありがとうございます。
import csv
validoption = ["i","u"]
while True:
option = input("Sign in or sign up\nPlease enter 'i' to sign in or 'u' to sign up: ")
if option in validoption:
if option is "i":
with open("login.txt","r") as l:
up = []
read = csv.reader(l)
count = 0
for line in read:
up.append(line)
count=+1
invalid = True
while invalid:
username = input("Please enter your username: ")
password = input("Please enter your password: ")
if [[y is username for y in x] for x in up]:
for x in up:
j = up[up.index(x)].index(username)
if password in up[up.index(x)][j+1]:
invalid = False
else:
print("Password is incorrect")
else:
print("Username is not recognised")
else:
with open("login.txt","a") as l:
username = input("Please enter your username: ")
while True:
password = input("Please enter your password\nPlease make sure that your password is longer than 8 characters, has a capiatal letter and a number: ")
if len(password)<8:
if any(p.isupper() for p in password):
if any(p.isdigit() for p in password):
break
else:
print("Password must have one number in it\n")
else:
print("Password must have one capital letter\n")
else:
print("Password must have more than 8 charaters")
userdetails = username+","+password
l.write(userdetails)
l.write("\n")
ありがとうございました:)
ユーザー名をキーに、パスワードを「定義」にして、辞書を「辞書」にしました。これはうまくいった。どうもありがとうございました :)))) – Ibby12311