나는 계정을 등록하는 프로그램을 가지고 있으며, 이제는 계정을 기록하는 기능을 사용하고 있습니다. 텍스트 파일을 분리하기 위해 "사용자 이름"과 "암호"목록을 저장했습니다. .파이썬을 사용하여 텍스트 파일의 목록 검색
usernames = []
passwords = []
usernames.append(username)
passwords.append(password)
usernamesFile = open("usernames.txt","a")
for usernames in usernames:
usernamesFile.write("%s\n" % usernames)
usernamesFile.close()
passwordsFile = open("passwords.txt", "a")
for passwords in passwords:
passwordsFile.write("%s\n" % passwords)
passwordsFile.close()
while True:
loginUsername = raw_input("Enter your username: ")
usernamesFile = open("usernames.txt", "r")
lines = usernamesFile.readlines()
if loginUsername in usernames:
index = usernames.index(username)
break
else:
print "Username not found"
continue
내 문제는 내가 텍스트 파일을 테스트 한 내가 등록한 사용자 이름을 모두 저장에도 불구하고, 검색은 여전히 돌아 오면 "사용자 이름을 찾을 수 없습니다." 나는 파이썬 전문가가 아니므로 간단한 방법으로 설명하면 좋을 것입니다.
그것은 당신의 코드처럼 보이지 않는 지금 내가 추측하고있어'lines', 아무것도 당신을 통해 검색하고 싶었 무엇입니까? (또한 : 참고로 : 파이썬을 배우면서도 암호 목록을 지우는 아이디어를 즉시 제거해야합니다.) –
암호 목록을 일반 텍스트로 저장하지 않으려면 어떻게합니까? – ghj