473,507 Members | 11,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing current time to a file

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.

Nov 11 '05 #1
2 2299

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

Nov 11 '05 #2
zo*****@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
Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2400
by: David Isaac | last post by:
"Alan Isaac" <aisaac0@verizon.net> wrote in message news:_A34e.2207$1r6.248@trnddc02... > I'd like to try personal financial management using Python. > I just found PyCheckbook, but it does not...
4
4833
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
10
24851
by: Brian Hanson | last post by:
Hi, I am trying to programmatically print a pdf file via an asp.net application. I have seen other postings that mention the following code used or something similar to it in a vb.net app. ...
1
5682
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
1013
by: melanieab | last post by:
Hi, When the print button is clicked, I save a snapshot of the screen to a bitmap file. Graphics currentTab = this.CreateGraphics(); Size s = this.Size; Bitmap memoryImage = new Bitmap(s.Width -...
1
2068
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
3
10537
by: IanWright | last post by:
I'm having a little trouble with a progress bar that I've got in C++. This works fine in Windows but is not working correctly in Linux, and I'm wondering if anyone can help? const char DONE =...
18
11264
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
1
13609
by: Glenn | last post by:
I am writing a program for field work that will use a receipt printer. I need to be able to adjust the page settings prior to printing depending on how much needs to be printed. I have been able...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.