One of the most effective ways to read delimited data like this is numpy.genfromtxt. for instance
>>> import numpy as np
>>> np.genfromtxt(r't3.txt', delimiter=',')
array([[-34.968398, -6.487265],
[-34.969448, -6.48825 ],
[-34.967364, -6.49237 ],
[-34.965735, -6.582322]])
Otherwise, you can use list comprehension to read line by line, divide by ',', convert values ββto, floatand finally create a listtuple
with open('t3.txt') as f:
mylist = [tuple(map(float, i.split(','))) for i in f]
Please note that when you open the file with with, it will take care of closing after that, so you do not need to.
source
share