Python返回一个错误,但代码正常

Python返回一个错误,但代码正常,python,python-3.x,Python,Python 3.x,我已经编写了一个查找日历月的小代码,但是python返回了错误 # First import the calendar module import calendar # ask of month and year yy = int(input("Enter year: ")) mm = int(input("Enter month: ")) # display the calendar print(calendar.month(yy, mm)) 现在,当我在kali linux中使用

我已经编写了一个查找日历月的小代码,但是python返回了错误

# First import the calendar module

import calendar

# ask of month and year

yy = int(input("Enter year: "))
mm = int(input("Enter month: "))

# display the calendar

print(calendar.month(yy, mm))
现在,当我在kali linux中使用“python3 calendar.py”运行这段代码时。它返回这个错误

python3 calendar.py
Enter year: 1989
Enter month: 8
Traceback (most recent call last):
  File "calendar.py", line 3, in <module>
    import calendar
  File "/root/calendar.py", line 12, in <module>
    print(calendar.month(yy, mm))
AttributeError: module 'calendar' has no attribute 'month'
python3 calendar.py
年份:1989年
输入月份:8
回溯(最近一次呼叫最后一次):
文件“calendar.py”,第3行,在
导入日历
文件“/root/calendar.py”,第12行,在
打印(日历月(yy,mm))
AttributeError:模块“calendar”没有属性“month”

当我在某个在线python解释器中运行它时,它工作正常。

因为您将python脚本命名为“calendar.py”。它正在导入当前文件,而不是真正的模块。更改名称,它就会工作。

如果您将脚本命名为
calendar.py
,请更改名称