I want to know how to save an array to a file. You already helped me a lot, but I have more naive questions (I'm new to Python):
@<TRIPOS>MOLECULE
NAME123
line3
line4
line5
line6
@<TRIPOS>MOLECULE
NAME434543
line3
line4
line5
@<TRIPOS>MOLECULE
NAME343566
line3
line4
I am currently have this code, but it's save only the last item from the array no the all listed in the items_grep. How to fix this?
items = []
with open("test.txt", mode="r") as itemfile:
for line in itemfile:
if line.startswith("@<TRIPOS>MOLECULE"):
items.append([])
items[-1].append(line)
else:
items[-1].append(line)
#
# list to grep
items_grep = open("list.txt", mode="r").readlines()
# writing files
for i in items:
if i[1] in items_grep:
open("grep.txt", mode="w").write("".join(i))
Thank you in advance!