我需要查看日志文件的更改。在查看了 stackoverflow 问题后,我看到人们推荐watchdog
. 所以我正在尝试测试,并且不确定在文件更改时在哪里添加代码:
import time
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path='.', recursive=False)
observer.start()
try:
while True:
time.sleep(1)
else:
print "got it"
except KeyboardInterrupt:
observer.stop()
observer.join()
while
如果文件已被添加/更改,我在哪里添加“得到它” - 在循环中?