Im searching for a string in a file, but even though there is matching string in the file it always returns false. Where am I going wrong?
file = open('temp.txt', 'r')
def search(userinput, file):
file.seek(0)
filecontent = file.readlines()
for i in filecontent:
sp = i.split(' ')
t_name = sp[0] + ' ' + sp[1]
print (t_name)
if (t_name == userinput):
return True
else:
return False
searchstr = 'Peter Piper'
found = search(searchstr, file)
print (found)
file.close
temp.txt
Peter Piper 20 30
Tom Cat 10 20
Jerry Mouse 30 50