0

Is there a way to append the current date to an output file. My output statement looks like,

result=open('Results.csv','wb')

If I run it today, I would like the file name to be something like Results20100528 (for May 28, 2010). If I run it tomorrow, I would like it to be Results20100529.

Thank you.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by oaktrees
0
import datetime
now = datetime.datetime.now()
suffix = now.strftime("%Y%m%d_%M%S)
result = open('Results%s.csv'%suffix,'wb')

Edited by griswolf: n/a

0

If anyone reads this in the future, there is one correction to the syntax. There should be end quotes for strftime.

import datetime
now = datetime.datetime.now()
suffix = now.strftime("%Y%m%d_%M%S")
result = open('Results%s.csv'%suffix,'wb')

Thanks again.

Edited by oaktrees: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.