【问题标题】:How to compare two binary files or sets of files and displays the differences between them in Python?如何比较两个二进制文件或文件集并在 Python 中显示它们之间的差异?
【发布时间】:2020-10-07 01:55:18
【问题描述】:

我有两个文本文件,想比较它们以便在单独的文件中写入比较报告,就像我们在批处理脚本中使用命令得到的一样

fc /B file1.txt file2.txt > result.txt

我尝试使用filecmp.cmp('file1.txt','file2.txt'),但这会返回布尔值。 这样做的正确方法是什么?

【问题讨论】:

    标签: python file batch-file binary compare


    【解决方案1】:

    看看 difflib。 https://docs.python.org/3/library/difflib.html

    它是为此而设计的,difflib.context_diff 应该是您正在寻找的东西。

    【讨论】:

    • 我尝试使用它,但这并没有给我输出作为摘要。
    • 好的,您能否编辑您的问题,以便我们知道您希望看到什么?现在,真的很难说你期望什么样的输出......
    猜你喜欢
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多