擅长:python、mysql、java
<p>我认为你的想法基本上是正确的,但是它可以更容易地实现。在</p>
<p>pyinotify</strong>模块中的<code>ProcessEvent</code>类已经有一个钩子可以用来过滤事件的处理。它是通过调用构造函数时给定的可选的<code>pevent</code>关键字参数指定的,并保存在实例的<code>self.pevent</code>属性中。默认值是<code>None</code>。它的值在类“<code>__call__()</code>”方法中使用,如<code>pyinotify.py</code>源文件中的以下片段所示:</p>
<pre><code>def __call__(self, event):
stop_chaining = False
if self.pevent is not None:
# By default methods return None so we set as guideline
# that methods asking for stop chaining must explicitly
# return non None or non False values, otherwise the default
# behavior will be to accept chain call to the corresponding
# local method.
stop_chaining = self.pevent(event)
if not stop_chaining:
return _ProcessEvent.__call__(self, event)
</code></pre>
<p>因此,您可以使用它只允许对具有特定后缀(又称扩展名)的文件执行以下操作:</p>
^{2}$