title: Python program to delete a specific line in a text file
body: <p>I have a text file Thailand_Rectangle2_National Parks.txt with the following lines. </p>
  
  <pre><code>1
  2
  3
  4
  5
  dy 0.5965
  7
  </code></pre>
  
  <p>Now, I want to delete the 6th line in this text file. </p>
  
  <p>For that, I am using the following python code. </p>
  
  <pre><code>f = open("C:/Users/Sreeraj/Desktop/Thailand_Rectangle2_National Parks.txt","r")
  lines = f.readlines()
  </code></pre>
  
  <p>So, I saved all the lines of this text file in 'lines'. </p>
  
  <pre><code>line6 = lines[5]
  t = line6[:2]
  f.close() 
  </code></pre>
  
  <p>So, now, I have 't' = "dy" . Now, </p>
  
  <pre><code>if t == "dy":
      f = open("C:/Users/Sreeraj/Desktop/Thailand_Rectangle2_National Parks.txt","w")
      for line in lines:
          if lines[5] != line6:
              f.write(line)
  
  f.close()
  </code></pre>
  
  <p>So, if the condition 't' = "dy" satisfies, then I will open this text file for writing and I will print all the lines except line6 (which means line6 is deleted from this text file). </p>
  
  <p>Unfortunately, I am getting the lines in this text file as blank, which means no lines are printed as outputs. </p>
  
  <p>But, I want the lines in the text file as given below. </p>
  
  <pre><code>1
  2
  3
  4
  5
  7
  </code></pre>
  
  <p>How can I solve this issue ? </p>
  
  <p>I want to use only Python programming to solve this issue; since this is a small task of a major work. </p>