title: How do I write raw binary data in Python?
body: <p>I've got a Python program that stores and writes data to a file.  The data is raw binary data, stored internally as <code>str</code>.  I'm writing it out through a utf-8 codec.  However, I get <code>UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 25: character maps to &lt;undefined&gt;</code> in the <code>cp1252.py</code> file.</p>
  
  <p>This looks to me like Python is trying to interpret the data using the default code page.  But it doesn't <em>have</em> a default code page.  That's why I'm using <code>str</code>, not <code>unicode</code>.</p>
  
  <p>I guess my questions are:</p>
  
  <ul>
  <li>How do I represent raw binary data in memory, in Python?</li>
  <li>When I'm writing raw binary data out through a codec, how do I encode/unencode it?</li>
  </ul>