如果帐户与txt文档中的一行完全相同,是否有某种代码可以让我打印(“登录”)? [Python]

问题描述 投票:1回答:1
if(choice1 == "/login"):
  uname = input("Username: ")
  pword = input("Password: ")

  account = str(uname) + str(pword)

  with open("accounts.txt") as acc: #CHECKS IF ACCOUNT IS IN DIRECTORY
    info = acc.readlines()
    for line in info:
      if(account in line):
        print("Logged in")
        loggedin = True
        break

我有没有可能使"if(account in line):"表示为"if(account is exactly the same as in any of the lines here):"

python file-writing login-system
1个回答
0
投票

尝试一下,

if(choice1 == "/login"):
  uname = input("Username: ")
  pword = input("Password: ")

  account = str(uname) + str(pword)

  with open("accounts.txt") as acc: #CHECKS IF ACCOUNT IS IN DIRECTORY
    if account in acc.readlines():
        print("Logged in")
        loggedin = True
© www.soinside.com 2019 - 2024. All rights reserved.