嘿,我是 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 ... ... ... ... //
谢谢