title: writing unicode to binary file in python
body: <p>I'm wondering how to write unicode (utf-8) to a binary file.  Here's the background: I've got a 40 byte header (10 ints), and a table with a variable number of triple-int structs.  Writing these was cake.  </p>
  
  <p>Now, I want to add a bunch of strings to the end of the file.  </p>
  
  <p>Writing regular ASCII based strings is easy:</p>
  
  <pre><code>value = ('ab')
  s = struct.Struct('2s')
  packed_data = s.pack(value)
  </code></pre>
  
  <p>I learned how to do this from the <a href="http://docs.python.org/library/struct.html" rel="nofollow">Interpret strings as packed binary data</a>.  </p>
  
  <p>But is there a way to do this for unicode (utf-8) based strings?</p>
  
  <p>Any ideas?  Has anyone done this before?</p>