md5 from python different then md5 from command line
John Salerno
johnjsal at NOSPAMgmail.com
Sun May 7 19:09:59 EDT 2006
Paul Rubin wrote:
> 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()
Any reason you can't just read the whole file at once and update m?
Also, doesn't the parameter for update have to be a string? If you're
reading the file in binary mode, would t still be a string?
Thanks.
More information about the Python-list
mailing list