我在python中显示错误的示例监视程序代码

时间:2013-03-15 09:39:00

标签: python watchdog

我复制了一个示例代码

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 ad watchdog的新手

我还需要针对以下问题提供更多答案: 以什么形式,下面的代码输出显示在哪里? 如何在代码中更改要监视的目录?

并尝试将其保存在文件test.py中,并将其保存为以下

  

python C:\ folder \ 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()

1 个答案:

答案 0 :(得分:0)

这看起来像监视器中的错误。它适用于Python 2.6和2.7。 sys.version是两者中的字符串,与元组相当。对我来说似乎是一个奇怪的想法。

此行为可能已更改为3.x.如果没有使用3.x正确测试,您应该会遇到更多麻烦。使用Python 2.7仍然是最安全的,因为许多库没有提供3.x支持。

无论如何,如果你真的想要克服这个问题,可以修改watchdog \ utils \ bricks.py中的第112行:

ver = tuple([int(x) for x in sys.version.split()[0].split('.')])
if not ver < (2, 6, 0):

这真的很难看。而是使用Python 2.7。