按照python实例编写python生成日历的实例
代码如下:
# Filename : test.py
# author by : www.runoob.com
# 引入日历模块
from calendar import month
# 输入指定年月
yy = int(input("输入年份: "))
mm = int(input("输入月份: "))
# 显示日历
print(month(yy,mm))
但在运行时出现如下错误:
"D:\Program Files\Python\Python36\python.exe" F:/LearningDocument/Python/untitled/test10.py
输入年份:2017
输入月份:09
Traceback (most recent call last):
File "F:/LearningDocument/Python/untitled/test10.py", line 5, in <module>
from calendar import month
File "F:\LearningDocument\Python\untitled\calendar.py", line 9, in <module>
print(calendar.month(yy,mm))
AttributeError: module 'calendar' has no attribute 'month'
经过检查发现自己在 本地保存了名为calendar.py的文件,导致与python中的类calendar冲突,将calendar.py文件重命名就解决此问题了