title: How to use the 'hex' encoding in Python 3.2 or higher?
body: <p>In Python 2, to get a string representation of the hexadecimal digits in a string, you could do</p>
  
  <pre><code>&gt;&gt;&gt; '\x12\x34\x56\x78'.encode('hex')
  '12345678'
  </code></pre>
  
  <p>In Python 3, that doesn't work anymore (tested on Python 3.2 and 3.3):</p>
  
  <pre><code>&gt;&gt;&gt; '\x12\x34\x56\x78'.encode('hex')
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  LookupError: unknown encoding: hex
  </code></pre>
  
  <p>There is at least <a href="https://stackoverflow.com/a/7795102/20670">one answer</a> here on SO that mentions that the <code>hex</code> codec has been removed in Python 3. But then, <a href="http://docs.python.org/py3k/library/codecs.html#standard-encodings" rel="noreferrer">according to the docs</a>, it was reintroduced in Python 3.2, as a "bytes-to-bytes mapping".</p>
  
  <p>However, I don't know how to get these "bytes-to-bytes mappings" to work:</p>
  
  <pre><code>&gt;&gt;&gt; b'\x12'.encode('hex')
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'bytes' object has no attribute 'encode'
  </code></pre>
  
  <p>And the docs don't mention that either (at least not where I looked). I must be missing something simple, but I can't see what it is.</p>