So I have written a binary file, and I am attempting to get the checksum of the File. I am not sure whether I am understanding the hashlib library fully, or whether I am understanding exactly how to implement it. Here is what I have, in Python 2.7:
def writefile(self, outputFile): outputFile = open(outputFile, 'wb+') for par in self.fileformat.pList: if par.name.lower() in self.calculated.final.keys(): outputFile.write(self.calculated.final[par.name.lower()]) else: outputFile.write(self.defaults.defaultValues[par.name.upper()]) outputFile.close() with open(outputFile, 'rb') as fh: m = hashlib.md5() while True: data = fh.read(8192) if not data: break m.update(data) print m.digest() outputFile.close() what I keep getting is :
TypeError: coercing to Unicode: need string or buffer, file found any help would be appreciated, because I could be headed in the completely wrong direction.
outputFile.close()at the end if you usewith. That's what it's for.