title: Searching and replacing in binary file
body: <p>First of all, I tried these questions and didn't work for me:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3162614/python-search-and-replace-in-binary-file">Python search and replace in binary file</a>   </li>
  <li><a href="https://stackoverflow.com/questions/6621280/python-re-module-to-replace-the-binary-data-inside-a-text-file">python re module to replace the binary data inside a text file?</a></li>
  </ul>
  
  <p>I'm working in manipulating a pdf file in binary.  I need to replace a string by other.</p>
  
  <p>This is my approach:</p>
  
  <pre><code>#!/usr/bin/python3
  # -*- coding: UTF-8 -*-
  
  with open("proof.pdf", "rb") as input_file:
      content = input_file.read()
      if b"21.8182 686.182 261.818 770.182" in content:
          print("FOUND!!")
      content.replace(b"21.8182 686.182 261.818 770.182", b"1.1 1.1 1.1 1.1")
      if b"1.1 1.1 1.1 1.1" in content:
          print("REPLACED!!")
  
  with open("proof_output.pdf", "wb") as output_file:
      output_file.write(content)
  </code></pre>
  
  <p>When I run the script it shows "FOUND!!", but not "REPLACED!!"</p>