tarsketcnAsg 8.1 Text File fput and Splitting This exercise loads the clipAndMea
ID: 3739244 • Letter: T
Question
tarsketcnAsg 8.1 Text File fput and Splitting This exercise loads the clipAndMeasures.txt file below using the importFile0 function Modify the code below to add track 2 from the second line of the text file. from earsketch import 3 init) 4 setTempo(100) 6 fileData importFile("http://earsketch.gatech.edu/itec2120/data/clipAndMeasures.txt") 8 lines- fileData.split( In") 10 track=1 11 first line lines[0] 4 setTempo(100) 6 fileData importFile("http://earsketch.gatech.edu/itec2120/data/clipAndleasures.txt") lines fileData.split( n 10 track1 11 first ine linest0 12 values-first_line.split) 3 clipvalues[o) 14 start. ?nt(values[1]) 5 end int(values[2]) 16 fitMedia(clip, track, start, end) 17 18 # add track 2 from second line of the text file. 19 20 finish)Explanation / Answer
Source code:
from earsketch import *
init()
setTempo(100)
fileData = importFile("http://earsketch.gatech.edu/itec2120/data/clipAndMeasures.txt")
lines = fileData.split(" ")
track = 1
first_line = lines[0]
second_line = lines[1]
values = second_line.split(";")
clip = values[0]
start = int(values[1])
end = int(values[2])
fitMedia(clip, track, start end)
finish()
Modified part:
The only thing that needs to be modified here is the line of code which states that first_line = lines[0]
here lines[] array consists of all those lines which are present in the txt file.
So in order to read second line of the files we just need to access the array lines with array index as 1.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.