如何检查python中输入的内容是否与csv文件中的内容相同

如何检查python中输入的内容是否与csv文件中的内容相同,python,csv,input,Python,Csv,Input,我试图制作一个程序,看看输入python程序的用户名和密码是否与存储在csv文件中的用户名和密码相同 logorsign = input("""Choose one: 1. Log in 2. Sign up 3. Quit """) print("") if logorsign == "1": Netflix_CSV = csv.reader(open("Netflix Task.csv", "rt")) first_Line = next

我试图制作一个程序,看看输入python程序的用户名和密码是否与存储在csv文件中的用户名和密码相同

logorsign = input("""Choose one:
1. Log in
2. Sign up
3. Quit
""")
print("")

if logorsign == "1":           
    Netflix_CSV = csv.reader(open("Netflix Task.csv", "rt"))       
    first_Line = next(Netflix_CSV)
    checkuser = input("Enter Username: ")
    print("")
    checkpasw = input("Enter Password: ")
    for row in Netflix_CSV:
        if row[0]  == checkuser:
            print(watched_films)
以上就是目前为止的代码

请帮忙


提前感谢

这里使用的最佳数据结构是字典:

user_passwords = dict()
user_films = dict()
user_logged_in = False

given_username = input('Enter Username: ')
print('')
given_password = input('Enter Password: ')
print('')

with open('Netflix Task.csv', 'r') as fh:
    reader = csv.reader(fh)
    reader.next()   # Skip the header line
    for line in reader:
        username, password, watched_films = line
        user_passwords[username] = password
        user_films[username] = watched_films

if user_passwords.get(given_username, False) == given_password:
    print('login successful')
    user_logged_in = True
else:
    print('Bad username/password')
然后,要访问用户的电影:

users_films = user_films[username]

请看一看pandas,它将改善您的查询。我遇到了以下错误:回溯(最近一次调用上次):文件“N:\Task 2.py”,第28行,与csv.reader(open('Netflix Task.csv','rt')一起作为fh:AttributeError:ExitMode更改为文件处理程序