我正在用python3编写脚本,但我无法解决以下问题。在
我有一份名单,上面有这样的图案:
ZINC123456
ZINC234567
ZINC345678
ZINC456789
...
我有一个像这样的大文件:
^{pr2}$我想做的是: 循环检查第一个列表中的每个项目,然后在第二个文件中搜索它。当找到这个项目时,复制这一行和下面的所有内容,直到下一个zincxxxxx模式到达一个新文件中。在
我该怎么做?非常感谢你的帮助!在
编辑:多亏了Sudipta Chatterjee,我找到了以下解决方案:
import sys
finZ=open(sys.argv[1],'r')
finX=open('zinc.sdf','r')
fout=open(sys.argv[1][:7]+'.sdf','w')
list=[]
thislinehaszinc = False
zincmatching = False
for zline in finZ:
if zline[0:4] == "ZINC":
name = zline[:-1] #line[4:-1]
if name not in list:
list.append(name)
for xline in finX:
if xline[0:4] == "ZINC":
thislinehaszinc = True
zincmatching = False
for line in list:
if line == xline[:-1]:
zincmatching = True
fout.write(xline)
print('Found: '+xline)
pass
else:
pass
else:
thislinehaszinc = False
if thislinehaszinc == False and zincmatching == True:
fout.write(xline)
相关问题 更多 >
编程相关推荐