![](/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.