Does hashlib support a file mode?
Phlip
phlip2005 at gmail.com
Wed Jul 6 13:38:10 EDT 2011
> >> def file_to_hash(path, m=None):
> >> if m is None:
> >> m = hashlib.md5()
> The first call will give you the correct checksum, the second: not. As the
> default md5 instance remembers the state from the previous function call
> you'll get the checksum of both files combined.
Ouch. That was it.
Python sucks. m = md5() looks like an initial assignment, not a
special magic storage mode. Principle of least surprise fail, and
principle of most helpful default behavior fail.
More information about the Python-list
mailing list