我有一个文件 abcd.txt
Shashank Saxena 24 male
Saurabh Parikh 23 male
Pradip Pillai 32 male
我有搜索此文件的 search.py 脚本。这个 search.py 从 html 文件中获取值并在 abcd.txt 文件中进行搜索。HTML有4个字段,分别是名字、姓氏、年龄和性别。当在名字字段中输入数据时,它正在被搜索,但对于其他字段,它不会被搜索
#!/usr/bin/python
import cgi
def get_search():
found = False
form = cgi.FieldStorage()
Fname = form.getvalue('firstname')
Lname = form.getvalue('lastname')
Age = form.getvalue('age')
Gender = form.getvalue('gender')
print "Content-type:text/html\n"
f = open("/tmp/abcd.txt","r")
for line in f:
temp = line.split()
#print temp
Fsearch = temp[0]
Lsearch = temp[1]
Asearch = temp[2]
Gsearch = temp[3]
if Fname.lower() in Fsearch.lower():
print line
found = True
if Lname.lower() in Lsearch.lower():
print line
found = True
if Age in Asearch:
print line
found = True
if Gender in Gsearch:
print line
found = True
if not found:
print "No such Records"
'''
if Fname in temp or Lname in temp or Age in temp or Gender in temp:
print "Hello", line
found = True
if not found:
print "No matched records"
'''
获取搜索()