There are many things to improve in your code.
data is a string, and str has no attribute readline().
read will read the whole content from file. Don't do this.
break the loop once you find zinput.
- don't forget to close the file, when you are done.
The algorithm is really simple:
1) file object is an iterable, read it line by line.
2) If a line contains your zinput, print it.
Code:
file = open("file.txt", 'r')
zinput = str(input("Enter the word you want me to search: "))
for line in file:
if zinput in line:
print line
break
file.close()
Optionally, you can use with to make things easier and shorter. It will close the file for you.
Code:
zinput = str(input("Enter the word you want me to search: "))
with open("file.txt", 'r') as file:
for line in file:
if zinput in line:
print line
break
read()from file and then usingreadline()in loop which basically overwrites the user input.zinputfrom the input call with every line in the data.