fork download
  1. import difflib
  2. import sys
  3. import os
  4.  
  5. input_file1 = '\\dir\\subdir\\application.properties'
  6. input_file2 = '\\dir\\application.properties'
  7.  
  8. output_file = str(input_file2[6:])
  9.  
  10. def get_difference(output, input_1, input_2):
  11. with open(os.getcwd() + input_1, 'r') as hosts0:
  12. with open(os.getcwd() + input_2, 'r') as hosts1:
  13. diff = difflib.unified_diff(
  14. hosts0.readlines(),
  15. hosts1.readlines(),
  16. fromfile='hosts0',
  17. tofile='hosts1',
  18. )
  19.  
  20. orig_stdout = sys.stdout
  21. f = file(output, 'w')
  22. sys.stdout = f
  23.  
  24. for line in diff:
  25. print line[1:].rstrip("\n")
  26.  
  27. sys.stdout = orig_stdout
  28. f.close()
  29.  
  30.  
  31. def delete_lines(filename):
  32. with open(str(filename), 'r') as fin:
  33. data = fin.read().splitlines(True)
  34. with open(str(filename), 'w') as fout:
  35. fout.writelines(data[3:])
  36.  
  37.  
  38. if __name__ == '__main__':
  39. get_difference(output_file, input_file1, input_file2)
  40. delete_lines(output_file)
  41.  
Runtime error #stdin #stdout #stderr 0.01s 9136KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 39, in <module>
  File "prog.py", line 11, in get_difference
IOError: [Errno 2] No such file or directory: '/home/nSDv6G\\dir\\subdir\\application.properties'