How do I watch a file for changes?

前端 未结 25 3258
孤街浪徒
孤街浪徒 2020-11-21 07:13

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I\'d like to read the new data in to do some processing on it

25条回答
  •  故里飘歌
    2020-11-21 07:57

    Have you already looked at the documentation available on http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html? If you only need it to work under Windows the 2nd example seems to be exactly what you want (if you exchange the path of the directory with one of the files you want to watch).

    Otherwise, polling will probably be the only really platform-independent option.

    Note: I haven't tried any of these solutions.

提交回复
热议问题