from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler class MyHandler(FileSystemEventHandler): def on_created(self, event): print(f"{event.src_path} has been created!") # create an observer instance observer = Observer() # set the path to the directory you want to monitor path = "/path/to/directory" # create an event handler instance handler = MyHandler() # schedule the observer to watch the directory for changes observer.schedule(handler, path, recursive=True) # start the observer observer.start() # stop the observer observer.stop() # join the observer to wait for it to complete observer.join()In this example, we have defined a custom event handler `MyHandler` that prints a message whenever a file is created in the monitored directory. We then create an observer instance, set the directory path, and schedule the observer to use the custom handler to monitor the directory for changes. Finally, we start the observer and wait for it to complete. Please note that the `watchdog` package needs to be installed before using the code examples.