问题:
How do I watch a file for changes using Python?建议使用看门狗,但我发现它只能观看目录,而不是文件.
watchdog-test.py是看门狗的示例脚本:
$python watchdog-test.py ab_test_res.sh &
[1] 30628
fbt@fbt64:~/laike9m$Traceback (most recent call last):
File "watchdog-test.py", line 15, in
observer.start()
File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/api.py", line 255, in start
emitter.start()
File "/usr/local/lib/python2.7/dist-packages/watchdog/utils/__init__.py", line 111, in start
self.on_thread_start()
File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify.py", line 121, in on_thread_start
self._inotify = InotifyBuffer(path, self.watch.is_recursive)
File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__
self._inotify = Inotify(path, recursive)
File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_c.py", line 187, in __init__
self._add_dir_watch(path, recursive, event_mask)
File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_c.py", line 363, in _add_dir_watch
raise OSError('Path is not a directory')
OSError: Path is not a directory
那么什么是最好的解决方案?我正在使用Linux(Ubuntu 12.04).顺便说一下,我不想使用民意调查.
如果觉得《python怎么改目录_如何查看文件 而不是使用Python进行更改的目录?》对你有帮助,请点赞、收藏,并留下你的观点哦!