title: updating Multiple lines in the same time with Python
body: <pre><code>with open('G1.txt', 'r') as f:
      lines = f.readlines()
  
  with open('G1.txt', 'w') as f:
      for i,line in enumerate(lines):
          if i==10:
                 f.write ("in1  G  OP  RE 1* " + str(g)+ "3500  /"+ '\n')
                 f.write ("in2  G  OP  RE 1* " + str(g)+ "3500  /"+ '\n')
          elif i==20:
              f.write(str(t)+ "*31 /"+'\n')
  </code></pre>
  
  <p>I have multiple line update inside a big file, and some of those lines are multiple lines 
  Every time I run the code, it removes the first line only and add the new lines to it. The output looks like this </p>
  
  <pre><code>in1  W  OP  RE 1*  19000  3500  /
  in2  W  OP  RE 1*  19000  3500  /
  in2  W  OP  RE 1*  10000  3500  /
  10*31
  </code></pre>
  
  <p>In this example, you will see there is 2 in2 in the file. So, every time i run the code those lines will add up to each other. so instead of having 2 lines I might end up with extra 5 lines</p>
  
  <pre><code>Is there a way to remove the old second line and update it with the new one without repeating `elif i==` for every single line
  Because sometime I have to update 7 or ten new lines in the same section and for different sections 
  </code></pre>
  
  <p>Best Regards</p>