[英]Python 3 readline() does not work
文本文件:
username
password
other
編碼:
filepass = datafile.readline(1)
filepass.rstrip('\n')
datafile.close()
entered_password = input("Enter Password")
if entered_password == filepass:
print ("Success")
else:
print ("Failure")
不管我輸入什么內容,Python都總是說“ Failure”。我需要做什么? 提前致謝。
readlines()
,您的問題代碼使用readline()
。 兩種不同的功能 size
/ hint
參數最多讀取字節數(在任何情況下都不行-字節)。 你可能是這樣說的
entered_password = datafile.readlines()[1].strip()
可以在代碼中添加一些明顯的容錯功能,但此處未指定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.