I got a very simple thing to to in python:
I need a list of tuples (year,month) for the last x months starting (and including) from today. So, for x=10 and toda
Or you can define a function to get the last month, and then print the months ( it's a bit rudimentary)
def last_month(year_month):#format YYYY-MM
aux = year_month.split('-')
m = int(aux[1])
y = int(aux[0])
if m-1 == 0:
return str(y-1)+"-12"
else:
return str(y)+"-"+str(m-1)
def print_last_month(ran, year_month= str(datetime.datetime.today().year)+'-'+str(datetime.datetime.today().month)):
i = 1
if ran != 10:
print( last_month(year_month) )
print_last_month(i+1, year_month= last_month(year_month))