Python Forum
How to delete portion of file already processed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to delete portion of file already processed?
#3
A .csv is just a text file. The only way to remove part of a text file (and have it remain a useful text file) is to rewrite it with the later portions moved up.


One technique would be that as you are processing your loop you write all the lines that you want to keep to a new file. When complete, swap the new file into the old file's place.
BashBedlam likes this post
Reply


Messages In This Thread
RE: How to delete portion of file already processed? - by bowlofred - Jan-21-2022, 04:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] how to delete the 10 first lines of an ascii file paul18fr 7 2,041 Aug-07-2024, 08:18 PM
Last Post: Gribouillis
  Delete file with read-only permission, but write permission to parent folder cubei 6 25,940 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  output provide the filename along with the input file processed. arjunaram 1 1,573 Apr-13-2023, 08:15 PM
Last Post: menator01
  Delete multiple lines from txt file Lky 6 4,147 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Find and delete above a certain line in text file cubangt 12 7,072 Mar-18-2022, 07:49 PM
Last Post: snippsat
  delete a file works but with error Leon79 4 4,021 Jul-14-2020, 06:51 AM
Last Post: snippsat
  Find, delete and add text into pdf file a_shvechkov 2 9,018 Jul-08-2020, 10:50 AM
Last Post: a_shvechkov
  Delete all contents of a file from the fifth line? PythonNPC 1 2,698 Apr-18-2020, 09:16 AM
Last Post: buran
  code not writing to projNameVal portion of code. umkc1 1 2,242 Feb-05-2020, 10:05 PM
Last Post: Larz60+
  Can't seem to figure out how to delete several lines from a text file Cosmosso 9 6,590 Dec-10-2019, 11:09 PM
Last Post: Cosmosso

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020