rbt wrote:
Jim wrote:

If I have a file with a floating point number on each line, what is the best way of reading them into a list (or other ordered structure)?

I was iterating with readline and appending to a list but it is taking ages.


Perhaps you should use readlines (notice the s) instead of readline.

I don't know if I thought of that, but I'm tokenizing each line before adding to a list of lists.


            for line in f:
                factor = []
                tokens = line.split()
                for i in tokens:
                    factor.append(float(i))
                factors.append(factor)

Is this nasty?

Jim
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to