md5 from python different then md5 from command line

Paul Rubin http
Sun May 7 14:56:47 EDT 2006


John Salerno <johnjsal at NOSPAMgmail.com> writes:
> Just a quick md5-related follow-up question: I was experimenting with
> it and making md5 sums for strings, but how do you use the md5 module
> to create a sum for an actual file, such as an .exe file?

m = md5.new()
f = file('foo.exe', 'b')  # open in binary mode
while True:
   t = f.read(1024)
   if len(t) == 0: break    # end of file
   m.update(t)
print m.hexdigest()



More information about the Python-list mailing list