all Python 3calendarexception
calendar.IllegalWeekdayError
exceptions
Raised for a weekday number outside 0–6, for example by setfirstweekday(7); a subclass of ValueError, with the bad number in the weekday attribute.
Syntax
except calendar.IllegalWeekdayError as e: e.weekday
A common cause is the isoweekday() habit where Sunday is 7: here Sunday is 6. Only setfirstweekday() validates the number; the constructors Calendar(7) and TextCalendar(7) raise nothing and silently take the value modulo 7, which is Monday.
Examples
import calendar
try:
calendar.setfirstweekday(7)
except calendar.IllegalWeekdayError as e:
print(e.weekday, isinstance(e, ValueError)) # → 7 True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy