def main(): with open('d:/test_trim.txt', 'w', encoding='UTF-8') as fout: can_write = False with open('d:/test.txt', 'r', encoding='UTF-8') as fin: line=fin.readline() while(line != ''): if line.find('TRACK') == -1: line = fin.readline() continue if line.find('TITLE') > -1: print line fout.write(line) line = fin.readline() print('Done.')
我参考了版上的代码改了一下,不过运行结果 应该是 TITLE "歌曲名",我关键的一个地方不会写。 就是输出的时候,怎么把TITLE和引号, 多余的tab或者引号去掉?