python-TypeError:';模块';对象不可调用
我想在我的应用程序中使用库,这是我的代码:python-TypeError:';模块';对象不可调用,python,scheduler,Python,Scheduler,我想在我的应用程序中使用库,这是我的代码: import telepot import sys import time import schedule import datetime from redis import Redis from rq_scheduler import Scheduler scheduler = Scheduler(connection=Redis()) def handle(): print("hello") def main(): sc
import telepot
import sys
import time
import schedule
import datetime
from redis import Redis
from rq_scheduler import Scheduler
scheduler = Scheduler(connection=Redis())
def handle():
print("hello")
def main():
scheduler.enqueue_at(datetime(2017, 9, 11, 22, 41),handle)
if __name__ == '__main__':
main()
我明白了:
更新:
Traceback (most recent call last):
File "***\__init__.py", line 22, in <module>
main()
File "***\__init__.py", line 18, in main
scheduler.enqueue_at(datetime(2017, 9, 11, 22, 41),handle)
TypeError: 'module' object is not callable
回溯(最近一次呼叫最后一次):
文件“***\\uuuu init\uuuuu.py”,第22行,在
main()
文件“***\\uuuu init\uuuuu.py”,第18行,主目录
调度程序。在(日期时间(2017,9,11,22,41),句柄处排队)
TypeError:“模块”对象不可调用
我的错误在哪里?为什么会出现这种情况?
datetime
是一个模块,它还声明了一个名为datetime
的类
scheduler.enqueue_at(datetime.datetime(2017, 9, 11, 22, 41),handle)
或
在理想情况下,类应该有一个符合PEP-8的名称(即,
datetime.datetime
),以避免混淆。可能它的副本必须是datetime.datetime(…)
@Akash,是的。不过,我很犹豫是否结束这个问题,因为它与那个问题有重复之处。应该有一篇维基百科文章“以模块命名的Python类列表”。)使用from datetime导入datetime
from datetime import datetime
...
schedule.enqueue_at(datetime(2017, 9, 11, 22, 41), handle)