Does hashlib support a file mode?
phlip2005 at gmail.com
Thu Jul 7 23:26:56 EDT 2011
> I worded that poorly. None is (AFAIK) the only instance of NoneType, but
> I should've clarified the difference.> The is operator does not compare types, it compares instances for identity.
None is typesafe, because it's strongly typed.
However, what's even MORE X-safe (for various values of X) is a method
that takes LESS for its arguments. That's why I switched from passing
an object to passing a type, because the more restrictive argument
type is more typesafe.
However, the MOST X-safe version so far simply passes a string, and
uses hashlib the way it designs to be used:
def file_to_hash(path, hash_type):
hash = hashlib.new(hash_type)
with open(path, 'rb') as f:
s = f.read(8192)
if not s: break
More information about the Python-list