Python 如何观察目录的变化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4708511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to watch a directory for changes?
提问by Gnu Engineer
Could not find anything in python core to do this. Can anyone recommend a library or "battery" to do this? Ideally I would like this to be portable but it's OK if it is available only for Unix (my server).
在 python 核心中找不到任何东西来做到这一点。谁能推荐一个图书馆或“电池”来做到这一点?理想情况下,我希望它是可移植的,但如果它仅适用于 Unix(我的服务器)也可以。
回答by pyfunc
On Linux, you could be interested in pyinotify
在 Linux 上,你可能对 pyinotify 感兴趣
Other related libraries:
其他相关库:
回答by Alain Pannetier
I don't think there's something portable for this kind of requirement. That's too close to the OS IMO. Otherwise for Linux, there's pynotify. pyinotify is a binding for Linux inotify kernel filesystem notification subsystem. Works quite well.
我认为这种要求没有什么可移植的。这太接近操作系统 IMO。否则对于 Linux,有pynotify。pyinotify 是 Linux inotify 内核文件系统通知子系统的绑定。效果很好。
回答by roberkules
I was just looking for a python package that watches file modifications. Just stumbled upon pywatchand it might just be what you're looking for. It's very simple, but does what I need (fixing pyScss' lack of a watcher).
我只是在寻找一个监视文件修改的 python 包。只是偶然发现了pywatch,它可能正是您正在寻找的。这很简单,但是可以满足我的需求(修复 pyScss 缺少观察者的问题)。

