[英]How to compare two binary files or sets of files and displays the differences between them in Python?
I have two text files and want to compare them in order to write the comparison report in the seperate file, like what we get in Batch script with the command我有两个文本文件,想比较它们以便在单独的文件中编写比较报告,就像我们在批处理脚本中使用命令一样
fc /B file1.txt file2.txt > result.txt
. fc /B file1.txt file2.txt > result.txt
。
I tried using the filecmp.cmp('file1.txt','file2.txt')
, but this is returning me the Boolean value.我尝试使用
filecmp.cmp('file1.txt','file2.txt')
,但这返回了 Boolean 值。 What is the correct method to do this?这样做的正确方法是什么?
Take a look at difflib.看看 difflib。 https://docs.python.org/3/library/difflib.html
https://docs.python.org/3/library/difflib.html
It's meant for this and difflib.context_diff
should be what you're looking for.它是为此而设计的,
difflib.context_diff
应该是您正在寻找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.