[Tutor] Different md5 values for files under Unix and Python?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon Jan 19 02:01:36 EST 2004
On Mon, 19 Jan 2004, jb wrote:
> > os.popen("md5 filename") and hash.update("filename"); digest=hash.digest()
> >
> > and I can't figure out what I'm doing wrong. The two md5's should
> > produce the same hash, right?
>
> hash = md5.md5()
> hash.update("filename")
> hash.hexdigest()
>
> will return the md5 hash of the string 'filename'.
>
> what you want to do is something like
>
> a.update(open('filename').read()), which will read the entire file in a
> string
And make sure the file is being opened in 'binary mode':
a.update(open('filename').read('rb'))
This is to ensure that the operating system doesn't try to misguidedly do
newline/carriage return conversions.
More information about the Tutor
mailing list