Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Printing current time to a file

Reply
Thread Tools

Printing current time to a file

 
 
zolaris@gmail.com
Guest
Posts: n/a
 
      11-11-2005
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.

 
Reply With Quote
 
 
 
 
skip@pobox.com
Guest
Posts: n/a
 
      11-11-2005

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

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      11-11-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing out the current URL for current ASP page in Perl Jack Perl Misc 3 12-22-2008 02:35 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM
How to change the current thread current culture at run time. Manu ASP .Net 1 07-20-2003 03:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57