Grand Finale


Can someone tell me why I keep getting this "wrong format" mensage?

print '%s/%s/%s  %s:%s:%s' % (now.month,, now.year, now.hour, now.minute, now.second)


I even put an extra 0 to fill the two places in the date format: print '0%s/0%s/%s %s:%s:%s' % (now.month,, now.year, now.hour, now.minute, now.second)


As we all know Python is very specific about indentions and grammar. In this case you have the completely right code except it would seem you have too much space between these two sets of %s. Try this spacing:

print "%s/%s/%s %s:%s:%s" %

Also, you don't need the zeros you just added in so take those out! :smiley:


Yeah...I wasn't one of the "we all know", but now I'm. Thank you!
I'm learning by my own so sorry for the stupids questions.


No listen this mistake is wayyyy too easy to make and you are by far not the first. I was just giving you the benefit of the doubt you realize this. Even realizing this I still make way to many errors myself in python similiar to this... but I am glad I could help! :smiley:


Hi @rhannarr,

If you would like to include zeroes in your output when needed, so that components of the dates and times are each displayed with a predetermined number of digits, you can use this technique to specify the length of each component, and to specify "0" as the fill character ...

print "{:02d}/{:02d}/{:04d} {:02d}:{:02d}:{:02d}".format(now.month,, now.year, now.hour, now.minute, now.second)

Example output ...

02/06/2017 17:04:25


Ah ok. I see what he means now. I thought rhannarr was using the zeros to space out his time and date to the correct format instead of realizing it was just in the spacing of his s%. Cool to know!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.