title: Writing 8 bit values to a binary file in python v3.3
body: <p>Please let me know the best way to write 8bit values to a file in python.  The values can be between 0 and 255.
  I open the file as follows:</p>
  
  <pre><code>f = open('temp', 'wb')
  </code></pre>
  
  <p>Assume the value I am writing is an int between 0 and 255 assigned to a variable, e.g.</p>
  
  <pre><code>x = 13
  </code></pre>
  
  <p>This does not work:</p>
  
  <pre><code>f.write(x)
  </code></pre>
  
  <p>..as you experts know does not work.  python complains about not being able to write ints to buffer interface.  As a work around I am writing it as a hex digit.  Thus:</p>
  
  <pre><code>f.write(hex(x))
  </code></pre>
  
  <p>..and that works but is not only space inefficient but clearly not the right python way.  Please help. Thanks.</p>