pythonfile-import

Out of range in list,while parsing .csv file


I want to parse my .csv file. In the logs, it's all right, I'm getting my first and the second value, but I have an error on the second value: Here is my code

    dec = attdecode.split("\n")
    line = 0

    for row in dec :
                line += 1
                rowparse = row.split(";")
                x=rowparse[0]
                y=rowparse[1]  # here, I GET : y=rowparse[1]IndexError: list index out of range
                print '//// rowparse', rowparse #I get all my line,with 4 elements divided by ;
                print 'x====', x #correct value
                print 'y===',y #correct value
                print 'Long===',len(rowparse) # I get 4 and it's correct

so if my y is correct, why I get an error on y=rowparse[1]


Solution

  • The code works just fine for me

    csv = "15717464674;Y5547;2;1\n14478878828;AB557;3;2"
    dec = csv.split("\n")
    line = 0
    
    for row in dec :
                line += 1
                rowparse = row.split(";")
                x=rowparse[0]
                y=rowparse[1]
                print(x)
                print(y)