我复制了一个示例代码
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
请帮助我,我是 python 广告看门狗的新手
对于以下问题,我还需要更多答案:以什么形式显示以下代码的输出以及在哪里?如何更改代码中要监控的目录?
并尝试通过将其保存在文件 test.py 中使用以下内容来运行它
python C:\文件夹\test.py
它返回了以下错误
C:\Python33>python c:\folder\test.py
Traceback (most recent call last):
File "c:\folder\test.py", line 4, in <module>
from watchdog.observers import Observer
File "C:\Python33\lib\site-packages\watchdog\observers\__init__.py", line 34,
in <module>
from watchdog.observers.api import BaseObserver, DEFAULT_OBSERVER_TIMEOUT
File "C:\Python33\lib\site-packages\watchdog\observers\api.py", line 62, in <module>
from watchdog.utils.bricks import OrderedSetQueue as SetQueue
File "C:\Python33\lib\site-packages\watchdog\utils\bricks.py", line 112, in <module>
if not sys.version < (2, 6, 0):
TypeError: unorderable types: str() < tuple()