Printing current time to a file

Peter Hansen peter at engcorp.com
Thu Nov 10 22:01:51 EST 2005


zolaris at gmail.com wrote:
> 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?

 >>> import time
 >>> time.ctime(time.time())
'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



More information about the Python-list mailing list