#decoding=utf-8
'''
编写可供用户查询的员工信息表!
1|用户认证
ID Name department phone
查询关键字:姓名
'''
import linecache
input01=raw_input("pls write your name:")
i=1
name=[]
count = len(open('user.txt','rU').readlines())
while i<=count:
fline = linecache.getline("user.txt",i)
li=fline.split(" ",3)
i+=1
print li[1]
name.append(li[1])
print name
for x in name:
if x=input01:
print "it's ok!"
break
感觉程序比较死,有一些缺陷:
1)独立定义了一个name列表,浪费内存
2)if的判断,最好加入到第一个while循环中获取name字段
转载于:https://blog.51cto.com/yedee/1548926