[Tutor] Creating unique output log files
Alexandre Ratti
alex@gabuzomeu.net
Fri, 17 May 2002 19:05:43 +0200
Hi Stuart,
At 12:00 17/05/2002 -0400, tutor-request@python.org wrote:
>From: stuart_clemons@us.ibm.com
>Date: Fri, 17 May 2002 10:50:35 -0400
>Subject: [Tutor] Creating unique output log files
>Any hints on how I can automatically create a unique output log everytime
>it's run. Making the date a part of the output log file name seems to
>make a lot of sense, but I don't know how to do it. Something like
>0517am.out & 0517pm.out.
Try this:
import time
timeStamp = time.gmtime(time.time())
formatString = "%Y-%m-%d-%H-%M-%S"
print "%s.out" % time.strftime(formatString, timeStamp)
>>> 2002-05-17-17-02-32.out
You could use a similar value as a file name. See the library section for
the "time" module for more info.
Cheers.
Alexandre