Lines in a file is not displayed (python)
<p>I'm a python beginner. So I encountered this problem. The file has 100 songs, each song with an id(X), title(T), time sig(M) and key sig(K),
the format of the text file is the same throughout the file. 
However it skipped 8 lines. Some of the tunes in the file has several titles, but only one is to be displayed </p>

<pre><code>file = open("musicFile.abc", "r")
idNum = ""
title = ""
timesig = ""
keysig = ""
total = 0
for line in file:
    if line[0] == 'X':
        idNum = line[2:]
    elif line[0] == 'T':
        sep = ','  
        line = line.split(sep, 1)[0]   
        title = line[2:]
        for i in range(4):
            if next(file) == 'T': 
            break
    elif line[0] == 'M':
        timesig = line[2:]
    elif line[0] == 'K':
        keysig = line[2:]
        fullLine = "Id: " + idNum + " .... " + "Title: " + title + " .... " + \
        "Time sig: " + timesig + " .... " + "Key sig: " + keysig
    fullLine = fullLine.replace("\n", "") 
    print(fullLine)
    total += 1

print("\n-------------------------------")
print("There are ", total, "tunes in the file")
print("-------------------------------")
</code></pre>

<p>This is the compiled result:
<a href="http://i.stack.imgur.com/4AEJp.png" rel="nofollow">compiled program</a></p>

<p>It should display there are 100 tunes in the file.</p>

<p>You use <code>next(file)</code> which reads next line so you skip some lines.</p>

python