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.
you can simplify your code as follows:
The condition
if li:is here to eliminate possible void lines.Important points:
don’t call a list with the name
listbecauselistis the name of built-in function of Pythonin Python,
10/100produces 0 ; you must put a dot to obtain the right result:10./100or10/100.do the calculus
list = list[1] - list[0]before dividing by 10000000, it is more precisewith open(....) as handle:is better to open the filesPersonally, I would do
Note that I used 10000000. to divide: if
1600000 - 1200000 = 400000is in a unit which is 100 nanoseconds, then400000 / 10000000is 0.04 secondEdit 1