Home >Backend Development >Python Tutorial >Python基于checksum计算文件是否相同的方法

Python基于checksum计算文件是否相同的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:13:091907browse

本文实例讲述了Python基于checksum计算文件是否相同的方法。分享给大家供大家参考。具体如下:

假设有2个二进制文件(0.bin, 1.bin),用checksum检验内容是否相同

# coding: utf8
# Python2.6.2
import md5
with open('0.bin', 'rb') as f:
  s = md5.new(f.read()).hexdigest()
with open('1.bin', 'rb') as f:
  ss = md5.new(f.read()).hexdigest()
print repr(s), len(s)
print repr(ss), len(ss)

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn