The Text File:
username
password
other
The code:
filepass = datafile.readline(1)
filepass.rstrip('\n')
datafile.close()
entered_password = input("Enter Password")
if entered_password == filepass:
print ("Success")
else:
print ("Failure")
Python always says "Failure" no matter what I type in. What do I need to do? Thanks in Advance.
readlines()
, your question code uses readline()
. Two different functions size
/ hint
parameter you have specified reads up to the number of bytes (not lines in either case -- bytes). You probably meant something like this
entered_password = datafile.readlines()[1].strip()
With some obvious fault tolerance to add to your code, but not specified here.
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.