AttributeError:“DateTemplates”对象没有属性“\u to\u date”

2024-10-03 02:37:23 发布

您现在位置:Python中文网/ 问答频道 /正文

代码发布了here,我试图编译程序,但每次编译都会控制这个回溯:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/ceradon/cerabot-rewrite/cerabot/tasks/date_templates.py", line 187, in 
    bot = DateTemplates()
  File "/home/ceradon/cerabot-rewrite/cerabot/tasks/date_templates.py", line 19, in __init__
    super(DateTemplates, self).__init__()
  File "cerabot/bot.py", line 51, in __init__
    self.setup()
  File "/home/ceradon/cerabot-rewrite/cerabot/tasks/date_templates.py", line 110, in setup
    self._load_templates()
  File "/home/ceradon/cerabot-rewrite/cerabot/tasks/date_templates.py", line 61, in _load_templates
    self._to_date.append(template.get(1).value.lower())
AttributeError: 'DateTemplates' object has no attribute '_to_date'

我迷路了,有人能帮我弄清楚吗?你知道吗


Tags: runinpyselfhomedateinitline
1条回答
网友
1楼 · 发布于 2024-10-03 02:37:23

当您调用super(DateTemplates, self).__init__()时,它运行Bot.__init__,它调用self.setup(),它运行DateTemplates.setup(),但是这发生在初始化self._to_date之前,因此还没有要附加到的列表。将super中的DateTemplates.__init__调用移到方法的末尾,这样应该可以工作。你知道吗

相关问题 更多 >