• <small id='TnEwp'></small><noframes id='TnEwp'>

    • <bdo id='TnEwp'></bdo><ul id='TnEwp'></ul>
  • <tfoot id='TnEwp'></tfoot>
  • <legend id='TnEwp'><style id='TnEwp'><dir id='TnEwp'><q id='TnEwp'></q></dir></style></legend>

  • <i id='TnEwp'><tr id='TnEwp'><dt id='TnEwp'><q id='TnEwp'><span id='TnEwp'><b id='TnEwp'><form id='TnEwp'><ins id='TnEwp'></ins><ul id='TnEwp'></ul><sub id='TnEwp'></sub></form><legend id='TnEwp'></legend><bdo id='TnEwp'><pre id='TnEwp'><center id='TnEwp'></center></pre></bdo></b><th id='TnEwp'></th></span></q></dt></tr></i><div id='TnEwp'><tfoot id='TnEwp'></tfoot><dl id='TnEwp'><fieldset id='TnEwp'></fieldset></dl></div>

        如何在Python中检测两个文件是否相同

        时间:2023-11-07
        • <bdo id='FTVpl'></bdo><ul id='FTVpl'></ul>

          <tfoot id='FTVpl'></tfoot>
          • <legend id='FTVpl'><style id='FTVpl'><dir id='FTVpl'><q id='FTVpl'></q></dir></style></legend>

            <small id='FTVpl'></small><noframes id='FTVpl'>

                  <tbody id='FTVpl'></tbody>

                1. <i id='FTVpl'><tr id='FTVpl'><dt id='FTVpl'><q id='FTVpl'><span id='FTVpl'><b id='FTVpl'><form id='FTVpl'><ins id='FTVpl'></ins><ul id='FTVpl'></ul><sub id='FTVpl'></sub></form><legend id='FTVpl'></legend><bdo id='FTVpl'><pre id='FTVpl'><center id='FTVpl'></center></pre></bdo></b><th id='FTVpl'></th></span></q></dt></tr></i><div id='FTVpl'><tfoot id='FTVpl'></tfoot><dl id='FTVpl'><fieldset id='FTVpl'></fieldset></dl></div>
                  本文介绍了如何在Python中检测两个文件是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在这种情况下对md5sum file1"和md5sum file2"进行系统调用并比较两个返回值是否足够?

                  Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?

                  推荐答案

                  好吧,这将告诉您它们是绝对不同还是可能相同.可能两个文件具有相同的散列但实际上不具有相同的数据...只是不太可能.

                  Well, that will tell you whether they're definitely different or probably the same. It's possible for two files to have the same hash but not actually have the same data... just very unlikely.

                  在您的情况下,如果您得到误报(即,如果您认为它们相同,但事实并非如此),会有什么影响?如果冲突只会意外发生,MD5 可能就足够了,不用担心冲突......但如果你的安全(或金钱)处于危险之中,并且有人可能会用与好"文件相同的哈希,你不应该依赖它.

                  In your situation, what is the impact if you get a false positive (i.e. if you think they're the same, but they're not)? MD5 is probably good enough not to worry about collisions if they would only occur accidentally... but if you've got security (or money) at stake and someone could plant a "bad" file with the same hash as a "good" file, you shouldn't rely on it.

                  就个人而言,我可能只是读取两个文件,比较每个字节 - 对于一次性比较,散列和这种方法都需要在它们相等时读取整个文件;正如丹尼尔在评论中指出的那样,进行逐字节比较可以让您在看到差异时尽早退出.首先比较文件大小是另一个快速优化:)

                  Personally, I'd probably just read both files, comparing each byte - for a one off comparison, both the hashing and this approach will require reading the whole file when they're equal; as Daniel points out in the comments, doing a byte-by-byte comparison lets you exit early as soon as you see a difference. Comparing the file sizes first is another quick optimization :)

                  当您将现有文件的哈希存储在某处时,哈希的一般优势就会出现,这样下次您可以只需读取新文件.

                  The general advantage of hashing occurs when you store the hash of the existing file somewhere, so that next time you can just read the new file.

                  这篇关于如何在Python中检测两个文件是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在性能方面比较 python 函数? 下一篇:python中的字符串比较但不是Levenshtein距离(我认为)

                  相关文章

                  • <bdo id='V9pQ4'></bdo><ul id='V9pQ4'></ul>
                2. <tfoot id='V9pQ4'></tfoot>

                    <i id='V9pQ4'><tr id='V9pQ4'><dt id='V9pQ4'><q id='V9pQ4'><span id='V9pQ4'><b id='V9pQ4'><form id='V9pQ4'><ins id='V9pQ4'></ins><ul id='V9pQ4'></ul><sub id='V9pQ4'></sub></form><legend id='V9pQ4'></legend><bdo id='V9pQ4'><pre id='V9pQ4'><center id='V9pQ4'></center></pre></bdo></b><th id='V9pQ4'></th></span></q></dt></tr></i><div id='V9pQ4'><tfoot id='V9pQ4'></tfoot><dl id='V9pQ4'><fieldset id='V9pQ4'></fieldset></dl></div>
                    1. <legend id='V9pQ4'><style id='V9pQ4'><dir id='V9pQ4'><q id='V9pQ4'></q></dir></style></legend>

                      <small id='V9pQ4'></small><noframes id='V9pQ4'>