I want to make a program that prints how long it has been running. I tried this

import time
b = time.tick()
print b

Even if this did work it wouldnt do what I want it to do. I basically want it to tell me how long the program has been running every 10 seconds. How would I go about doing this?

Thanks.

Rysin

You could do this:

while True:
    now = time.time()
    print now
    time.sleep(10)

The main problem with this approach is that the program can't do anything else during the sleeping period. You could potentially make a separate thread (look up threading if you don't know what this is) that would run this code while the rest of your program does its thing.

OR, you could do it using the after method from Tkinter, but this may pop up a window. Notice that this function works in milliseconds.

from Tkinter import *
import time

root = Tk()

def printtime():
    now = time.time()
    print now
    root.after(10000, printtime)
    
printtime()
root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.