我对编程很陌生。当我在 IDLE3 shell 中输入以下代码时,它工作正常。当我保存它并将其作为模块运行或通过终端运行时,它返回以下错误:
File "/home/pi/Python_Programs/calendar.py", line 4, in calendar.prmonth(2016, i) AttributeError: 'module' object has no attribute 'prmonth'
这是我的代码:
import calendar
for i in range(1, 13):
calendar.prmonth(2016, i)
请告诉我我做错了什么?
最佳答案
这是因为您将模块命名为 calendar.py - Python 正在尝试从您自己的模块加载 prmonth
,而不是从实际的日历模块 - 您已有效地隐藏它。
只需将您的模块命名为其他名称,以便从实际的日历模块访问 prmonth
。
关于python - 如何在 Python 中使用日历类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37479473/