2

The calendar module defines constants e.g. MONDAY (0), TUESDAY (1), etc. for the days of the week.

And the source code even defines (but does not export) constants for January (1) and February (2), but not the rest of the months.

I can of course throw in a dozen of these definitions in a small module of my own. But given how common these must be, I'm left wondering:

Is there a standard python module defining constants for all of the months?

5
  • you mean like an enum? for a mapping, see this q&a. Commented Apr 16, 2023 at 15:15
  • Sure, could be. I basically want to be able to do from some_module import APRIL, and then use APRIL instead of 4 where needed e.g. to initialise a datetime.date object. Commented Apr 18, 2023 at 7:42
  • I'd probably just use an IntEnum. But I agree, it seems a bit inconsistent for the calendar module to define weekdays but not months. Maybe make a feature request? Commented Apr 18, 2023 at 8:20
  • 2
    Started: discuss.python.org/t/… Commented Apr 19, 2023 at 10:28
  • There is also now an open issue: github.com/python/cpython/issues/103636 Commented Apr 20, 2023 at 13:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.