简体   繁体   中英

Python 3 readline() does not work

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.

  1. Your question title states readlines() , your question code uses readline() . Two different functions
  2. The 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM