Python用列表实现简单的登陆_简单

http://bbs.51cto.com/viewthread.php?tid=1318046  这是原帖

#!/usr/bin/env python
#-*- coding:UTF-8 -*-                            


file_obj = file ('D:\Python\TEST1.txt','r+')  #打开TEST1.txt这个文档以r+的方式
L = []   #定义一个空list
obj_list=file_obj.readlines()     #读取TEST1.txt的多行 我就写了两行而已

for ele in obj_list:
        line= ele.strip()        #去掉每个字符的空格
        v =line.split(' ')       #以空格分割每个字符
        L.extend(v)        #将每个元素添加进L列表 这里注意如果用append是添加进list
print L
conter = 0
import getpass

while True:
        if conter < 3:
                Account = raw_input('please input your username:')
                if Account in L:
                        print "welcome loading"
                        break
                else:
                        print 'loading error , please again:'
                        conter +=1
                        continue
        else:
                break
while True:
        if conter < 5:
                passwd = getpass.getpass('please input password:')  #这里密码不是显示的
                if len(passwd) ==0 or passwd != 'p@ssword':
                        print "password error"
                        conter +=1
                        continue
                else:
                        print "loading complet"
                        break
        else:
                print "byebye!"
        break