1 回答

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
這是因?yàn)槟阅J酱蜷_(kāi)文件a+,該模式將文件指針?lè)旁谖募┪?。因?for 循環(huán)將立即結(jié)束并且什么也不會(huì)發(fā)生。
您需要以模式打開(kāi)文件r+。下面是一個(gè)工作示例:
email = emailEntry.get().strip()
if email:
with open('emails.txt', 'r+') as emailList:
found = False
for line in emailList:
if email == line.strip():
found = True
break
if found:
print('Someone already used this e-mail')
else:
print('add', email, 'to file')
emailList.write('\n'+email)
添加回答
舉報(bào)