Python 类型错误:';模块';对象不可调用:日历模块

Python 类型错误:';模块';对象不可调用:日历模块,python,Python,我第一次在python中使用日历函数这是我的代码: import calendar print ("The calender of year 2018 is : ") print (calendar.calendar(2018,2,1,6)) print ("The starting day number in calendar is : ",end="") print (calendar.firstweekday()) 我得到以下输出 The calender of year 2018 i

我第一次在python中使用日历函数这是我的代码:

import calendar

print ("The calender of year 2018 is : ")
print (calendar.calendar(2018,2,1,6))
print ("The starting day number in calendar is : ",end="")
print (calendar.firstweekday())
我得到以下输出

The calender of year 2018 is : 
Traceback (most recent call last):
  File "C:/Users/AAKASH PATEL/Desktop/calendar.py", line 5, in <module>
    import calendar
  File "C:/Users/AAKASH PATEL/Desktop\calendar.py", line 10, in <module>
    print (calendar.calendar(2018,2,1,6))
TypeError: 'module' object is not callable
2018年日历为:
回溯(最近一次呼叫最后一次):
文件“C:/Users/AAKASH PATEL/Desktop/calendar.py”,第5行,在
导入日历
文件“C:/Users/AAKASH PATEL/Desktop\calendar.py”,第10行,在
打印(日历。日历(2018,2,1,6))
TypeError:“模块”对象不可调用

如何解决此问题

将脚本名称从
calendar.py
重命名为
calendarScript.py

"C:/Users/AAKASH PATEL/Desktop/calendar.py"


注意:不要将脚本命名为与模块相同的名称。

将脚本名称从
calendar.py
重命名为
calendarScript.py

"C:/Users/AAKASH PATEL/Desktop/calendar.py"


注意:不要将脚本命名为与模块相同的名称。

当复制代码并执行它时,它工作得非常好!但是我看到你的脚本,你的代码叫做calendar.py!Python认为这就是您想要导入的内容!因此,请将您的脚本重命名为其他脚本

当复制并执行代码时,它工作得非常好!但是我看到你的脚本,你的代码叫做calendar.py!Python认为这就是您想要导入的内容!因此,请将您的脚本重命名为其他脚本

您将脚本命名为
calendar.py
,因此导入的就是该文件。您可以在回溯中看到这一点:

  File "C:/Users/AAKASH PATEL/Desktop/calendar.py", line 5, in <module>
    import calendar
  File "C:/Users/AAKASH PATEL/Desktop\calendar.py", line 10, in <module>
    print (calendar.calendar(2018,2,1,6))

请注意,
日历。日历(2018)
就足够了;接下来三个参数(
w
表示列宽,
l
表示每周行数,
c
表示月列间距)的默认值分别为2、1和6。

您将脚本命名为
calendar.py
,因此导入的就是该文件。您可以在回溯中看到这一点:

  File "C:/Users/AAKASH PATEL/Desktop/calendar.py", line 5, in <module>
    import calendar
  File "C:/Users/AAKASH PATEL/Desktop\calendar.py", line 10, in <module>
    print (calendar.calendar(2018,2,1,6))

请注意,
日历。日历(2018)
就足够了;接下来三个参数(
w
表示列宽,
l
表示每周行数,
c
表示月列间距)的默认值分别为2、1和6。

仔细查看您的回溯。您导入了自己的脚本。请仔细查看您的回溯。您导入了自己的脚本。calendarScript:不太Pythonic(PEP8)。@CristiFati…只是一个示例:)calendarScript:不太Pythonic(PEP8)。@CristiFati…只是一个示例:)