title: How to replace the last line ina text file?
body: <p>I have a program that runs twice a day however I am rewriting it as I'm making a new update for my program. I'm running into a problem. The program writes about 2500 different text files each time it runs.</p>
  <p>Each file is a csv and has five columns
  date, data, data, data, data</p>
  <p>Im wanting to delete the last row of the data to write the new information only if it has already ran that day.</p>
  <pre><code>with open('file.csv', 'r+') as file:
      info = [line.split(',') for line in file]
      for row in info:
          if str(today) in row:
              #need help here
  </code></pre>
  <p>this is the old one that I'm re-doing. I need to rework it as it will no longer work with the new program.</p>
  <pre><code>with open('file.csv', 'a+') as file:
      file.write(str(today) + ',' +
                 str(data) + ',' +
                 str(data) + ',' +
                 str(data) + ',' +
                 str(data) + ',' + '\n')
  </code></pre>