I am append-writing lists to a text file through iterations using writelines(str(list)). For short, I will use 2 lists to illustrate:
list1=['[#1]:', (4, 8, 16, 29), (4, 8, 16, 30), (4, 8, 16, 32)]
list2=['[#2]:', (3, 9, 13, 20), (3, 9, 13, 36), (3, 9, 13, 38)]
and in the text file, I have a pile of separate lists:
['[#1]:', (4, 8, 16, 29), (4, 8, 16, 30), (4, 8, 16, 32)] ['[#2]:', (3, 9, 13, 20),
(3, 9, 13, 36), (3, 9, 13, 38)]
When I read back the text file into a list using readlines(file.txt), I get a single list of a string:
["['[#1]:', (4, 8, 16, 29), (4, 8, 16, 30), (4, 8, 16, 32)], ['[#2]:', (3, 9, 13, 20),
(3, 9, 13, 36), (3, 9, 13, 38)]"]
This is expected. What I want to do is to remove the ' " ' (quotation marks) at the beginning and end of the list so I can then iterate through the list and process list[#1], list[#2] etc. I expect that this is elementary but I can't work it out. I would appreaciate if someone can show me how.
Thanks in advance.