我想用在我的項目apscheduler.scheduler
,這是我的代碼python-類型錯誤:函數必須調用
import sys
from time import sleep
from apscheduler.scheduler import Scheduler
TOKEN = "****"
sched = Scheduler()
sched.start()
def my_job(text):
print(text)
def main() :
job = sched.add_date_job(my_job('25'), '2017-09-08 14:08:05', args=['text'])
while True:
sleep(1)
sys.stdout.write('.'); sys.stdout.flush()
if __name__ == '__main__':
main()
,我得到這個例外
25
Traceback (most recent call last):
File "F:\+faeze\workspace\testHelloWorld\src\test\testDateTime.py", line 22, in <module>
main()
File "F:\+faeze\workspace\testHelloWorld\src\test\testDateTime.py", line 16, in main
job = sched.add_date_job(my_job('25'), '2017-09-08 14:08:05', args=['text'])
File "C:\Python27\lib\site-packages\apscheduler\scheduler.py", line 318, in add_date_job
return self.add_job(trigger, func, args, kwargs, **options)
File "C:\Python27\lib\site-packages\apscheduler\scheduler.py", line 284, in add_job
options.pop('coalesce', self.coalesce), **options)
File "C:\Python27\lib\site-packages\apscheduler\job.py", line 47, in __init__
raise TypeError('func must be callable')
TypeError: func must be callable
哪裏是我的錯?
更新:TypeError: func must be callable
是什麼意思?
這意味着錯誤的變量被傳遞給add_job方法和add_job方法接收可變/非可調用替代地稱爲實際功能 – AK47
'func'是你的方法的參數,它試圖在某個時候調用func()並且它不能。例如func = '10'... func()什麼都不會做。數字10不可回調 – AK47