0

I need help solving this error. I have created a class that has different functions in it. My aim is to call certain functions of the class that I have created based on the triggering of specific events. When my event is triggered I get an error saying Name error.

I am including the code below:

class OurHandler(FileSystemEventHandler):

    # def __init__(self, source):
    #     self.source = source

    def move_epub(self):
        for i in os.listdir(self.source):
            print("Hello World")

    def on_any_event(self, event):
        print(f"\n\n{self}\t\t {event}\n\n")
        move_epub()

track_this_folder = "pathname"
a = OurHandler()
observer = Observer()
observer.schedule(a, track_this_folder)
observer.start()
try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    observer.stop()
observer.join()

enter image description here

wjandrea
  • 28,235
  • 9
  • 60
  • 81
lAaravl
  • 929
  • 2
  • 9
  • 20

1 Answers1

1

move_epub is an instance method, so you need to call self.move_epub()

P.S. The next problem you'll have is that self.source is undefined in move_epub.

wjandrea
  • 28,235
  • 9
  • 60
  • 81