-2
我想从测试文件夹中读取所有fasta文件,并将文件的名称放在单个文件的所有标头中。代码为第一个文件工作,并不继续第二个文件并返回错误。你能帮我找到我的代码中的错误或编辑它。谢谢从文件夹中读取所有文件并编辑
import sys, glob, os, string
header = ''
check = 0
path = "./test/"
dirs = os.listdir(path)
for file in dirs:
fp = open(file, "r")
fpx = open('%s_output.txt' % file, 'w')
for line in fp:
if line.startswith('>'):
line = line.rstrip()
check = check + 1
if check >= 1:
header = line
fpx.write(header + '_' + file + '\n')
else:
line = line.rstrip()
fpx.write(line + '\n')
请提供运行代码时返回的错误。 – mobiuseng