Question: How do you write data to an existing file at the beginning of a file, without writing what is already there, and do not read the entire file in memory? (e.g. preend)
information:
I am working on a project right now, when the program often uploads data to a file. This file will take off very quickly up to 3-4 GB. I run this simulation on a computer with only 768 MB of RAM. pulling all this data into the ram again and again will be a big pain and a huge waste of time. Modeling is already taking enough time to work as it is.
The file is structured in such a way that the number of dumps it makes is indicated at the beginning with a simple value, for example 6. every time the program creates a new dump, I want it to increase, so now the problem is 10, 100, 1000 and so dump. the program will enter 10 only a penalty, but will delete the first letter of the next line:
"9 \ n580,2995,2083,028 \ n ..."
"10 \ n80,2995,2083,028 \ n ..."
it is obvious that the difference between 580 and 80 in this case is significant. I cannot lose these values. so I need a way to add a little space there so that I can add to this new data without losing my data, or not have to pull out the whole file and then rewrite it.
Basically what I'm looking for is a kind of prepend function. something to add data to the beginning of the file, not to the end.
Programmed in Python
~ p