def months(start_month, start_year, end_month, end_year):
    month, year = start_month, start_year
while True:
    yield month, year
if (month, year) == (end_month, end_year):
    return
month += 1
if month > 12:
    month = 1
year += 1
Как создать итератор месяца