jeudi 20 octobre 2016

Python iteration not entering if-elif

Pardon me if this is a really simple question. I've been at this for hours. I'm trying to read a csv file per row. However on the last row I don't want it to append any "," that's why I had separated the problem in an if-elif statement.

I'm not sure if this is just me sleepy but I can't seem to fix this simple matter. It doesn't enter in any condition yet when I print out the print (iter, row_count , iter < row_count) I'm 100% sure that the last row is False.

#loop in csv
    iter = 0

    for row in data:
        iter += 1
        print (iter, row_count , iter < row_count)
        if (iter < row_count == True):
            print("TRUE")
            id = row[0]
            name = row[1]
            latitude = row[2]
            longitude = row[3]
            output += template % (row[0], row[3], row[2], row[1])
            output += ","
            print (output)
        elif (iter < row_count == False):
            print("FALSE")
            id = row[0]
            name = row[1]
            latitude = row[2]
            longitude = row[3]
            output += template % (row[0], row[3], row[2], row[1])
            print (output)

Aucun commentaire:

Enregistrer un commentaire