2

I want to make a loop where if a column is empty in a row to do something else. The problem is that it can't determine the empty row. I tried as null, na , '',' ' and with double quotes and nothing.

for i in t_list:
    with arcpy.da.SearchCursor(i, ["name","num"]) as cur:
        for row in cur:
            if row[1] is not "''":
               print(row)

Gives:

nog1, num = '1'
nog2, ''

And it returns even the the empty rows

1 Answer 1

4

To check for not na/none use:

if row[1] is not None

To check for both None and empty string use:

if row[1] not in ('', None)

Or simply:

if row[1]

Which will be true if value is not empty or None:

a = ''
if a:
    print('Not empty')
a = None
if a:
    print('Not None')
a = 'hello'
if a:
    print(a)

Outputs:

hello

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.