So, I could be going about this the wrong way and if so, I’d appreciate a different way at looking at solving the problem, but here is what I am trying to do, and how I’m attempting to do it.
I am making a simple address-book based on some beginner project suggestions I found and I’m slowly implementing it, but I cannot figure how to get it to search for a certain section of the file. I want it to print the name, address, phone and mobile. All of which are on a separate line, 4 lines total.
I’m using the following code to accomplish this:
def search_entries():
found = 0
search = raw_input("Please enter the person's name: ")
for line in open('addbook.txt', 'r').readlines():
if search in line:
found = 1
if found >= 1:
print line
if found == 4: break
However, instead of printing just printing those 4 lines from the person’s name it prints the rest of the file. Any help is appreciated, thanks.
Realized that I forgot to add a counter to the code: