.
12 , , :
>>> def rot_list(l,n):
... return l[n:]+l[:n]
...
>>> rot_list(range(1,13),2)
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]
, , ( ), , ( n) , :
>>> tar=[1,2,3,9]
>>> n=2
>>> [x for x in range(1,13)[n:]+range(1,13)[:n] if x in tar]
[3, 9, 1, 2]
>>> tar=[3,1,2,9]
>>> [x for x in range(1,13)[n:]+range(1,13)[:n] if x in tar]
[3, 9, 1, 2]
, , , - :
>>> nm=[3,9,1,2]
>>> fn=['%02i' % x for x in nm]
>>> fn
['03', '09', '01', '02']
All of these methods work whether Jan is "0" or "1". Just change any link range(1,13)to range(0,12)depending on the agreement.
Edit
If I understand what you are doing, this code will help:
import datetime
def prev_month(year,month,day):
l=range(1,13)
l=l[month:]+l[:month]
p_month=l[10]
if p_month>month:
p_year=year-1
else:
p_year=year
return (p_year,p_month,1)
def next_month(year,month,day):
l=range(1,13)
l=l[month:]+l[:month]
p_month=l[0]
if p_month<month:
p_year=year+1
else:
p_year=year
return (p_year,p_month,1)
year=2011
month=2
t=(year-1,month,1)
ds=[]
for i in range(1,13):
print datetime.date(*t).strftime('%m, %y')
t=next_month(*t)
Conclusion:
02, 10
03, 10
04, 10
05, 10
06, 10
07, 10
08, 10
09, 10
10, 10
11, 10
12, 10
01, 11
Just put the appropriate file name format in the method strftime()...
Hope this is what you are looking for ...