title: hashlib.md5() TypeError: Unicode-objects must be encoded before hashing
body: <p>I am new to coding and have ran into a problem trying to encode a string.</p>
  
  <pre><code>&gt;&gt;&gt; import hashlib
  &gt;&gt;&gt; a = hashlib.md5()
  &gt;&gt;&gt; a.update('hi')
  Traceback (most recent call last):
    File "&lt;pyshell#22&gt;", line 1, in &lt;module&gt;
      a.update('hi')
  TypeError: Unicode-objects must be encoded before hashing
  &gt;&gt;&gt; a.digest()
  b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
  </code></pre>
  
  <p>Is (a) now considered to be encoded?</p>
  
  <p>Second question: When I run the same code above in a script I get this error:</p>
  
  <pre><code>import hashlib
  a = hashlib.md5()
  a.update('hi')
  a.digest()
  </code></pre>
  
  <p>Traceback (most recent call last):
    File "C:/Users/User/Desktop/Logger/Encoding practice.py", line 3, in 
      a.update('hi')
  TypeError: Unicode-objects must be encoded before hashing</p>
  
  <p>Why is the code working in the shell and not the script?
  I am working with Windows and Python 3.4</p>
  
  <p>Thanks.  </p>