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