Here is a generator that basically goes forever in a circular list from 1 to 12
def get_next_month(month): i_month = month while True: if i_month == 12: i_month = 1 else: i_month = i_month+1 yield i_month
Here is how to use it.
def month_current_and_next(month, count = 1 ): if month == 0: time_t = datetime.now() current_month = time_t.month else: current_month = month g = get_next_month(current_month) month_list = [current_month] for m in range(count): month_list.append(next(g)) return month_list
Here is the full gist