Date conversion in python -


i have data in text file in following format:

50 cent     1975-07-06 75 cents    1933-01-29 9th wonder  1975-01-15 fine frenzy   1984-12-23 

i want convert like:

50 cent     july 6, 1975 75 cents    january 29, 1933 9th wonder  january 15, 1975 fine frenzy   december 23, 1984 

could of please me.thanks in advance!

import time  text = """50 cent     1975-07-06 75 cents    1933-01-29 9th wonder  1975-01-15 fine frenzy   1984-12-23"""  line in text.splitlines():     dob = line.rsplit(none, 1)[-1]     dob_new = time.strftime('%b %d, %y', time.strptime(dob, '%y-%m-%d'))      print line.replace(dob, dob_new) 

result:

 50 cent     july 06, 1975 75 cents    january 29, 1933 9th wonder  january 15, 1975 fine frenzy   december 23, 1984 

bonus:

a strftime cheatsheet


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -