read from file

Jeremy Dillworth jwdillworth at
Fri Sep 12 16:55:18 CEST 2003

It depends.  Is the information being appended to the end of the file?
If so then the solution is pretty simple.

Just record the file size when you read it, watch the mtime using os.stat(),
when the file changes open it and do a to the original file size
before beginning to read.  When done reading, record the new filesize.

If records at the end of the file are incomplete you'll need to compensate.
Maybe you could record an expected_file_size and an already_read_file_size.
Seek to the already_read_file_size to pick up records that were incomplete
during the last read.  When inspecting the file, compare against 

If the new data is being written to various positions in the file then
the solution is much more complicated and we need more specifics.
You need a way to know which records in the file have changed.

--- Tom <llafba at> wrote:
> Hi folks,
> I need to read information from a file. That is not the problem, BUT 
> another programm (I have no control about that programm) constantly 
> writes more information into that specific file. How can I get the new 
> information that has bee added to that file and that I have not yet 
> read? I don't want to re-read the entire file, because that is a whole 
> lot of data!!
> I wrote a little software that is analysing the data that is written 
> into the file. That's why I would only like to get the new data.
> Any help would be deeply appreciated.
> Thanks Tom
> P.S.: Another question would be: Is there a way to find the file that 
> was last edited?
> -- 

More information about the Python-list mailing list