Apr-23-2020, 07:20 PM
(This post was last modified: Apr-23-2020, 07:20 PM by deanhystad.)
f_toread = 'C:\\02\mytext.txt' lstr = '-- InitializeRequest' lstart = "LotComplete" last_lstart = None last_lstr = None with open(f_toread) as fp: line = fp.readline() print (line) # Do not print here. cnt = 1 flag = False while line: if lstart in line: # Did I find a pair? if last_lstart is not None and last_lstr is not None: # I found a pair! print(last_lstart, last_str) # Here is where you print your pair last_lstart = cnt # Indent was wrong last_lstr = None elif lstr in line: last_lstr = cnt cnt += 1 line = fp.readline()