Hello I need your help on the following problem. I am parsing the file that looks like this
@<TRIPOS>MOLECULE
NAME123
line3
line4
line5
line6
@<TRIPOS>MOLECULE
NAME434543
line3
line4
line5
@<TRIPOS>MOLECULE
NAME343566
line3
line4
I currenly have this code that is working ok...
mols = []
with open("test2.mol2", mode="r") as molfile:
for line in molfile:
if line.startswith("@<TRIPOS>MOLECULE"):
mols.append(line)
else:
mols[-1] += line
#
for i in range(len(mols)):
out_filename = "file%d.mol2" % i
with open(out_filename, mode="w") as out_file: out_file.write(mols[i]);
but whem I tried to save the files with name according to the second field of array, the one after @MOLECULE (NAME....) with code like this - it doesn't work. Please, help me to fix the code. Thank's!
for i in mols:
out_filename = str(i.split()[1]) + ".mol2" % i
with open(out_filename, mode="w") as out_file: out_file.write(mols[i]);
The error is
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: not all arguments converted during string formatting