Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading