Jan-21-2024, 09:30 PM
Apologies in advance for something that I'm sure you all have encountered before - but I cant find an answer!
The following code happily writes each line as a newline in the output file, unless the difference found is on the last line(I'm using difflib.Differ).
Hope you can see but the final '? ^' of each input file should be on a newline. I did try adding a newline (\n) to my write statement, but that just inserted every other line as spaces in the output
I'm sure there are many other ways to do this, but I'm just looking to understand what is the cause of the issue and the resolution - I suppose I could test if its the last record in the file and treat it differently, but that seems a bit rubbish.
? ^
+ dhj22
? ^
- d23y
? -
- aaaad34? ^
+ aabad34? ^
The following code happily writes each line as a newline in the output file, unless the difference found is on the last line(I'm using difflib.Differ).
Hope you can see but the final '? ^' of each input file should be on a newline. I did try adding a newline (\n) to my write statement, but that just inserted every other line as spaces in the output
I'm sure there are many other ways to do this, but I'm just looking to understand what is the cause of the issue and the resolution - I suppose I could test if its the last record in the file and treat it differently, but that seems a bit rubbish.
for line in difference.compare(a, b): f3.write(line)- dhx22
? ^
+ dhj22
? ^
- d23y
? -
- aaaad34? ^
+ aabad34? ^