wait until change
Lane LiaBraaten
lliabraa at isrparc.org
Fri Oct 17 12:53:26 EDT 2003
On Friday 17 October 2003 12:35 pm, Tom wrote:
> Hi,
>
> I have the following problem. I analyse data from a file. When I am done
> analysing all the data that was in that file, I want to let my program
> wait until this specific file has changed (which indicates that new data
> has been added to the file from a third party program that I don't
> control). If that file has changed, I want my program to continue.
>
> What would be the appropriate command to check if the file changed? And
> how can I implement "wait until" into my program? I googled a lot to
> find any hints, but couldn't find anything helpful. But I found
> something about a python that was stabbed in NY in 2000. :-) Thought
> that was funny. :-)
I would use os.stat() which returns all sorts of info about the file including
modification time.
More info at: http://web.pydoc.org/1.5.2/os.html
time=os.stat(file)[8]
# analyze data
while 1:
if os.stat(file)[8]>time:
#analyze data again
>
> I would deeply appreciate, if you could maybe include some little
> fragments of code to show me how to use your suggestions. I am
> relatively new to python and I often have problems with Pythons Library
> Reference, because it doesn't show examples and is very technically.
> That makes it difficult for me to really understand that. It also would
> be great, if you could tell me which modules I have to include. I hope
> all that is not asked too much. I assume that both problems can be
> solved with a few easy lines of code. I just don't know them. :-)
>
> Thanks a lot for your help and suggestions.
> Regards Tom
I'm sure there are a number of ways to do this.
Good Luck,
LGL
More information about the Python-list
mailing list