python3でスクリプトを書いているのですが、以下の問題が解決できません。
このパターンの名前のリストがあります:
ZINC123456
ZINC234567
ZINC345678
ZINC456789
...
そして、私は次のような大きなファイルを持っています:
ZINC123456
xxx
xxx
xxx
ZINC987654
xxy
xxy
xxy
xxy
ZINC654987
...
私がやりたいことは次のとおりです。最初のリストのすべての項目をループし、2 番目のファイルで検索します。この項目が見つかったら、次の ZINCxxxxxx パターンに到達するまで、この行と以下のすべてを新しいファイルにコピーします。
これどうやってするの?ご助力ありがとうございます!
編集: 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)