【发布时间】:2015-08-27 13:10:10
【问题描述】:
for 循环的结构看起来不对。由于某种原因,它没有正确跳转到语句的“else”部分。我将在控制台中尝试这个以简化一些事情,看看我是否有运气:
def verifylogin():
fin=open("moosebook.txt","r")
data=fin.readlines()
for line in data:
fields=line.split()
fields=[i.rstrip("','") for i in fields] #strips the named character from END of field
fields=[i.replace("'",'') for i in fields]#when reading the list, you want to remoe the ',' so it isn't part of the username or password
fields=[i.replace("(",'') for i in fields] #simiarly, remove the bracket and replace it
line=line.rstrip()
print(fields)
access_permitted = False
for counter in range(0,len(fields)):
if textlogin.get()==fields[counter] and textpassword.get()==fields[counter+1]:
access_permitted=True
if access_permitted:
welcome=Label(myGui,text="Access Granted. Loading Profile ....")
welcome.pack()
else:
denied=Label(myGui,text="Access Denied")
denied.pack()
【问题讨论】:
-
你能展示一下
fields的样子吗? -
你能描述一下结果吗?
-
您确定 textlogin.get() 和 textpassword.get() 工作正常吗?
-
是的,textlogin 和 textpassword 肯定可以工作。我也试过这个:
-
结果:在输入 'fields[0] 和 fields[1]' 作为用户名和密码时,它会出现“Access Granted”......然后是几个 Access Denied。当我输入下一组用户名和密码时,它会执行类似的操作,除了以一些拒绝访问开始,然后是授予访问权限。换句话说,它有点工作,但不完全......