title: Unpacking "0xff" vs. "\xff"
body: <p>I'm trying to read the binary data from a wavefile using the wave library.  The data is read and reported as string literals of the form '\x0f\x06\x0a...' and I would like to convert hexadecimal numbers to integers (you know, in base ten).  The problem I'm having is that these strings aren't really being treating as hex numbers, but sort of like unicode characters.</p>
  
  <pre><code>import wave
  import struct
  
  path="C:\\directory\\file.wav"
  
  file=wave.open(path,'r')
  data=file.readframes(10)
  
  print repr(data)
  </code></pre>
  
  <p>'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'</p>
  
  <pre><code>int_dat=struct.unpack('10i',data)
  </code></pre>
  
  <p>The error that comes up when I try something like</p>
  
  <pre><code>struct.unpack('i','\xff')
  </code></pre>
  
  <p>is that struct.unpack is expecting a string of length 4, and is only receiving a string of length 1.  It's clear to me why that's happening, but is there a format option for unpack that will allow me to unpack '\xff'?</p>
  
  <pre><code>struct.unpack('i','0xff')
  </code></pre>
  
  <p>Obviously works fine.  Similarly</p>
  
  <pre><code>struct.unpack('i',r'\xff')
  </code></pre>
  
  <p>works.</p>
  
  <p>Alternatively, is there a convenient to convert a string that looks like '\xff\x01\x63...'
  to either a raw string (though I'm not sure that makes sense since the "\x" is being treated as an escape character (is that the right term?) and not a character), or to the form '0xff0x010x63'.</p>