I´m having some trouble with reading a file line-by-line, instead of reading the the file into memory. As of right now, I\'m reading the file into memory, and it works perfect.
Original problem is that you've hit the end of the file and need to go back to the start to iterate over it again. You can do this in a single iteration through the file, split into two and then sum.
with open(filename) as f:
A, B = map(sum, zip(*((x, x**2) for x in map(float, f))))