第三种:用字典的方式来实现
#!/usr/bin/env python
f=file('contact.txt')
personal={}
for line in f.readlines():
name= line.split()[0]
personal[name]=line
while True:
f=file('contact.txt')
personal={}
for line in f.readlines():
name= line.split()[0]
personal[name]=line
while True:
input=raw_input('please input username:').strip()
if len(input) == 0:continue
if input in personal:
#if personal.has_key(input):
#print 'username information: %s' %personal.get(input)
print 'username information: %s' %personal[input]
else:
print '%s not found,please input' %input
Python简单查询用户(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/80c7b0f8b483cb008b0ec421a06617d4.html