formatting text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grantstech
    New Member
    • Jun 2007
    • 16

    formatting text

    I am creating files in a directory and they need to be formatted by month/day format, but I haven't figured out how to format text so that it always shows four numbers.
    Can anyone help me out?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by grantstech
    I am creating files in a directory and they need to be formatted by month/day format, but I haven't figured out how to format text so that it always shows four numbers.
    Can anyone help me out?
    I'd use strftime() from the datetime module.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      [code=Python]import datetime

      seed_date = datetime.date(2 007,01,01)
      td = datetime.timede lta(1)
      fileList = [''.join((seed_d ate+td*i).strft ime('%m%d'))+'. txt' for i in range(365)][/code]

      Comment

      • grantstech
        New Member
        • Jun 2007
        • 16

        #4
        Originally posted by bvdet
        [code=Python]import datetime

        seed_date = datetime.date(2 007,01,01)
        td = datetime.timede lta(1)
        fileList = [''.join((seed_d ate+td*i).strft ime('%m%d'))+'. txt' for i in range(365)][/code]




        Thanks, I get it now.

        Comment

        • spgarg04
          New Member
          • Aug 2007
          • 1

          #5
          Originally posted by grantstech
          I am creating files in a directory and they need to be formatted by month/day format, but I haven't figured out how to format text so that it always shows four numbers.
          Can anyone help me out?
          thanks i also got it..

          Comment

          Working...