lundi 24 décembre 2018

for loop stopped after the inner while loop executed

I have a for loop with two while loops inside to read the input file and extract specific fields from the input file. However, my for loop stops after the second while loop is executed...any ideas?

That's what my code looks like:

for line in file:
    if column1 == '1':
        do something
        read next line
        while column1 == '2':
            read next line
        while column1 == '3':
            do something
            read next line

Currently, the for loop stop after the while loops and won't go to the next line in the input file.

The input data file looks like:

(Line1)    1    data1_1    data1_2 ...
(Line2)    2    data2_1    data2_2 ...
(Line3)    2    data3_1    data3_2 ...
(Line4)    3    data4_1    data4_2 ...
(Line5)    3    data5_1    data5_2 ...
(Line6)    3    data6_1    data6_2 ...
(Line7)    1    data7_1    data7_2 ...
(Line8)    2    data8_1    data8_2 ...
(Line9)    3    data9_1    data9_2 ...
(Line10)    3    data10_1    data10_2 ...
    ...

My code will stop at line 6, why?

Aucun commentaire:

Enregistrer un commentaire