Figure out month number from month abbrievation
Azolex
cretin at des.alpes.ch
Wed Apr 12 17:11:38 EDT 2006
John Salerno wrote:
> 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?
you don't have a python shell always at hand for such cases of curiosity ?
>>> import calendar
>>> tuple(calendar.month_abbr)
('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec')
More information about the Python-list
mailing list