title: Converting 2.5 byte comparisons to 3
body: <p>I'm trying to convert a 2.5 program to 3.</p>
  
  <p>Is there a way in python 3 to change a byte string, such as b'\x01\x02' to a python 2.5 style string, such as '\x01\x02', so that string and byte-by-byte comparisons work similarly to 2.5? I'm reading the string from a binary file.</p>
  
  <p>I have a 2.5 program that reads bytes from a file, then compares or processes each byte or combination of bytes with specified constants. To run the program under 3, I'd like to avoid changing all my constants to bytes and byte strings ('\x01' to b'\x01'), then dealing with issues in 3 such as:</p>
  
  <pre><code>a = b'\x01'
  b = b'\x02'
  </code></pre>
  
  <p>results in</p>
  
  <pre><code>(a+b)[0] != a
  </code></pre>
  
  <p>even though similar operation work in 2.5. I have to do (a+b)[0] == ord(a), while a+b == b'\x01\x02' works fine. (By the way, what do I do to (a+b)[0] so it equals a?)</p>
  
  <p>Unpacking structures is also an issue.</p>
  
  <p>Am I missing something simple?</p>