The calendar module defines the Calendar class, which encapsulates calculations for values such as the dates of the weeks in a given month or year. In addition, the TextCalendar and HTMLCalendar classes can produce pre-formatted output.
In [2]:
import calendar
c = calendar.TextCalendar(calendar.MONDAY)
c.prmonth(2017,7)
In [3]:
import calendar
import pprint
cal = calendar.Calendar(calendar.SUNDAY)
cal_data = cal.yeardays2calendar(2017, 3)
print('len(cal_data) :', len(cal_data))
top_months = cal_data[0]
print('len(top_months) :', len(top_months))
first_month = top_months[0]
print('len(first_month) :', len(first_month))
print('first_month:')
pprint.pprint(first_month, width=65)
In [4]:
import calendar
cal = calendar.TextCalendar(calendar.SUNDAY)
print(cal.formatyear(2017, 2, 1, 1, 3))
In [9]:
import calendar
c = calendar.LocaleTextCalendar(locale='en_US')
c.prmonth(2017, 7)
print()
c = calendar.LocaleTextCalendar(locale='fr_FR')
c.prmonth(2017, 7)