new to python, help please !!
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Nov 11 21:58:35 EST 2015
On Thursday 12 November 2015 04:48, Quivis wrote:
> On Wed, 11 Nov 2015 08:34:30 -0800, Anas Belemlih wrote:
>
>> md5
>
> If those are md5 values stored inside files, wouldn't it be easier to
> just hash them?
>
> import hashlib
>
> m1 = hashlib.sha224(open('f1').read()).hexdigest()
> m2 = hashlib.sha224(open('f2').read()).hexdigest()
I presume that the purpose of the exercise is to learn basic Python skills
like looping.
Also, using sha224 when all you want is a simple "different"/"equal" is
horribly inefficient. Sha224 needs to read the entire file, every single
byte, *and* perform a bunch of expensive cryptographic operations. Consider
reading two five GB files, the first starting with byte \x30 and the second
starting with byte \x60. The two bytes are different, so we know the files
differ, but sha224 still needs to do a massive amount of work.
--
Steve
More information about the Python-list
mailing list