How to generate a list
of date
objects for each day in a specific month and year.
I've tried using calendar
module, but it's not what I want.
Using the timedelta module you can loop through all the possible values nicely and stop when the month changes.
from datetime import date, timedelta
def generate_month_days(year, month):
start_date = date(year, month, 01)
cur_date = start_date
while cur_date.month == start_date.month:
yield cur_date
cur_date += timedelta(days=1)
for d in generate_month_days(2015,11):
print d