我想知道在创建新的file.txt
. 我的目标是检查我是否开始,结束值超过一对,然后我想为每对创建单独的文件。如果不是,那么就保持原样。
def searchPFAM(fname):
with open(fname,'rb') as f:
root = etree.parse(f)
for lcn in root.xpath("/protein/match[@dbname='PFAM']/lcn"):#find dbname =PFAM
try:
start = int(lcn.get("start"))#if it is PFAM then look for start value
end = int(lcn.get("end"))#if it is PFAM then also look for end value
yield start, end
except (TypeError , ValueError) as e:
pass
with open('newfile.txt','w') as fileinput:
for start, end in searchPFAM(fname):
print start, end
if start <= end:
text=''.join(makeList[(start-1):(end-1)])
fileinput.write(text)