最近,我对Python语言感兴趣,所以我尝试测试以下内容 码。
import sched
import time
scheduler = sched.scheduler(time.time, time.sleep)
def print_event(name, start):
now = time.time()
elapsed = int(now - start)
print 'EVENT: %s elapsed=%s name=%s' % (time.ctime(now), elapsed, name)
start = time.time()
print 'START:', time.ctime(start)
scheduler.enter(2, 1, print_event, ('first', start))
scheduler.enter(3, 1, print_event, ('second', start))
scheduler.run()
测试后我得到如下错误:
calvin @calvin-K42Jv:/ usr / local / myprjs / Python $ python sched3.py Traceback(最近一次调用最后一次): 文件" sched3.py",第1行,in 导入sched 文件" /usr/local/myprjs/Python/sched.py" ;,第2行,在 s = sched.scheduler(time.time,time.sleep) AttributeError:'模块'对象没有属性' scheduler'