Printing current time to a file

Z

zolaris

I am trying to print the current system time to a file. I know only a
little bit about Python. I have gotten the very simple:

Print time.time()

to work properly. From what I gather the line to print it to a file
should look like:

self.log.write(time.ctime(time.time()))

But that prints nothing in the file assigned to log. Is there
something I should be doing extra?

Thanks.
 
S

skip

zolaris> self.log.write(time.ctime(time.time()))

zolaris> But that prints nothing in the file assigned to log. Is there
zolaris> something I should be doing extra?

There's no newline in there. You probably need to flush the file:

self.log.write(time.ctime(time.time()))
self.log.flush()

You might want to write a newline after the time as well. If the logfile is
line-buffered that will also provoke a flush.

Skip
 
P

Peter Hansen

I am trying to print the current system time to a file. I know only a
little bit about Python. I have gotten the very simple:

Print time.time()

to work properly. From what I gather the line to print it to a file
should look like:

self.log.write(time.ctime(time.time()))

But that prints nothing in the file assigned to log. Is there
something I should be doing extra?
'Thu Nov 10 22:00:57 2005'

Since that clearly returns a string, and the write() method takes a
string, you either do NOT have a "file assigned to log", or you haven't
opened it, or perhaps you are expecting to see the output even though
you haven't closed the file or flushed it.

Maybe showing us the missing code would help...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top