title: Python - separating individual lines in a paragraph from a text file
body: <p>I have a text file which contains the following paragraph:</p>
  
  <p>The above with statement will automatically close the file after the nested block of code. The above with statement will automatically close the file after the nested block of code. The above with statement will automatically close the file after the nested block of code.<br>
  The above with statement will automatically close the file after the nested block of code without.</p>
  
  <p>Now, I would like to modify the file by separating the individual lines for the paragraph, and save it in the same text file as the following:</p>
  
  <p>The above with statement will automatically close the file after the nested block of code.<br>
  The above with statement will automatically close the file after the nested block of code.<br>
  The above with statement will automatically close the file after the nested block of code.<br>
  The above with statement will automatically close the file after the nested block of code without.</p>
  
  <p>I was able to do it, but it was bit complicated. My code is as follows:</p>
  
  <p><strong>try-1</strong></p>
  
  <pre><code>file = open("file_path")
  content = file.read()
  file.close()
  file = open("file_path", 'w')
  a = content.replace('. ', '.\n')
  file.write(a)
  file.close()
  </code></pre>
  
  <p><strong>try-2</strong></p>
  
  <pre><code>file = open("file_path")
  contents = file.readlines()
  file.close()
  b = []
  for line in contents:
      if not line.strip():
          continue
      else:
          b.append(line)
  b = "".join(b)
  file = open("file_path", 'w')
  file.write(b)
  file.close()
  </code></pre>
  
  <p>I opened the file twice to read and twice to write, is there any better way to separate the line from a paragraph from a text file, and writing it to the same text file?</p>