Python-日期和时间:AttributeError:“模块”对象没有属性“月” [英] Python - Date and Time: AttributeError: 'module' object has no attribute 'month'
本文介绍了Python-日期和时间:AttributeError:“模块”对象没有属性“月”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在Python中的日历代码,我将其保存为 calendar.py
到我的文件夹。
This is my calendar code in Python and I have saved it to my folder as calendar.py
.
import calendar
a = calendar.month(2016, 3)
print (a)
print ("The Calendar :")
当我执行它时,会引发错误:
When I execute it, it raises an error :
Traceback (most recent call last):
File "calendar.py", line 1, in <module>
import calendar
File "/opt/lampp/htdocs/py/calendar.py", line 2, in <module>
a = calendar.month(2016, 3)
AttributeError: 'module' object has no attribute 'month'
这是怎么回事?
推荐答案
问题是您使用了calendar.py这个名字文件。使用任何其他名称,您将能够导入python模块日历。
The problem is that you used the name calendar.py for your file. Use any other name, and you will be able to import the python module calendar.
这篇关于Python-日期和时间:AttributeError:“模块”对象没有属性“月”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文