python-workout
python-workout copied to clipboard
e21b1_md5_files.py (calculate the MD5 hash for the contents of every file)
I think you are calculating the MD5 of the filename string... not of the content of the file...
for one_filename in glob.glob(f'{dirname}/*'):
try:
m = hashlib.md5()
m.update(one_filename.encode())
output[one_filename] = m.hexdigest()
except:
pass
Perhaps...
for one_filename in glob.glob(f'{dirname}/*'):
try:
with open(one_filename, 'rb') as file:
data = file.read()
output[one_filename] = hashlib.md5(data).hexdigest()
except:
pass