Watching a file another app is writing
nagle at animats.com
Mon Mar 12 18:53:19 CET 2007
Nick Vatamaniuc wrote:
> On Mar 11, 3:36 pm, Gordon Airporte <JHoo... at fbi.gov> wrote:
>>I'm trying to find a way to take a file that another program has opened
>>and writes to periodically, open it simultaneously in Python, and
>>automatically update some of my objects in Python when the file is
>>I can open the file and manually readlines() from it to keep up to date,
>>it's the automatic part I'm having trouble with. This is on Windows.
> You might need to look at pywin32 for Windows specific ways to listen
> to "file changed" event.
> On Unix a quick shortcut would be to simply read the output of 'tail -
> f <file>' command...
"tail -f" just checks the file size once a second. It's not doing
Windows, of course, actually has a mechanism for finding out that
files have changed, so that will work.
Note that if you're doing this as a means of interprocess
communication, there are better ways.
More information about the Python-list