title: Writing a line between lines
body: <p>I am writing a script where I have to insert a line between two lines. For example:</p>
  
  <pre><code>&lt;tag1&gt;
      &lt;subtag1&gt;     
             Line 1 - with some text 
             Line 2 - with some text
      &lt;/subtag&gt; - #closing of subtag
  
  **--&gt; here i have (between closure of subtag and tag1) to insert a new tag (3 lines, opening tag, body and closing tag)**
  
  &lt;/tag1&gt;
  </code></pre>
  
  <p>I am trying the below-mentioned code, but I am not able to write anything in the file.</p>
  
  <pre><code> with open ('abc.xml' , "r+") as f:
       for line in f:
           if '&lt;/subtag&gt;' in line:
               f.write('\n text1\n')
               f.write('text2')
               f.write('text3')
  </code></pre>
  
  <p>Can somebody please let me know where in the above code I am doing it wrong, or any other idea to write a code for inserting a line between two lines in a file in python?</p>