Python Watchdog TypeError:“bool”对象不可迭代

问题描述

我正在编写一个脚本来检查给定 CSV 文件中的任何修改,并尝试使用看门狗来执行此操作。按照来自 this 站点的(几乎相同的)示例,我有以下代码:

import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler

def on_deleted(event):
    print(f"what the f**k! Someone deleted {event.src_path}!")

def on_modified(event):
    print(f"hey buddy,{event.src_path} has been modified")

if __name__ == "__main__":
    patterns = ["meetingschedule.csv"]
    ignore_directories = True
    case_sensitive = True
    my_event_handler = PatternMatchingEventHandler(patterns,ignore_directories,case_sensitive)

    my_event_handler.on_deleted = on_deleted
    my_event_handler.on_modified = on_modified

    path = "E:\\COPY\\APPs\\ZoomAutoLog\\Zoommeeting-main\\Ext_Tools\\"
    my_observer = Observer()
    my_observer.schedule(my_event_handler,path)

    my_observer.start()
    print('Watchdog is Monitoring now...')
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print('Stopping Watchdog...')
        my_observer.stop()
        my_observer.join()

当我向监视文件夹添加文件或目录时,我收到一个 TypeError: 'bool' object is not iterable。这是回溯:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\threading.py",line 954,in _bootstrap_inner
self.run()
  File "C:\Program Files\Python39\lib\site-packages\watchdog\observers\api.py",line 199,in run
    self.dispatch_events(self.event_queue,self.timeout)
  File "C:\Program Files\Python39\lib\site-packages\watchdog\observers\api.py",line 372,in dispatch_events
    handler.dispatch(event)
  File "C:\Program Files\Python39\lib\site-packages\watchdog\events.py",line 399,in dispatch
    if match_any_paths(paths,File "C:\Program Files\Python39\lib\site-packages\watchdog\utils\patterns.py",line 85,in 
match_any_paths
    if _match_path(path,set(included),set(excluded),case_sensitive):
TypeError: 'bool' object is not iterable

我尝试将 go_recursively 变量的类型更改为 str 和 tuple ,但出现相同的错误。我还尝试将递归参数直接设置为 True 并得到相同的错误。甚至我试图用谷歌搜索任何有关此错误的相关信息,但没有找到。感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)