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 6198699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:43+00:00 2026-05-24T04:03:43+00:00

I am back again with another python query. I have been trying to do

  • 0

I am back again with another python query. I have been trying to do some calculations with the items present in a list. Here is the code:

import math

def Usage() :
    print "Usage :python beznew.py transcriptionsFile"

if __name__ == "__main__" :

    if len(sys.argv) != 2 : 
        Usage() 

    else :
        transcriptionFile = sys.argv[1]
        tFile = open(transcriptionFile, "r")

        for line in iter(tFile) :
            list = line.split()

            # changing the unit of time from 100 nano seconds to seconds
            list[0] = list[0] / 100000000
            list[1] = list[1] / 100000000

            # duration of each phoneme
            list = list[1] - list[0]

            # extracting the start time of each phoneme
            newlist = list.pop[0]    

            print list
            print newlist

        close.tFile 

The input file looks like the following:

000000 1200000 pau

1200000 1600000 dh

1600000 2000000 ih

2000000 3100000 k

3100000 3400000 aa

3400000 3800000 r

I am trying to change the numerical values to seconds. And also trying to get the difference between first and second numbers. It would not allow me to divide. I dont understand what am I doing wrong. Thank you.

  • 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-05-24T04:03:44+00:00Added an answer on May 24, 2026 at 4:03 am

    you can simplify your code as follows:

    transcriptionFile = 'calculus.txt'
    
    with open(transcriptionFile, "r") as tFile:
            for line in tFile :
                    li = line.split()
                    if li: 
                            new = ((int(li[1]) - int(li[0]))/10000000. , li[2])     
                            print li,'  ',new
    

    The condition if li: is here to eliminate possible void lines.

    Important points:

    • don’t call a list with the name list because list is the name of built-in function of Python

    • in Python, 10/100 produces 0 ; you must put a dot to obtain the right result: 10./100 or 10/100.

    • do the calculus list = list[1] - list[0] before dividing by 10000000, it is more precise

    • with open(....) as handle: is better to open the files

    Personally, I would do

    transcriptionFile = 'calculus.txt'
    
    with open(transcriptionFile, "r") as tFile:
            gen = (line.split() for line in tFile if line.strip())
            li = [((int(t2)-int(t1))/10000000.,phon) for (t1,t2,phon) in gen]
            print '\n'.join(map(str,li))
    

    Note that I used 10000000. to divide: if 1600000 - 1200000 = 400000 is in a unit which is 100 nanoseconds, then 400000 / 10000000 is 0.04 second

    Edit 1

    transcriptionFile = 'calculus.txt'
    
    with open(transcriptionFile, "r") as tFile:
            gen = (line.split() for line in tFile if line.strip())
            firstVals, lapTimes = [],[]
            for (t1,t2,phon) in gen:
                    firstVals.append( (int(t1)/10000000.,phon) )
                    lapTimes.append( (int(t2)-int(t1))/10000000.,phon) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I convert a List<MyObject> to an IEnumerable<MyObject> and then back again? I
EDIT AGAIN : I don't want to create another question, so asking here. I
Back in the old days, Help was not trivial but possible: generate some funky
Back in VB6, I wrote a few functions that would let me code without
Back in college, only the use of pseudo code was evangelized more than OOP
In general, Python sets don't seem to be designed for retrieving items by key.
I have a weird problem! I'm trying to create a listview with checkboxes. In
I have data that is being encrypted and sent to another page, where it
Back in the days of Unix, you couldn't even close a software without reading
Back in the 90s when I first started out with MFC I used to

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.