rearranging a list of months

Posted by MacUsers on Stack Overflow See other posts from Stack Overflow or by MacUsers
Published on 2011-02-14T04:19:32Z Indexed on 2011/02/14 7:25 UTC
Read the original article Hit count: 169

Filed under:

How can I list the numbers 01 to 12 (one for each of the 12 months) in such a way so that the current month always comes last where the oldest one is first. In other words, if the number is grater than the current month, it's from the previous year.

e.g. 02 is Feb, 2011 (the current month right now), 03 is March, 2010 and 09 is Sep, 2010 but 01 is Jan, 2011. In this case, I'd like to have [09, 03, 01, 02]. This is what I'm doing to determine the year:

for inFile in os.listdir('.'):
    if inFile.isdigit():
    month = months[int(inFile)]
       if int(inFile) <= int(strftime("%m")):
           year = strftime("%Y")
       else:
           year = int(strftime("%Y"))-1
       mnYear = month + ", " + str(year)

I don't have a clue what to do next. What should I do here?

© Stack Overflow or respective owner

Related posts about python