Figure out month number from month abbrievation

John Salerno johnjsal at NOSPAMgmail.com
Wed Apr 12 17:02:13 EDT 2006


Bill wrote:

> def month_number(monthabbr):
>     """Return the month number for monthabbr; e.g. "Jan" -> 1."""
>     for index, day in enumerate(calendar.month_abbr):
>         if day == monthabbr:
>             return index
> 
> which works well enough but isn't very clever.  I'm pretty new to
> Python; what am I missing here?
> Thanks -- Bill.

I'm curious, does that really work, or is there a problem with the first 
index being 0? Or is that avoided somehow?



More information about the Python-list mailing list