Need Help comparing dates

Tim Chase python.list at tim.thechases.com
Mon Jun 19 14:39:24 EDT 2006


> I kept getting a Python error for the following line:
> 
> month = m[webMonth]
> 
> I changed it to month = month_numbers[webMonth]
> 
> and that did the trick.

Sorry for the confusion.  Often when I'm testing these things, 
I'll be lazy and create an alias to save me the typing.  In this 
case, I had aliased the month_numbers mapping to "m":

	>>> m = month_numbers

and it slipped into my pasted answer email.  You correctly fixed 
the problem.  The purpose of the mapping is simply to resolve the 
month name to the month number so that the month number can be 
used.  Depending on how predictable the website's date string 
will be, you can use

	month_numbers = dict([(date(2006, m, 1).strftime("%b").upper(), 
m) for m in range(1,13)])

and then use

	month = month_numbers[webMonth.upper()]

or

	month = month_numbers[webMonth[0:3].upper()]

depending on whether the website might return full month names or 
not.

-tkc








More information about the Python-list mailing list