【问题标题】:python AttributeError: 'module' object has no attribute 'monthcalendar'python AttributeError:“模块”对象没有属性“月历”
【发布时间】:2013-12-27 17:55:20
【问题描述】:

这是我正在尝试的代码。但是 Idle 给出了一个属性错误。虽然日历是python标准库中的一个模块。

AttributeError: 'module' 对象没有属性 'monthcalendar'

代码:

def main():
   today = datetime.datetime.date(datetime.datetime.now())
   current = re.split('-', str(today))
   current_no = int(current[1])
   current_month = year[current_no-1]
   current_day = int(re.sub('\A0', '', current[2]))
   current_yr = int(current[0])

   print '<h1> %s %s </h1 >' %(current_month, current_yr)

   month = calendar.monthcalendar(current_yr, current_no) 

【问题讨论】:

  • 请显示整个代码。
  • 您的文件不会被称为 calendar.py,对吧?
  • print calendar.__file__ 显示的模块文件名是什么?

标签: python datetime module calendar attributeerror


【解决方案1】:

模块日期时间当然有一个属性月历。我看到此错误的唯一原因是您的文件名称为“Calendar.py”

【讨论】:

    【解决方案2】:

    是的。最初我将它保存为 calendar.py 并显示错误消息,最终通过更改文件名修复它。

    【讨论】:

    • 回复与多年前发布的答案相同的评论毫无意义。
    猜你喜欢
    • 2015-03-09
    • 2013-07-05
    • 1970-01-01
    • 2011-10-25
    • 2017-09-02
    • 2014-07-24
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多