Does hashlib support a file mode?
Mel
mwilson at the-wire.com
Wed Jul 6 15:43:36 EDT 2011
Phlip wrote:
> If I call m = md5() twice, I expect two objects.
>
> I am now aware that Python bends the definition of "call" based on
> where the line occurs. Principle of least surprise.
Actually, in
def file_to_hash(path, m = hashlib.md5()):
hashlib.md5 *is* called once; that is when the def statement is executed.
Later on, when file_to_hash gets called, the value of m is either used as
is, as the default parameter, or is replaced for the duration of the call by
another object supplied by the caller.
Mel.
More information about the Python-list
mailing list