0

I have two log files that I am trying to compare, in bash:

$ diff logfile_56.log logfile_57.log

returns nothing.

However, when I do the following with difflib.ndiff I get the following:

import difflib

with ('logfile_56.log', 'r') as file_one:
    content_one = file_one.readlines()

with ('logfile_57.log', 'r') as file_two:
    content_two = file_two.readlines()

delta = difflib.ndiff(content_one, content_two)

if len(list(delta)) == 0:
    print('Diff exists!')

This shows me that a diff exists, even when there isn't one. Although I see no '+' or '-' in the output and just the content of logfile_57.log instead. How should I be successfully detecting whether a diff exists or not? I can check the delta variable for + or - but, it is likely that the contents of either of these files would contain those characters anyway.

I'd like to use ndiff because the output when a diff does exist is something that works perfectly for my use case.

Am I doing something wrong?

readytotaste
  • 199
  • 2
  • 4
  • 17
  • Do the files end with a newline? If they don't then they are treated as binary files and diff does not work. – cup Sep 18 '19 at 04:50

1 Answers1

0

I have a feeling that zero-sized list of the differences means THERE ARE NO DIFFERENCES!

if len(list(delta)) == 0:
    print('Diff exists!')

Maybe if you replace == with != ...

lenik
  • 23,228
  • 4
  • 34
  • 43