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
Had the same challenge. If the issue is not with a similar file name, please note that the prevmonth
and nextmonth
functions have been deprecated https://bugs.python.org/issue35406
You can still access them using the _prevmonth and _nextmonth functions, but note that they don't check if the month is valid (kindly refer to the link posted above for details), so you may need to write your assert statement before using them
MONTH_NUMBER = 12 # enter your month number here
assert MONTH_NUMBER in range(0,13)
# continue the rest of your code
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.
Do not name the file as calendar.py and there should be no calendar.py file on the same path
You might have given your file name as calendar.py. This is imported instead of the module in the standard library.
Solution: Rename the file. Also, make sure to delete "calendar.pyc" file located in the same path where you are running the script.
As a check, do the following to locate your module import calendar print(calendar)
Renaming the file is not going to be enough, when you import the file a .pyc
is created so even if you rename you are still going to have a .pyc
with the same name in the folder so you are still going to be importing from that.
Also if you have any calendar.py
or .pyc
in your path before the standard libs calendar
you will end up importing that also so make sure there are no other files named calendar.py/pyc
anywhere in your path.