main.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import difflib
  2. def are_files_identical(file1_path, file2_path):
  3. """Check if two files have the same contents."""
  4. with open(file1_path, 'r') as file1, open(file2_path, 'r') as file2:
  5. file1_contents = file1.read()
  6. file2_contents = file2.read()
  7. return file1_contents == file2_contents
  8. def show_file_differences(file1_path, file2_path):
  9. """Show differences between two files."""
  10. with open(file1_path, 'r') as file1, open(file2_path, 'r') as file2:
  11. file1_lines = file1.readlines()
  12. file2_lines = file2.readlines()
  13. diff = difflib.unified_diff(file1_lines, file2_lines, fromfile='file1', tofile='file2')
  14. return ''.join(diff)
  15. # Example usage
  16. file1_path = "./examples/BouncingBalls/Python/output.txt"
  17. file2_path = "./examples/BouncingBalls/PyDEVS/output.txt"
  18. if are_files_identical(file1_path, file2_path):
  19. print("The files are identical.")
  20. else:
  21. print("The files are different. Here are the differences:")
  22. differences = show_file_differences(file1_path, file2_path)
  23. print(differences)