嘿,我是一個Python新手,我需要一些幫助。當循環結束它總是拋出通知循環停止的異常蟒蛇循環異常
try:
it = iter(cmLines)
line=it.next()
while (line):
if ("INFERNAL1/a" in line) or ("HMMER3/f" in line) :
title = line
line = it.next()
if word2(line) in namesList: //if second word in line is in list
output.write(title)
output.write(line)
line = it.next()
while ("//" not in line):
output.write(line)
line = it.next()
output.write(line)
line = it.next()
except Exception as e:
print "Loop exited becuase:"
print type(e)
print "at " + line
finally:
output.close()
:我寫下來下面的代碼。儘管它沒有過早終止。我如何阻止?
有沒有更好的方法來寫我的代碼?更時尚的東西。我有一個有大量信息的大文件,我只想捕捉我需要的信息。信息每片的格式爲:
Infernal1/a ... Name someSpecificName ... ... ... ... //
謝謝
您獲得哪種類型的Exception? –