简体   繁体   中英

Problem with reading lines in TXT File, for line in

I have a problem which don't let me to make a Login System. What I want to do here is Open the TXT file, and search for Username and Password in one line. If the password and Username is in the one Line, the login is successful, we can continue. My code:

elif "l" in Register_Login or "L" in Register_Login:
        check = True
        while open(Database, mode = 'r', encoding = 'utf-8') as f:
        Vardas = input("Please enter your Username!\n")
        Password = getpass.getpass("Please enter your Password!\n")
        for line in f:
            if("Vardas : " + Vardas + " Password : " + Password + " ") == line.strip():
                print("You're logged in")
                check = False
                break;
            else:
                print("Wrong Combination!")
                continue;

My TXT File Lines. 在此处输入图片说明

EDIT** After editing some code, I get another error.

elif "l" in Register_Login or "L" in Register_Login:
    check = True
    with open('Registruoti.txt', mode = 'r', encoding = 'utf-8') as f:
        Vardas = input("Please enter your Username!\n")
        Password = getpass.getpass("Please enter your Password!\n")
    for line in f:
        if("Vardas : " + Vardas + " Password : " + Password + " ") == line.strip():
            print("You're logged in")
            check = False
            break;
        else:
            print("Wrong Combination!")
            continue;

错误2

It is not supposed to work, the correct way to use a context manager is by using with keyword, not while . Also preserve the correct indentation after using a context manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM