chuckiechan1
Programmer
I think I have this doing what I want except I would like it to search each line throughout the document adding the amount of times the group was found.
I was thinking I could do this with a while loop and readline() although I could not make it work and if I put a readline() in place of the read() I couldn’t get the results I was with read() it would come up “was not found” I am not sure why because my search was on the first line in the document.
If anyone could let me know what I am doing wrong or if there is a better way that would be grate. Thanks.
This is the code I am using now without repeating over the lines.
I was thinking I could do this with a while loop and readline() although I could not make it work and if I put a readline() in place of the read() I couldn’t get the results I was with read() it would come up “was not found” I am not sure why because my search was on the first line in the document.
If anyone could let me know what I am doing wrong or if there is a better way that would be grate. Thanks.
This is the code I am using now without repeating over the lines.
Code:
look_in = raw_input ("Enter the search file to look in ")
search = raw_input ("Enter your search item ")
txt = open(look_in).read()
search2 = search.split()
for item in search2:
c = txt.count(item)
if c > 0: print "(",c,")", "Of your search was found"
else: print item, "was not found"