Hi it's from my first program in Python. How I can make it better?
from collections import namedtuple
Point = namedtuple('Point ', ['x', 'y'])
def read():
ins = open("PATH_TO_FILE", "r")
array = []
first = True
expected_length = 0
for line in ins:
if first:
expected_length = int(line.rstrip('\n'))
first = False
else:
parsed = line.rstrip('\n').split ()
array.append(Point(int(parsed[0]), int(parsed[1])))
if expected_length != len(array):
raise NameError("error on read")
return array
It reads list of points from file with format
<number of points>
x1 y1
x2 y2