Question about nested loop

Isaac Won winefrog at gmail.com
Mon Dec 31 05:02:56 EST 2012


Hi all,
I am a very novice for Python. Currently, I am trying to read continuous columns repeatedly in the form of array. 
my code is like below:

import numpy as np

b = []


c = 4
f = open("text.file", "r")


while c < 10:
        c = c + 1

        for  columns in ( raw.strip().split() for raw in f ):


                b.append(columns[c])

        y = np.array(b, float)
        print c, y


I thought that  can get the arrays of the columns[5] to [10], but I only could get repetition of same arrays of columns[5].

The result was something like:

5 [1 2 3 4 ......, 10 9 8]
6 [1 2 3 4 ......, 10 9 8]
7 [1 2 3 4 ......, 10 9 8]
8 [1 2 3 4 ......, 10 9 8]
9 [1 2 3 4 ......, 10 9 8]
10 [1 2 3 4 ......, 10 9 8]


What I can't understand is that even though c increased incrementally upto 10, y arrays stay same.

Would someone help me to understand this problem more?

I really appreciate any help.

Thank you,

Isaac



More information about the Python-list mailing list