I am using linecache to get the lines before the occurrence of a string. But it is not working. I cannot understand what the problem is?
with open(fileName, 'r') as inFile:
between = False
for num, line in enumerate(inFile, 1):
if st_time in line:
between = True
if between:
if 'Broken pipe' in line:
line1 = linecache.getline(fileName, num-55)
if 'ERROR' in line1:
print("yes")
if en_time in line:
between = False
It was the problem one of you mentioned. Linecache won't store the entire lines, it will only store the line specified. For example line1 = linecache.getline(fileName, num - 22) will store only the (num -22)th line. I thought it would store till the (num-22)th line.