dimanche 21 juin 2015

ELSE Statement for CSV file not working

I'm trying to fit in an ELSE statement for a variable within a CSV File.

CSV File:

abcd, qwerty, aoo9

I have attempted the following:

variable = raw_input('Variable: ')
with open('FILE.csv', "rb") as csvfile:
        z = csv.reader(csvfile, delimiter=',')
        for row in z:
            if variable in row[1]: 
                print 'A' 
            else:
                print 'B'
                sys.exit()

However, regardless of whether variable is in row[1] or not, it will still print 'B'.

I have also tried:

elif variable not in row [1]: #...

But that doesn't work either.

Thanks.

Aucun commentaire:

Enregistrer un commentaire