Calendar Module in Python not working

Question:

I tried to use the python calendar module in version 3.5.2 with:

import calendar

yy = 2016
mm = 12

# To ask month and year from the user
# yy = int(input("Enter year: "))
# mm = int(input("Enter month: "))

display=calendar.calendar(yy,mm)

# display the calendar
print(display)

but every time I try to run it, crashes and says:

line 2, in <module>
import calendar

line 4, in <module>
cal = calendar.month(2016, 2)

AttributeError: module 'calendar' has no attribute 'month'

Conversely, I tried this in terminal (using Python 2.7), and it does what it is told…!

Just unsure why this doesn’t work in one of the latest version of Python

Asked By: thecooldudes12345

||

Answers:

From this answer here. You probably calling another file called calendar. Use this to find where that file is: print(calendar) Hope this helps!

EDIT: also according to the documentation, I think that you are looking for the function monthdatescalendar(year, month) not calendar.month(). please read over the python3 documentation for calendar. Thanks!

Answered By: zoecarver

You already named a file calendar.py that it is referencing instead of the calendar module.

https://intellipaat.com/community/65020/why-calendar-module-is-not-working-on-python-3

Answered By: bayo ade
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.