I need to read tuples from a txt. I tried with numpy (using genfromtxt) but it didn\'t work (or at least, I don\'t know how). This is is my txt:
(0,0) (0,0)
You can try this one, although it does not use the numpy library:
from ast import literal_eval as createTuple
tupleList = []
with open("test.txt","r") as infile:
for line in infile:
line = line.split()
for l in line:
tupleList.append(createTuple(l))
print(tupleList)
Format of input file:
(0,0) (0,0) (1,0) (2,3)
(1,0) (1,1) (1,1) (3,3)
(2,0) (1,2) (2,1) (4,4)
(3,0) (2,2) (3,1) (5,5)
Output (list of tuples):
[(0, 0), (0, 0), (1, 0), (2, 3), (1, 0), (1, 1), (1, 1), (3, 3), (2, 0), (1, 2), (2, 1), (4, 4), (3, 0), (2, 2), (3, 1), (5, 5)]