title: Python writing a long int as a binary value to a file
body: <p>I have been trying to take a long int (m39 prime) and store it as a binary file.
  When I attempt to write the bin value to a file it is written as a string.</p>
  
  <pre><code>&gt;&gt;&gt; m39 = bin(2**13466917-1)
  &gt;&gt;&gt; open('m39', 'wb').write(m39) 
  madsc13ntist@jaberwock:~/Desktop$ xxd m39 | head
  0000000: 3062 3131 3131 3131 3131 3131 3131 3131  0b11111111111111
  0000010: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000020: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000030: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000040: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000050: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000060: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000070: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  0000080: 3131 3131 3131 3131 3131 3131 3131 3131  1111111111111111
  </code></pre>
  
  <p>I'm feeling pretty certain that there is a ridiculously simple answer to this but I haven't been successful at converting m39 into a bytearray or a buffer for writing.  Should I be using io or memoryview, etc.</p>
  
  <p>Many thanks in advance for any assistance anyone can provide. :)</p>
  
  <p>I am using Python 2.7.3 and I prefer to us builtin modules if at all possible.</p>
  
  <p>EDIT: I am attempting to store the value as a binary file which would occupy much less space on the disk/memory.  I understand that the bin type is a string in python but I am attempting to write <code>\x11\x11\x11\x11 not \x31\x31\x31\x31</code>.  My intent is not to print a string representation of the value, but to store it efficiently for later use/manipulation.</p>