I was trying to write a small program to get the checksums of some files. Using the code mentioned over here, I made this:
import hashlib
import sys
from functools import partial
def md5sum(filename):
with open(filename, mode='rb') as f:
d = hashlib.md5()
for buf in iter(partial(f.read, 128), b''):
d.update(buf)
return d.hexdigest()
print(md5sum(sys.argv[0]))
That code works fine. However, when I try adding SHA1 support like so:
import hashlib
import sys
from functools import partial
def md5sum(filename):
with open(filename, mode='rb') as f:
d = hashlib.md5()
for buf in iter(partial(f.read, 128), b''):
d.update(buf)
return d.hexdigest()
def sha1sum(filename):
with open(filename, mode='rb') as f:
d = hashlib.sha1()
for buf in iter(partial(f.read, 128), b''):
d.update(buf)
return d.hexdigest()
if sys.argv[0] == 'md5':
print(md5sum(sys.argv[1]))
elif sys.argv[0] == 'sha1':
print(sha1sum(sys.argv[1]))
it stops printing the output (for both MD5 and SHA1). What am I doing wrong here?