Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Date and Time: AttributeError: 'module' object has no attribute 'month'

Tags:

python

date

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'

What's going on?

like image 625
yuvaraj Avatar asked Dec 15 '22 08:12

yuvaraj


2 Answers

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.

like image 143
timgeb Avatar answered May 13 '23 13:05

timgeb


Do not name the file as calendar.py and there should be no calendar.py file on the same path

like image 20
Abhijeet Verma Avatar answered May 13 '23 12:05

Abhijeet Verma