Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:If中的测试总是返回false_Python - Fatal编程技术网

Python:If中的测试总是返回false

Python:If中的测试总是返回false,python,Python,以下是我正在运行的测试: accget = StringVar() E2 = Entry(pm, bd =1, textvariable = accget).grid(row=1, column=1) B2 = Tkinter.Button(pm, text ="Access saved passwords", command = accesspass).grid(row=1,column=3) def accesspass(): f

以下是我正在运行的测试:

accget = StringVar()
E2 = Entry(pm, bd =1, textvariable = accget).grid(row=1, column=1)
B2 = Tkinter.Button(pm, text ="Access saved passwords", 
                        command = accesspass).grid(row=1,column=3)


def accesspass():
    for line in reversed(open("passfile.txt", "r").readlines()):
        if str(accget) in line:
            print("yes")   
        else:
            print("no")
设置在GUI中,当用户填写E2并按下B2时,程序会从最后一行开始迭代passfile.txt,如果字符串在一行中,则意味着打印yes。但是,即使一个单词在一行中,或者我已经将该行的全部内容放在字段中,测试也总是返回false,并且我对everyline的结果都是no


有人能解释一下为什么会这样吗?

我想先试试两件事

打印变量,包括accget和文件中的每一行。确保你看到了你所期望的

确保accget的格式与您期望的一致。意思是空白,大写,等等。 祝你好运

应该是

if accget.get() in line:

不知道文件的内容很难说。你试过打印这些行吗?在比较字符串之前,请考虑使用.TABLE函数。文件包含一类列表,用于类似行后的名称:相应的NAMYANKUYU!您能解释一下为什么会有不同吗?accget是一个StringVar,您必须使用get获取值
if accget.get() in line: