[Tutor] trying to get md5sums of a list of files

Sean 'Shaleh' Perry shalehperry@comcast.net
Thu Jul 17 10:21:02 2003


> So I coded up the following:
>
> #!/usr/local/bin/python
>
> import os, sys, md5
>
> for path in open('filelist2'):
>         myline = path.strip()
>         f = open(myline, 'r')
>         m = md5.new()
>         for line in f.readlines():
>                 m.update(line)
>         f.close()
>         md5sum = m.digest()
>         print m
>
> However, the output does not make sense, where have I gone wrong?
>

you failed you read the docs fully (-:

`digest()'
     Return the digest of the strings passed to the `update()' method
     so far.  This is a 16-byte string which may contain non-ASCII
     characters, including null bytes.

`hexdigest()'
     Like `digest()' except the digest is returned as a string of
     length 32, containing only hexadecimal digits.  This may be used
     to exchange the value safely in email or other non-binary
     environments.

>>> import md5
>>> md5.new("Nobody inspects the spammish repetition").digest()
'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
>>> md5.new("Nobody inspects the spammish repetition").hexdigest()
'bb649c83dd1ea5c9d9dec9a18df0ffe9'