title: Tried 'a+' to read and append at the same time but didn't work
body: <p>These are the contents of the <code>contacts.txt</code> file:</p>
  <blockquote>
  <p>foo 69</p>
  <p>bar 70</p>
  <p>baz 71</p>
  </blockquote>
  <p>I want to delete &quot;foo 69&quot; and this is what I did:</p>
  <pre><code>with open('contacts.txt','a+') as f:
      for line in f:
          with open('contacts.txt','a+') as f:
              if &quot;foo&quot; in line:
                  line.replace(&quot;foo&quot;, &quot;&quot;)
  </code></pre>
  <p>It did not do anything.</p>