I'm currently trying to write a program to read through a file, and print any lines that contain an "[ERROR]" or "statistics:" message. The program will work for finding error lines, but will not find any lines with statistics. The thing is that if I comment out the line that looks for error codes (using the same method), the statistics line works perfectly. This is Python 3.9.1 if that matters. Any thoughts?
def searchFor(word, f):
print("=" * 75)
print("Lines containing: ", word)
print("-" * 50)
lines = f.readlines()
for line in lines:
if word in line:
print(line)
print("=" * 75)
def main():
f = open("error_log.txt", "r")
searchFor("[error]", f)
searchFor("statistics:", f)
main()