title: Create file from bytes stored as string
body: <p>I have a use case where I am getting a blob back from the database which I have to convert to a binary file. Python stores this as a string although it is actually bytes. When I try to write as binary I get a Type Error, str not accepted.</p>
  
  <p>I wrote some sample code to reproduce what the variable looks like. I have seen sample code in other languages where this task is rather easy. Help in solving this problem using python 3 would be greatly appreciated. It is probably something very simple that I am missing and I was unable to find an answer online.</p>
  
  <pre><code>import binascii
  
  f = open('test.xlsx', 'rb')
  content = binascii.hexlify(f.read())
  f.close
  
  output = content.decode("utf-8")
  
  #output2 = hex(int(output, 16))
  
  f = open('temp', 'wb')
  f.write(output) #TypeError: a bytes-like object is required, not 'str' 
  f.close()
  
  #Convert back to type bytes and recreate the file
  </code></pre>