sys.argv[0]
is the name of the script; command line arguments are stored in sys.argv[1:]
. You probably wanted to test sys.argv[1]
instead:
if sys.argv[1] == 'md5':
print(md5sum(sys.argv[2]))
elif sys.argv[1] == 'sha1':
print(sha1sum(sys.argv[2]))
Note that your original 'working' version only ever calculated the MD5 hash of the script itself.