title: Delete final line in file with python
body: <p>How can one delete the very last line of a file with python?</p>
  <p>Input File example:</p>
  <pre><code>hello
  world
  foo
  bar
  </code></pre>
  <p>Output File example:</p>
  <pre><code>hello
  world
  foo
  </code></pre>
  <p>I've created the following code to find the number of lines in the file - but I do not know how to delete the specific line number.</p>
  <pre><code>    try:
          file = open(&quot;file&quot;)
      except IOError:
          print &quot;Failed to read file.&quot;
      countLines = len(file.readlines())
  </code></pre>