我想用FileSystemEventHandler()
观看Windows文件系统上的特定文件。我感兴趣的事件是FileCreatedEvent(src_path)
和FileModifiedEvent(src_path)
。
我将执行以下操作:
library(vcdExtra)
linlin <- glm(Freq ~ mental + ses + Rscore:Cscore, family = poisson, data
= Mental)
logLik(linlin)
linlin$model$Freq # observed frequencies
linlin$fitted.values # expected frequencies
# how do I get the log-likelihood function value?
此解决方案有效,但我想知道是否存在更好的解决方案以及如何实现它。如何立即使用2019.us.NYC
个事件?我如何摆脱部分冗余的from watchdog.events import FileSystemEventHandler
from watchdog.observers.polling import PollingObserver
import time
class FileMonitor(FileSystemEventHandler):
def __init__(self, file_path):
self.file_path = file_path
def on_created(self, event):
if isinstance(event, FileCreatedEvent):
if event.src_path == self.file_path:
print("file has been created")
print(event)
def on_modified(self, event):
if isinstance(event, FileModifiedEvent):
if event.src_path == self.file_path:
print("file has changed")
print(event)
event_handler = FileMonitor(<PATH-TO-FILE>)
observer = PollingObserver()
observer.schedule(event_handler,
path=<PATH-TO-FILE-ROOT-DIR>,
recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
和src_path
。