def load_fasta(filename):
with open(filename) as f:
for seq in re.finditer(r">[^>]*", f.read()):
yield seq.group(0)
for thing in load_fasta(filename):
...
with语句将在for循环完成后关闭文件。请注意,由于您将整个文件读入内存,因此只需使用
def load_fasta(filename):
with open(filename) as f:
data = f.read()
for seq in re.finditer(r">[^>]*", data):
yield seq.group(0)
使用
yield
而不是单个生成器表达式with
语句将在for
循环完成后关闭文件。请注意,由于您将整个文件读入内存,因此只需使用相关问题 更多 >
编程相关推荐