I would like to create a python function that would allow me to iterate over the months from a start point to a stop point. For example it would look something like
def months(start_month, start_year, end_month, end_year):
Calling months(8, 2010, 3, 2011) would return:
((8, 2010), (9, 2010), (10, 2010), (11, 2010), (12, 2010), (1, 2011), (2, 2011), (3, 2011))
The function could just return a tuple of tuples, but I would love to see it as a generator (ie using yield).
I’ve checked the calendar python module and it doesn’t appear to provide this functionality. I could write a nasty for loop to do it easily enough, but I’m interested to see how gracefully it could be done by a pro.
Thanks.
The calendar works like this.
All multiple-unit things work like this. Feet and Inches, Hours, Minutes and Seconds, etc., etc. The only thing that’s not this simple is months-days or months-weeks because months are irregular. Everything else is regular, and you need to work in the finest-grained units.