Python自动化-自动将文件移动到另一个文件夹中-代码不执行

Python自动化-自动将文件移动到另一个文件夹中-代码不执行,python,automation,python-watchdog,Python,Automation,Python Watchdog,我创建了一个文本文件,希望将其从一个文件夹移动到另一个文件夹。每次我在空闲状态下运行它并尝试它时,什么都没有发生 from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler import os import json import time class MyHandler(FileSystemEventHandler): def on_modified(self,

我创建了一个文本文件,希望将其从一个文件夹移动到另一个文件夹。每次我在空闲状态下运行它并尝试它时,什么都没有发生

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

import os
import json
import time

class MyHandler(FileSystemEventHandler):
    def on_modified(self, event):
        for filename in os.listdir(folder_to_track):
            src = folder_to_track + "/" + filename
            new_destination = folder_destination + "/" + filename
            os.rename(src, new_destination)

folder_to_track = "/Users/nimit/Desktop/New"
folder_destination = "/Users/nimit/Desktop/New2"
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, folder_to_track, recursive=True)

try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    observer.stop()
observer.join()

如果不使用括号,请尝试
event\u handler=MyHandler
。括号不会更改,仍然无效。请保留括号。将
observer.start()
添加到
observer.schedule(…)
之后,我收到一个错误,错误是:TypeError:dispatch()缺少1个必需的位置参数:“event”保留括号:
event\u handler=MyHandler()
尝试
event\u handler=MyHandler
不带括号它不会更改,仍然不起作用保留括号。在
observer.schedule(..)
之后添加
observer.start()
,然后我得到一个错误,错误是:TypeError:dispatch()缺少1个必需的位置参数:“event”保留括号:
event\u handler=MyHandler()