1

On my Mac, my code is working. Why doesn't it work on Windows 10?

from twilio.rest import Client 
import time 
import hashlib 
from datetime import date 
from watchdog.observers import Observer 
from watchdog.events import FileSystemEventHandler

class ModifiedEventHandler(FileSystemEventHandler):
    def on_modified(self, event):
        with open(pathname) as f:
            f = f.readlines()

            for line in f:
                code = hashlib.sha256(line.encode('utf-8')).hexdigest()
                if pattern in line and code not in important:
                    important.append(code)
                    client.messages.create(to=TO, from_=FROM,
                                           body=MSG + str(date.today().strftime('%d.%m.%Y')))
                    break

            print(len(important))


if __name__ == "__main__":
    event_handler = ModifiedEventHandler()

    my_observer = Observer()
    my_observer.schedule(event_handler, pathname, recursive=True)

    my_observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        my_observer.stop()
    my_observer.join()

When I execute the method on_modified the method is not executed:

 def on_modified(self, event):
        print(pathname)

log shows nothing at all and on my MAC it works.

durmex
  • 119
  • 6
  • Where does `FileSystemEventHandler` come from? – larsks Jun 04 '22 at 15:09
  • Welcome to Stack Overflow. Please read [ask] and [mre], and show any necessary `import`s etc. required to make the code work. We should be able to copy and paste your code and test it as is. Ideally, the code should *only* contain what is needed *to demonstrate the problem* - it does not need to be the entire code for the entire problem. If the problem is that `def on_modified(self, event):` doesn't get called at all, then we don't need anything beyond `pass`, or `print('on_modified was called')` for the body. – Karl Knechtel Jun 04 '22 at 15:17
  • On the other hand, if `on_modified` *does* get called and just doesn't seem to have any *effect*, then the next question is to figure out *what actually is happening* when it gets called - and isolate the problem. See also https://ericlippert.com/2014/03/05/how-to-debug-small-programs/. – Karl Knechtel Jun 04 '22 at 15:18
  • sorry here the imports: from twilio.rest import Client import time import hashlib from datetime import date from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler – durmex Jun 05 '22 at 13:58

0 Answers0