BEGINNER: converting integer to short month name?

MCollins at co.seminole.fl.us MCollins at co.seminole.fl.us
Wed Apr 9 22:13:01 CEST 2003


hi,

i've just been introduced to python.  i started out as with asp, migrated
to php, and now here i am with python.

anyway, i'm working on a utility that will download all the log files i
need every month for all the servers we monitor.  some of these files are
ftp'd and some are pulled down via http.

the http files have names such as ex0303.log or exMar03.log, depending on
the server admin's decision.

so i have a function that will take the current month and year, and back it
up to the previous month to build the correct logfile name (i.e., in april
2003, i'm downloading 0303.log).

that works fine for the numerical month names.  now i'm trying to convert
the numerical month into it's short month name equivalent to grab those
files.

i could always use a long if , elif, elif to do the job, but i was
wondering if there was built-in function already capable of that.  i was
just looking for something a little more elegant.

any suggestions?

current code:

month_year = strftime("%m,%y", gmtime())
      split_month_year = month_year.split(",")

      the_year = split_month_year[1]
      the_month = split_month_year[0]
      the_year = int(the_year)
      the_month = int(the_month)

      if the_month == 1:
            the_year = the_year - 1
            the_month = 12
      else:
            the_month = the_month - 1


      the_year="0" + str(the_year)
      the_month="0" + str(the_month)

      getMonthYear = fileString + the_year + the_month + ".log"
      return getMonthYear













More information about the Python-list mailing list