![](/img/trans.png)
[英]Reading lines from .txt into batch file and handing into command line as arguments?
[英]Problem with reading lines in TXT File, for line in
我有一个问题,不允许我制作登录系统。 我想在这里做的是打开TXT文件,并在一行中搜索用户名和密码。 如果密码和用户名在一行,则登录成功,我们可以继续。 我的代码:
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;
编辑** 编辑一些代码后,我又收到一个错误。
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;
它不应该工作,使用上下文管理器的正确方法是使用with
关键字, while
不是while
。 使用上下文管理器后还要保留正确的缩进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.