lundi 9 avril 2018

If statements and 2D array in Python

I have a table on excel, and I would like to check if some element is empty, for misstyping or whatelse.

So, I want to check all of elements which are placed at [1].

import csv
matrix = csv.reader(open("matrix1.csv","rb"))

arr = range(50)

x = 0
for row in matrix:
    arr[x] = row
    x += 1

i = 0
len = len(arr)
for i in range(len):
    if ((arr[i][1]) is None):
        print("it is empty")

TypeError: 'int' object is not subscriptable

But, if i code like my code below, it works, but my console still says:

TypeError: 'int' object is not subscriptable

for i in range(len):
    if ((arr[i]) != 0):
        print(arr[i][1])

Full console output:

585957 Traceback (most recent call last): 545253 515359 575951 File "C:/PycharmProjects/test.py", line 17, in 525356 print(arr[i][1]) 565958 585754 TypeError: 'int' object is not subscriptable 505152 535250

It means, it gives me the elements I want, but it is still not cool.

What am I missing? Thanks!

Aucun commentaire:

Enregistrer un commentaire