md5 for large files

Dave Brueck dave at pythonapocrypha.com
Tue Mar 4 14:13:10 EST 2003


On Tue, 4 Mar 2003, Bob Ballard wrote:

> Can someone provide me with a snippet or pointer to usinging Python to
> verify the md5 value for a large file?  All examples I've seen are for a
> small string.  I'm not yet using GPG for NT and I need to verify or generate
> md5 values for file xfers.

Hi Bob,

How about:

import md5
m = md5.new()
f = open('somefile','rb')
while 1:
  data = f.read(32768) # Read a block
  if not data: break
  m.update(data)
print m.digest()

-Dave





More information about the Python-list mailing list