文件中的行不显示(python)

时间:2016-10-09 00:45:43

标签: python

我是一名蟒蛇初学者。所以我遇到了这个问题。该文件有100首歌曲,每首歌曲有一个id(X),title(T),time sig(M)和key sig(K), 整个文件中文本文件的格式是相同的。 但它跳过了8行。文件中的一些曲调有几个标题,但只有一个要显示

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("-------------------------------")

这是编译结果: compiled program

它应该显示文件中有100个曲调。

1 个答案:

答案 0 :(得分:0)

您使用<?php echo '<pre>'; echo ($ordermess['creditCardPaymentInfo']->getCardNumberLast4()); echo '</pre>'; die; ?> 读取下一行,以便跳过某些行。