I've looked around, but can't figure out why my 3rd function, info_count(), is running on an infinite loop:
def error_statement():
errorLog = open("error_log.txt", "r")
for line in errorLog:
if "[error]" in line:
print(line)
def statistics_statement():
errorLog = open("error_log.txt", "r")
for line in errorLog:
if "statistics" in line:
print(line)
def info_count():
errorLog = open("error_log.txt", "r")
count = 0
for line in errorLog:
if "[info]" in line:
count += 1
print(count)
error_statement()
statistics_statement()
info_count()
The first two return the proper results and ends. But my count keeps looping and I don't see why it doesn't break at the end of the run.
In addition, once I get that count, I want to later print those lines out, but only a specific section ie the IP address, which may vary on each line that returns "[info]". Please advise.
info_count(), The print(count) is within the for loop. You might want to print the count outside the loop and then post a sample output?errorLog = open("error_log.txt", "r")towith open("error_log.txt", "r") as errorLog?