I am new to coding and have ran into a problem trying to encode a string.
>>> import hashlib
>>> a = hashlib.md5()
>>> a.update(\'
Since you are encoding simple strings I deduce that you are running Python 3 where all strings are unicode objects, you have two options:
"Nobody inspects".encode('utf-8')
Use binary strings as shown in the manuals:
m.update(b"Nobody inspects")
m.update(b" the spammish repetition")
The reason for the differing behaviour in the script to the shell is that the script stops on the error whereas in the shell the last line is a separate command but still not doing what you wish it to because of the previous error.