Search code examples
pythondate

How do you get a list of day and month names in the Python standard library?


I have some custom date code that needs the names of the days and months as lists.

I would expect to find them in the standard library somewhere, but time and datetime don't seem to have them. I could define my own lists, or use time.strftime() to get each name, but that seems clunky. How/where can I get lists of day names and month names?


Solution

  • You were looking in the wrong base libraries to get those lists, what you needed was -

    import calendar
    print(list(calendar.month_name))
    print(list(calendar.day_name))
    

    gets you a list of months and days of the week