Python3 - How to convert a string to hex
<p>I am trying to convert a string to hex character by character, but I cant figure it out in Python3.</p>

<p>In older python versions, what I have below works:</p>

<pre><code>test = "This is a test"
for c in range(0, len(test) ):
   print( "0x%s"%string_value[i].encode("hex") )
</code></pre>

<p>But with python3 I am getting the following error: </p>

<p>LookupError: 'hex' is not a text encoding; use codecs.encode() to handle arbitrary codecs.</p>

<p>Can anyone help to tell me what the conversion would be in python3.</p>

<p>Thanks in advance</p>