Someplace nice

Converting a month name from a string to an int

I was recently writing a python script where a function was passed a month name as a string and I wanted to get out the month number as an int based on that string.

I found quite a few posts about going the other way, but this is how I managed to do it:

import calendar

list(calendar.month_name).index(‘<insert month name here>’)

Archive