title: How to cast a string to bytes without encoding
body: <p>I have a bunch of binary data that comes to python via a char* from some C interface (not under my control) so I have a string of arbitrary binary data (what is normally a byte array). I would like to convert it to a byte array to simplify using it with other python functions but I can't seem to figure out how.</p>
  
  <p>Examples that don't work:</p>
  
  <p><code>data = rawdatastr.encode()</code> this assumes "utf-8" and mangles the data == BAD</p>
  
  <p><code>data = rawdatastr.encode('ascii','ignore')</code> strips chars over 127 == BAD</p>
  
  <p><code>data = rawdatastr.encode('latin1')</code> not sure -- this is the closest so far but I have no proof that it is working for all bytes.</p>
  
  <p><code>data = array.array('B', [x for x in map(ord,data)]).tobytes()</code> This works but seems like a lot of work to do something simple. Is there something simpler?</p>
  
  <p>I am thinking I need to write my own identity encoding that just passes the bytes along (I <em>think</em> latin1 does this based upon some reading but no proof thus far).</p>