I have one question because I can not find a solution for my problem.
gen is a generator (result of difflib.Differ.compare()):
normally by iterating over gen I can read each line. The problem is that on each iteration I need to read the current line and the two next lines.
Example (normal output by iterating line by line):
iteration 1:
line = 'a'
iteration 2:
line = 'b'
iteration 3:
line = 'c'
iteration 4:
line = 'd'
iteration 5:
line = 'e'
iteration 6:
line = 'f'
iteration 7:
line = 'g'
but in my case I need to get this:
iteration 1:
line = 'a'
next1 = 'b'
next2 = 'c'
iteration 2:
line = 'b'
next1 = 'c'
next2 = 'd'
iteration 3:
line = 'c'
next1 = 'd'
next2 = 'e'
iteration 4:
line = 'd'
next1 = 'e'
next2 = 'f'
iteration 5:
line = 'e'
next1 = 'f'
next2 = 'g'
iteration 6:
line = 'f'
next1 = 'g'
next2 = None
iteration 7:
line = 'g'
next1 = None
next2 = None
I was trying to play with gen.send(), itertools.islice(), but I can not find the proper solution. I don't want to convert this generator into a list (then I could read next1 as gen[i + 1], next2 as gen[i + 2], but this is totally inefficient when the diff output is large.