擅长:python、mysql、java
<p>您正在尝试以“a+”模式打开文件,并在其中的行上循环(这样做时,文件位于末尾,因此将找不到任何内容)。在任何情况下,如果这只是一个输出文件,那么您将以“a”模式打开它以附加到它</p>
<p>可能您只想打开一次文件进行追加,在<code>with</code>语句中,当您想要实际向文件追加字符串时,使用<code>file_object.write(...)</code>执行主循环。请注意,使用此<code>with</code>构造时不需要<code>file_object.close()</code></p>
<pre><code>with open("Mimp_hits.bed", "a") as file_object:
for sequence in SeqIO.parse(infile, "fasta"):
# ... etc per original code ...
if length < mimp_length:
file_object.write("{}\t{}\t{}\n".format(
sequence.description, h.start(), h_rc.end()))
</code></pre>