Newbie question

Harry Knitter nospam at knitter-edv-beratung.de
Fri Jul 23 07:41:10 EDT 2004


Thomas Guettler wrote:

> Am Fri, 23 Jul 2004 13:03:47 +0200 schrieb Harry Knitter:
> 
>> Hello,
>> 
>> I am new with Python and would like to know how to achieve to make a
>> Python
>> program continously  listening if a certain data file is changed from
>> another program.
>> Thanks
> 
> untested:
> 
> import os
> import time
> 
> file="...."
> mtime=os.path.getmtime(file)
> while 1:
>     if os.path.getmtime(file)!=mtime:
>         print "%s changed" % file
>         mtime=os.path.getmtime(file)
>     time.sleep(1)
> 
Thanks, however, how do I have to invoke this procedure avoiding the program
remaining in this endles loop.What I want to achieve is, that the program
does something, when the file is changed an then listening again. Meanwhile
the user shoud be able to use the program as usual. i.e. I need this
procedure as a background process triggering a special action.

Harry



More information about the Python-list mailing list