Hashing a file in Python
问题 I want python to read to the EOF so I can get an appropriate hash, whether it is sha1 or md5. Please help. Here is what I have so far: import hashlib inputFile = raw_input("Enter the name of the file:") openedFile = open(inputFile) readFile = openedFile.read() md5Hash = hashlib.md5(readFile) md5Hashed = md5Hash.hexdigest() sha1Hash = hashlib.sha1(readFile) sha1Hashed = sha1Hash.hexdigest() print "File Name: %s" % inputFile print "MD5: %r" % md5Hashed print "SHA1: %r" % sha1Hashed 回答1: TL;DR