title: Create a file from its binary value in python
body: <p>I've created a script which allows me to read the binary representation of a whole file, yet I couldn't find a way to write the binary stream back to a file using python.</p>
  
  <p>The code I'm using to get the binary value is the following:</p>
  
  <pre><code> fileBin = ""
   bytes = bytearray(open(file, "rb").read())
   for i in range(0, len(bytes)):
       fileBin = fileBin + str(('{:08b}'.format(bytes[i])))
   return fileBin
  </code></pre>