Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:21:15+00:00 2026-06-03T20:21:15+00:00

No clue why this is happening. I must be missing something obvious. I’m trying

  • 0

No clue why this is happening. I must be missing something obvious.

I’m trying to make a counter print out something like SMPTE code (hours:minutes:seconds:frames (assuming 24fps)).

Code thus far:

import time


s_time = time.time()
def format_time():
    t = time.time() - s_time 
    if t < 1:
        print '00:00:00:%02d' % int(t/0.041666666666666664)
    elif t < 60:
        t = str(t).split('.')

        print '00:00:%02d:%02d' % (int(t[0]), int(int(t[1][:4])/0.041666666666666664) )

while True:
    format_time()

All seems well initially, until the duration surpasses 1 second and the elif branch is entered. Seconds print out fine, but the frames print out the full multi-digit result of the calculation. Given that the formatting operator is specifying %02d, just like it does in the first if branch (which behaves as expected), why is it not obeying in the second branch? I’m at a loss trying to figure out why it is still printing the full result rather than the truncated version.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:21:16+00:00Added an answer on June 3, 2026 at 8:21 pm

    You are trying to get the integer part and the fractional part of the float to print your result. It is a good practice to use operators and functions on numeric data directly instead of adding a heavy overhead by converting the float into str and back to number.

    Use the math module modf function for that. It will also simplify your algorithm.

    import time
    import math
    
    s_time = time.time()
    def format_time():
        t = time.time() - s_time
        if t < 60:
            f,i = math.modf(t)
            print '00:00:%02d:%02d' % (i, f/0.041666666666666664)
    
    while True:
        format_time()
    

    PS: for your code error, in your elif block, you are passing t as an integer with a huge value instead of passing the 0.xxxxx value of it. This error wouldn’t occur if you keep using the math functions of floats.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no clue why this is happening but maybe someone here knows. I
I am new to Objective-C and I have no clue why this code is
I have no clue how to validate this string. I am simply supplying an
This should work right? I have not a clue as to why it's not.
I have no clue of where to start on this. I've never done any
I am receiving this error. I have no clue as to why it would
I am doing this: @person.attributes = params[:person] Can anyone give me a clue as
This might be a dummy question, but I cannot find any clue in all
I was asked this question today by a colleague, and couldn't find any clue
I have a model like this: class Entity(models.Model): entity_name = models.CharField(max_length=100) entity_id = models.CharField(max_length=30,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.