Does hashlib support a file mode?
ethan at stoneleaf.us
Wed Jul 6 16:24:31 EDT 2011
>> On 2011.07.06 12:38 PM, Phlip wrote:
>>> 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.
> If I call m = md5() twice, I expect two objects.
You didn't call md5 twice -- you called it once when you defined the
Phlips naive code:
def file_to_hash(path, m = hashlib.md5()):
happens once, when
def line is executed
If you want separate md5 objects, don't create just one when you create
the function, create one inside the function:
def file_to_hash(path, m = None):
if m is None:
m = hashlib.md5()
You should try the Principle of Learning the Language.
More information about the Python-list