[英]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? 不管我输入什么内容,Python都总是说“ Failure”。我需要做什么? Thanks in Advance.
提前致谢。
readlines()
, your question code uses readline()
. readlines()
,您的问题代码使用readline()
。 Two different functions size
/ hint
parameter you have specified reads up to the number of bytes (not lines in either case -- bytes). size
/ hint
参数最多读取字节数(在任何情况下都不行-字节)。 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. 可以在代码中添加一些明显的容错功能,但此处未指定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.