def are_files_identical(filename1, filename2, debug=False):
 with open(filename1, 'rb') as fileA:
  with open(filename2, 'rb') as fileB:
   result = True
   for (lineA, lineB) in izip(sorted(fileA.readlines()), sorted(fileB.readlines())):
    if (lineA.strip() != lineB.strip()):
     if debug:
      print ('Error while comparing files. ' + 'First difference at line below.')
      print '=> Output file line: {0}'.format(lineA)
      print '=> Refer. file line: {0}'.format(lineB)
     result = False
     break
   return result

def are_files_identical ( filename1 , filename2 , debug = False ) : with open ( filename1 , 'rb' ) as fileA : with open ( filename2 , 'rb' ) as fileB : result = True for ( lineA , lineB ) in izip ( sorted ( fileA . readlines ( ) ) , sorted ( fileB . readlines ( ) ) ) : if ( lineA . strip ( ) != lineB . strip ( ) ) : if debug : print ( 'Error while comparing files. ' + 'First difference at line below.' ) print '=> Output file line: {0}' . format ( lineA ) print '=> Refer. file line: {0}' . format ( lineB ) result = False break return result
compare two files .