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?
#11
I think the problem may only be in your mind. A big file likely does not slow things down. It takes longer to process a big file because there is more information to process, but making the file smaller does not reduce the time to process each element/transaction/whatever. Trying to remove the processed information is just going to slow things down because not only are you still doing the work to process the file information, but you are doing additional work to change information about the file, maybe even modifying non-volatile memory which is slow relative to most computer operations.
Reply
#12
If things are taking too long, you should look into profiling the program. Find out which parts are slow and which parts are not. Only worry about the parts that are slow.

One way is to stub out the real work you're doing. Write a program that reads through the lines like you would and passes them to an empty function in the right order. If you can do that quickly then that part doesn't need to be sped up.
ndc85430 likes this post
Reply
#13
It always worth of remembering:

Quote:Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

---Donald Knuth
ndc85430 likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#14
There was another question recently about a file with 2 million rows. Is this related? I was curious how that ended, but I didn't see an echo.

I never had big data to process.

But if your data is split into years, why not just check each year?

An electrician once told me, if you have a broken cable, cut it in half and test each half.

2 possibilities:

1. You cut it exactly where it is broken (unlikely).
2. One half is good.

Don't know what answers you are looking for, but checking slices of the readlines() list may ease the burden.

The original file will always be preserved until and unless you overwrite it: original_file.write(new_data) so just open it 'r'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  output provide the filename along with the input file processed. arjunaram 1 926 Apr-13-2023, 08:15 PM
Last Post: menator01
  Delete multiple lines from txt file Lky 6 2,275 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Find and delete above a certain line in text file cubangt 12 3,447 Mar-18-2022, 07:49 PM
Last Post: snippsat
  delete a file works but with error Leon79 4 2,916 Jul-14-2020, 06:51 AM
Last Post: snippsat
  Find, delete and add text into pdf file a_shvechkov 2 5,920 Jul-08-2020, 10:50 AM
Last Post: a_shvechkov
  Delete all contents of a file from the fifth line? PythonNPC 1 1,899 Apr-18-2020, 09:16 AM
Last Post: buran
  code not writing to projNameVal portion of code. umkc1 1 1,669 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 4,111 Dec-10-2019, 11:09 PM
Last Post: Cosmosso
  delete file with handling 3Pinter 1 2,090 Oct-17-2019, 04:06 PM
Last Post: 3Pinter
  delete a file after closing it mcgrim 1 2,096 May-14-2019, 08:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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