Python and time / datetime
Question: I've recently began work on a Python program as seen in the fragment below.

    
    
    # General Variables
    running = False
    new = True
    timeStart = 0.0
    timeElapsed = 0.0
    
    def endProg():
        curses.nocbreak()
        stdscr.keypad(False)
        curses.echo()
        curses.endwin()
        quit()
    
    # Draw
    def draw():
        stdscr.addstr(1, 1, ">", curses.color_pair(6))
        stdscr.border()
        if running:
            stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.ctime( timeStart - timeElapsed ) ) )
    
            stdscr.redrawwin()
        stdscr.refresh()
    
    # Calculate
    def calc():
        if running:
            timeElapsed = t.clock() - timeStart
    
    stdscr.border()
    stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( t.clock() - t.clock() ) ) )
    
    # Main Loop
    while True:
        # Get Input
        kInput = stdscr.getch()
    
        # Close the program
        if kInput == ord('q'):
            endProg()
    
        # Stop the current run
        elif kInput == ord('s'):
            stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( t.clock() - t.clock() ) ) )
            running = False
            new = True
    
        # Start a run
        elif kInput == ord(' ') and new:
            running = not running
            new = not new
            timeStart = dt.datetime.now()
    
        # Toggle the timer
        elif kInput == ord('p') and not new:
            timeStart = dt.datetime.now() - timeStart
            running = not running
    
        calc()
        draw()
    

**My program is a bit between solutions currently** , sorry if something
doesn't look right. I'll be more than happy to explain.

I've spent the last several hours reading online about the time and datetime
modules for python, trying to figure out how I can use them to accomplish my
goals, but however I've tried to implement them it's been no use.

Essentially, I need my program to measure the elapsed time from when a button
is pressed and be able to display it in a hour:minute.second format. The
subtraction has made it very difficult, having to implement things such as
timedelta. From what I have read online there is no way to do what I'm wanting
without the datetime module, but it's given me nothing but problems.

Is there an easier solution, does my code have any outstanding errors, and how
stupid am I?


Answer: Using ˋtime.time`:

    
    
    import time
    
    star = time.time()
    # run long processing...
    elapsed = time.time() - start
    

Et voilà !

