搜索的數據我有abcd.txt無法在一個文件在python
Shashank Saxena 24 male
Saurabh Parikh 23 male
Pradip Pillai 32 male
文件我有過這個文件中搜索search.py腳本。 這個search.py從html文件獲取值並在abcd.txt文件中進行搜索。 HTML有4個字段,分別是Firstname,Lastname,Age和Gender。當在姓名字段中輸入的數據是越來越搜查,但不是爲別人領域的沒有得到搜索
#!/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"
'''
get_search()
請修復代碼的縮進。 –
這與我使用的是一樣的。沒有縮進問題 –
因此'Lname = form.getvalue('lastname')'是'get_search'的最後一行嗎?看起來並不適合我。 –