IFRAME SYNC
import difflib
def compare_text_files(file1_path, file2_path):
with open(file1_path, 'r', encoding='utf-8') as file1, open(file2_path, 'r', encoding='utf-8') as file2:
text1 = file1.readlines()
text2 = file2.readlines()
d = difflib.Differ()
diff = list(d.compare(text1, text2))
for line in diff:
if line.startswith(' '):
continue
elif line.startswith('- '):
print(f"Line removed: {line[2:]}")
elif line.startswith('+ '):
print(f"Line added: {line[2:]}")
if __name__ == "__main__":
file1_path = "path/to/your/file1.txt"
file2_path = "path/to/your/file2.txt"
compare_text_files(file1_path, file2_path)import difflib
def compare_large_text_files(file1_path, file2_path):
chunk_size = 4096 # You can adjust the chunk size based on your needs
with open(file1_path, 'r', encoding='utf-8') as file1, open(file2_path, 'r', encoding='utf-8') as file2:
while True:
chunk1 = file1.read(chunk_size)
chunk2 = file2.read(chunk_size)
if not chunk1 and not chunk2:
break
d = difflib.Differ()
diff = list(d.compare(chunk1.splitlines(keepends=True), chunk2.splitlines(keepends=True)))
for line in diff:
if line.startswith(' '):
continue
elif line.startswith('- '):
print(f"Line removed: {line[2:]}")
elif line.startswith('+ '):
print(f"Line added: {line[2:]}")
if __name__ == "__main__":
file1_path = "path/to/your/large_file1.txt"
file2_path = "path/to/your/large_file2.txt"
compare_large_text_files(file1_path, file2_path)
IFRAME SYNC
Comments
Post a Comment