title: python 3: string to hex, hex to format
body: <p>Question: I need to convert a string into hex and then format the hex output.</p>
  
  <pre><code>tmp = b"test"
  test = binascii.hexlify(tmp)
  print(test) 
  </code></pre>
  
  <p>output: b'74657374'</p>
  
  <hr>
  
  <p>I want to format this hex output to look like this: 74:65:73:74 </p>
  
  <p>I have hit a road block and not sure where to start. I did think of converting the output to a string again and then trying to format it but there must be an easier way.</p>
  
  <p>Any help would be appreciated, thanks.</p>
  
  <p>==========</p>
  
  <p>OS: Windows 7</p>
  
  <pre><code>tmp = "test"
  hex = str(binascii.hexlify(tmp), 'ascii')
  print(hex)
  
  formatted_hex = ':'.join(hex[i:i+2] for i in range(0, len(hex), 2))
  print(formatted_hex
  </code></pre>
  
  <p>[Error]
  Traceback (most recent call last):
    File "C:\pkg\scripts\Hex\hex.py", line 24, in 
      hex = str(binascii.hexlify(tmp), 'ascii')
   TypeError: 'str' does not support the buffer interface</p>
  
  <p>This code only works when using tmp = b'test' I need be able use tmp = importString in fashion as I'm passing another value to it from a file order for my snippet to work. Any thoughts?</p>