In <[EMAIL PROTECTED]>, Steven W. Orr
wrote:
> I want to call datetime.datetim() whose arg2 is a number between 1-12 so I
> have to convert the month to an integer.
> I wrote this, but I have a sneaky suspicion there's a better way to do it.
>
> mons = {'Jan':1, 'Feb':2, 'Mar':3, 'Apr':4, 'May':5, 'Jun':6,
> 'Jul':7, 'Aug':8, 'Sep':9, 'Oct':10, 'Nov':11, 'Dec':12 }
>
> def mon2int( mon ):
> global mons
> return mons[mon]
You've already got some answers, I just want to point out that the
``global`` is unnecessary here and that `mons` as a constant should be
spelled in capital letters by convention. And maybe it's better to write
`MONTHS` instead the abbreviation.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list