Oct-17-2016, 05:36 PM
This is what I came up with.
from datetime import date def yield_file_dates(start_year, start_month, amount_of_months): current_date = date(start_year, start_month, 1) for _ in range(amount_of_months): yield 'DC{:%Y%m}'.format(current_date) if current_date.month == 12: current_date = current_date.replace(current_date.year + 1, 1) else: current_date = current_date.replace(month=current_date.month + 1) for file_date in yield_file_dates(2016, 10, 5): print(file_date)
Output:DC201610
DC201611
DC201612
DC201701
DC201702