title: How could I convert a bytes to a whole hex string?
body: <pre><code>a1 = b'\x01\x02\x41'
  </code></pre>
  
  <p><code>\x41</code> is <code>A</code></p>
  
  <p>and when I print <code>str(a1)</code>, I get</p>
  
  <pre><code>b'\x01\x02A'
  </code></pre>
  
  <p>how could I get the original hex string?</p>
  
  <p>I want to get:</p>
  
  <pre><code>\x01\x02\x41
  </code></pre>
  
  <p>I use this string for <code>redis-cli --pipe</code>.</p>
  
  <p>I don't want python to print the converted string for me.</p>
  
  <p>How could I do it?</p>
  
  <p>now I do like this:</p>
  
  <pre><code>def convert(i:bytes):
      result = list()
      for j in i:
          result.append('\\x%s' % bytes([j]).hex())
      return ''.join(result)
  </code></pre>
  
  <p>It is too ugly.
  Is there a better way?</p>
  
  <p>btw.</p>
  
  <p>This is my redis-cli --pipe script:</p>
  
  <pre><code>SET "\xda\xb8\xe6\xc0\x79\x62\xea\x06\xde\x9e\xb0\x4e\x68\xde\x0b\x62" "\x00\x42\xdc\x06\x03\x00\x00\x00"
  SET "\x68\xfa\xfc\x03\x36\x99\xb0\x56\xb4\x00\xaf\x61\x42\xe0\x30\x42" "\x01\x42\xdc\x06\x03\x00\x00\x00"
  SET "\x40\x98\xb9\x8f\xd8\x4e\x2e\x32\x40\x09\xca\xa4\x55\x52\xde\x7f" "\x02\x42\xdc\x06\x03\x00\x00\x00"
  SET "\xd0\x75\xdf\x46\x36\xd0\xb4\xed\xcc\xed\xd6\x27\xf7\xd9\xc5\xa5" "\x03\x42\xdc\x06\x03\x00\x00\x00"
  </code></pre>
  
  <p>I use it this way:</p>
  
  <pre><code>cat sample.redis | redis-cli --pipe
  </code></pre>