Need Help comparing dates

colincolehour at gmail.com colincolehour at gmail.com
Mon Jun 19 20:46:50 EDT 2006


The program works great! It does everything I wanted it to do and now
I'm already thinking about ways of making it more useful like emailing
me the results of my program.

Thanks everyone for the help and advice.

Colin

Tim Chase wrote:
> > 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